diff --git a/src/Fable.Cli/Entry.fs b/src/Fable.Cli/Entry.fs index cdd7c8e792..74921cbfb8 100644 --- a/src/Fable.Cli/Entry.fs +++ b/src/Fable.Cli/Entry.fs @@ -88,6 +88,11 @@ let knownCliArgs () = [ "--yes" ], [ "Automatically reply 'yes' (e.g. with `clean` command)" ] [ "--noRestore" ], [ "Skip `dotnet restore`" ] [ "--noCache" ], [ "Recompile all files, including sources from packages" ] + [ "--noGitignore" ], + [ + "Don't generate a `.gitignore` file in the `fable_modules` folder" + "(Useful when publishing the compiled output, e.g. to npm)" + ] [ "--exclude" ], [ "Don't merge sources of referenced projects with specified pattern" @@ -366,6 +371,7 @@ type Runner = SourceMapsRoot = args.Value "--sourceMapsRoot" NoRestore = args.FlagEnabled "--noRestore" NoCache = args.FlagEnabled "--noCache" + NoGitignore = args.FlagEnabled "--noGitignore" // TODO: If we select optimize we cannot have F#/Fable parallelization NoParallelTypeCheck = args.FlagEnabled "--noParallelTypeCheck" Exclude = args.Values "--exclude" diff --git a/src/Fable.Compiler/ProjectCracker.fs b/src/Fable.Compiler/ProjectCracker.fs index e91104e4d8..ffdb1a9419 100644 --- a/src/Fable.Compiler/ProjectCracker.fs +++ b/src/Fable.Compiler/ProjectCracker.fs @@ -80,7 +80,10 @@ type CacheInfo = let getFableModulesFromDir (baseDir: string) : string = IO.Path.Combine(baseDir, Naming.fableModules) |> Path.normalizePath -let getFableModulesFromProject (projDir: string, outDir: string option, noCache: bool, evaluateOnly: bool) : string = +let getFableModulesFromProject + (projDir: string, outDir: string option, noCache: bool, noGitignore: bool, evaluateOnly: bool) + : string + = let fableModulesDir = outDir |> Option.defaultWith (fun () -> projDir) |> getFableModulesFromDir @@ -95,7 +98,8 @@ let getFableModulesFromProject (projDir: string, outDir: string option, noCache: if File.isDirectoryEmpty fableModulesDir then IO.Directory.CreateDirectory(fableModulesDir) |> ignore - IO.File.WriteAllText(IO.Path.Combine(fableModulesDir, ".gitignore"), "**/*") + if not noGitignore then + IO.File.WriteAllText(IO.Path.Combine(fableModulesDir, ".gitignore"), "**/*") fableModulesDir @@ -103,7 +107,7 @@ type CrackerOptions(cliArgs: CliArgs, evaluateOnly: bool) = let projDir = IO.Path.GetDirectoryName cliArgs.ProjectFile let fableModulesDir = - getFableModulesFromProject (projDir, cliArgs.OutDir, cliArgs.NoCache, evaluateOnly) + getFableModulesFromProject (projDir, cliArgs.OutDir, cliArgs.NoCache, cliArgs.NoGitignore, evaluateOnly) let builtDlls = HashSet() @@ -157,7 +161,8 @@ type CrackerOptions(cliArgs: CliArgs, evaluateOnly: bool) = IO.Directory.CreateDirectory(fableModulesDir) |> ignore - IO.File.WriteAllText(IO.Path.Combine(fableModulesDir, ".gitignore"), "**/*") + if not cliArgs.NoGitignore then + IO.File.WriteAllText(IO.Path.Combine(fableModulesDir, ".gitignore"), "**/*") type CrackerResponse = { diff --git a/src/Fable.Compiler/Util.fs b/src/Fable.Compiler/Util.fs index fb2de98baa..386215f0d5 100644 --- a/src/Fable.Compiler/Util.fs +++ b/src/Fable.Compiler/Util.fs @@ -24,6 +24,7 @@ type CliArgs = Configuration: string NoRestore: bool NoCache: bool + NoGitignore: bool NoParallelTypeCheck: bool SourceMaps: bool SourceMapsRoot: string option diff --git a/src/Fable.Compiler/Util.fsi b/src/Fable.Compiler/Util.fsi index 35fdbddf88..b96eabb8bb 100644 --- a/src/Fable.Compiler/Util.fsi +++ b/src/Fable.Compiler/Util.fsi @@ -23,6 +23,7 @@ type CliArgs = Configuration: string NoRestore: bool NoCache: bool + NoGitignore: bool NoParallelTypeCheck: bool SourceMaps: bool SourceMapsRoot: string option diff --git a/tests/Integration/Compiler/Util/Compiler.fs b/tests/Integration/Compiler/Util/Compiler.fs index 7d73591e71..4a6b62ffa7 100644 --- a/tests/Integration/Compiler/Util/Compiler.fs +++ b/tests/Integration/Compiler/Util/Compiler.fs @@ -46,6 +46,7 @@ module Compiler = SourceMapsRoot = None NoRestore = false NoCache = false + NoGitignore = false NoParallelTypeCheck = false Exclude = ["Fable.Core"] Replace = Map.empty