From ab5e21d84faa930832aa42aa383c5952603a273f Mon Sep 17 00:00:00 2001 From: "Angel D. Munoz" Date: Sat, 9 Oct 2021 23:37:44 -0500 Subject: [PATCH 1/5] Allow include/exclude fiels from paths --- src/Perla/Build.fs | 72 ++++++++++++++++++++++++++++++---------------- src/Perla/Types.fs | 26 +++++++++++++++++ 2 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/Perla/Build.fs b/src/Perla/Build.fs index b350efe..20aba9d 100644 --- a/src/Perla/Build.fs +++ b/src/Perla/Build.fs @@ -172,6 +172,22 @@ module Build = let esbuildVersion = defaultArg buildConfig.esbuildVersion Constants.Esbuild_Version + let copyExcludes = + match buildConfig.copyPaths with + | None -> BuildConfig.DefaultExcludes() + | Some paths -> + paths.exclude + |> Option.map List.ofSeq + |> Option.defaultValue (BuildConfig.DefaultExcludes()) + + let copyIncludes = + match buildConfig.copyPaths with + | None -> List.empty + | Some paths -> + paths.``include`` + |> Option.map List.ofSeq + |> Option.defaultValue List.empty + task { match config.fable with | Some fable -> @@ -216,33 +232,39 @@ module Build = let getDirectories (map: Map) = let root = Environment.CurrentDirectory - for key in map.Keys do - Directory.EnumerateFiles(Path.GetFullPath(key), "*.*", opts) - |> Seq.filter - (fun file -> - not <| file.Contains(".fable") - && not <| file.Contains("bin") - && not <| file.Contains("obj") - && not <| file.Contains(".fsproj") - && not <| file.Contains(".fs") - && not <| file.Contains(".js") - && not <| file.Contains(".css") - && not <| file.Contains(".ts") - && not <| file.Contains(".jsx") - && not <| file.Contains(".tsx") - && not <| file.Contains("index.html")) - |> Seq.iter - (fun path -> - let posPath = path.Replace(root, $"{outDir}") + let totalPaths = + [| for key in map.Keys do + yield! + Directory.EnumerateFiles(Path.GetFullPath(key), "*.*", opts) |] - try - Path.GetDirectoryName posPath - |> Directory.CreateDirectory - |> ignore - with - | _ -> () + let includedFiles = + totalPaths + |> Array.takeWhile + (fun path -> + copyIncludes + |> List.exists (fun ext -> path.Contains(ext))) - File.Copy(path, posPath)) + let excludedFiles = + totalPaths + |> Array.skipWhile + (fun path -> + copyExcludes + |> List.exists (fun ext -> path.Contains(ext))) + + [| yield! includedFiles + yield! excludedFiles |] + |> Array.Parallel.iter + (fun path -> + let posPath = path.Replace(root, $"{outDir}") + + try + Path.GetDirectoryName posPath + |> Directory.CreateDirectory + |> ignore + with + | _ -> () + + File.Copy(path, posPath)) devServer.mountDirectories |> Option.map getDirectories diff --git a/src/Perla/Types.fs b/src/Perla/Types.fs index f5c4df3..966e212 100644 --- a/src/Perla/Types.fs +++ b/src/Perla/Types.fs @@ -80,9 +80,14 @@ module Types = liveReload = Some true useSSL = Some false } + type CopyPaths = + { ``include``: (string seq) option + exclude: (string seq) option } + type BuildConfig = { esBuildPath: string option esbuildVersion: string option + copyPaths: CopyPaths option target: string option outDir: string option bundle: bool option @@ -93,10 +98,31 @@ module Types = injects: (string seq) option externals: (string seq) option } + static member DefaultExcludes() = + [ "index.html" + ".fsproj" + ".fable" + "fable_modules" + "bin" + "obj" + ".fs" + ".js" + ".css" + ".ts" + ".jsx" + ".tsx" ] + static member DefaultConfig() = { esBuildPath = None esbuildVersion = Some Constants.Esbuild_Version + copyPaths = + { ``include`` = None + exclude = + BuildConfig.DefaultExcludes() + |> Seq.ofList + |> Some } + |> Some target = Some "es2017" outDir = None bundle = Some true From de02352c02e259c0138f4b60016fb7847bfe3e3d Mon Sep 17 00:00:00 2001 From: "Angel D. Munoz" Date: Sat, 9 Oct 2021 23:37:44 -0500 Subject: [PATCH 2/5] use ?module to transform json modulesAllow include/exclude fiels from paths --- src/App/{public => assets}/favicon.ico | Bin src/App/assets/manifest.webmanifest | 10 ++++ src/App/index.html | 2 + src/App/perla.jsonc | 2 +- src/App/src/App.fs | 2 +- src/Perla/Build.fs | 72 ++++++++++++++++--------- src/Perla/Server.fs | 13 +++-- src/Perla/Types.fs | 26 +++++++++ 8 files changed, 96 insertions(+), 31 deletions(-) rename src/App/{public => assets}/favicon.ico (100%) create mode 100644 src/App/assets/manifest.webmanifest diff --git a/src/App/public/favicon.ico b/src/App/assets/favicon.ico similarity index 100% rename from src/App/public/favicon.ico rename to src/App/assets/favicon.ico diff --git a/src/App/assets/manifest.webmanifest b/src/App/assets/manifest.webmanifest new file mode 100644 index 0000000..c87f98a --- /dev/null +++ b/src/App/assets/manifest.webmanifest @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/web-manifest-combined.json", + "name": "App", + "description": "Some App", + "start_url": "/", + "lang": "en-US", + "background_color": "#FFFFFF", + "display": "standalone", + "orientation": "portrait" +} diff --git a/src/App/index.html b/src/App/index.html index dd89fe9..b9fc04d 100644 --- a/src/App/index.html +++ b/src/App/index.html @@ -5,6 +5,8 @@ F# Dev Server Test Ground + +