diff --git a/build/BasicTasks.fs b/build/BasicTasks.fs index 90e04a7d..b6fe9cfc 100644 --- a/build/BasicTasks.fs +++ b/build/BasicTasks.fs @@ -7,6 +7,103 @@ open Fake.IO.Globbing.Operators open ProjectInfo +[] +module Helper = + + open Fake + open Fake.Core + + let createProcess exe arg dir = + CreateProcess.fromRawCommandLine exe arg + |> CreateProcess.withWorkingDirectory dir + |> CreateProcess.ensureExitCode + + module Proc = + + module Parallel = + + open System + + let locker = obj() + + let colors = [| + ConsoleColor.DarkYellow + ConsoleColor.DarkCyan + ConsoleColor.Magenta + ConsoleColor.Blue + ConsoleColor.Cyan + ConsoleColor.DarkMagenta + ConsoleColor.DarkBlue + ConsoleColor.Yellow + |] + + let print color (colored: string) (line: string) = + lock locker + (fun () -> + let currentColor = Console.ForegroundColor + Console.ForegroundColor <- color + Console.Write colored + Console.ForegroundColor <- currentColor + Console.WriteLine line) + + let onStdout index name (line: string) = + let color = colors.[index % colors.Length] + if isNull line then + print color $"{name}: --- END ---" "" + else if String.isNotNullOrEmpty line then + print color $"{name}: " line + + let onStderr name (line: string) = + let color = ConsoleColor.Red + if isNull line |> not then + print color $"{name}: " line + + let redirect (index, (name, createProcess)) = + createProcess + |> CreateProcess.redirectOutputIfNotRedirected + |> CreateProcess.withOutputEvents (onStdout index name) (onStderr name) + + let printStarting indexed = + for (index, (name, c: CreateProcess<_>)) in indexed do + let color = colors.[index % colors.Length] + let wd = + c.WorkingDirectory + |> Option.defaultValue "" + let exe = c.Command.Executable + let args = c.Command.Arguments.ToStartInfo + print color $"{name}: {wd}> {exe} {args}" "" + + let run cs = + cs + |> Seq.toArray + |> Array.indexed + |> fun x -> printStarting x; x + |> Array.map redirect + |> Array.Parallel.map Proc.run + + let dotnet = createProcess "dotnet" + + let npm = + let npmPath = + match ProcessUtils.tryFindFileOnPath "npm" with + | Some path -> path + | None -> + "npm was not found in path. Please install it and make sure it's available from your path. " + + "See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info" + |> failwith + + createProcess npmPath + + let run proc arg dir = + proc arg dir + |> Proc.run + |> ignore + + let runParallel processes = + processes + |> Proc.Parallel.run + |> ignore + let setPrereleaseTag = BuildTask.create "SetPrereleaseTag" [] { printfn "Please enter pre-release package suffix" let suffix = System.Console.ReadLine() diff --git a/build/Build.fs b/build/Build.fs index f9ddf97f..9f07e1a5 100644 --- a/build/Build.fs +++ b/build/Build.fs @@ -22,25 +22,25 @@ open ReleaseTasks let _release = BuildTask.createEmpty "Release" - [clean; build; runTests; pack; buildDocs; createTag; publishNuget; releaseDocs] + [clean; build; runTests; pack; buildDocs; createTag; publishNuget; publishNPM; releaseDocs] /// Full release of nuget package, git tag, and documentation for the prerelease version. let _preRelease = BuildTask.createEmpty "PreRelease" - [setPrereleaseTag; clean; build; runTests; packPrerelease; buildDocsPrerelease; createPrereleaseTag; publishNugetPrerelease; prereleaseDocs] + [setPrereleaseTag; clean; build; runTests; packPrerelease; buildDocsPrerelease; createPrereleaseTag; publishNugetPrerelease; publishNPMPrerelease; prereleaseDocs] /// Full release of nuget package for the prerelease version. let _releaseNoDocs = BuildTask.createEmpty "ReleaseNoDocs" - [clean; build; runTests; pack; createTag; publishNuget;] + [clean; build; runTests; pack; createTag; publishNuget; publishNPM] /// Full release of nuget package for the prerelease version. let _preReleaseNoDocs = BuildTask.createEmpty "PreReleaseNoDocs" - [setPrereleaseTag; clean; build; runTests; packPrerelease; createPrereleaseTag; publishNugetPrerelease] + [setPrereleaseTag; clean; build; runTests; packPrerelease; createPrereleaseTag; publishNugetPrerelease; publishNPMPrerelease;] ReleaseNotesTasks.updateReleaseNotes |> ignore diff --git a/build/PackageTasks.fs b/build/PackageTasks.fs index 375e3a09..029e896e 100644 --- a/build/PackageTasks.fs +++ b/build/PackageTasks.fs @@ -17,8 +17,8 @@ let private replaceCommitLink input = let commitLinkPattern = @"\[\[#[a-z0-9]*\]\(.*\)\] " Regex.Replace(input,commitLinkPattern,"") -let pack = BuildTask.create "Pack" [clean; build; runTests] { - if promptYesNo (sprintf "creating stable package with version %s OK?" stableVersionTag ) +let packDotNet = BuildTask.create "PackDotNet" [clean; build; runTests] { + if promptYesNo (sprintf "[.NET] creating stable package with version %s OK?" stableVersionTag ) then !! "src/**/*.*proj" -- "src/bin/*" @@ -39,8 +39,8 @@ let pack = BuildTask.create "Pack" [clean; build; runTests] { else failwith "aborted" } -let packPrerelease = BuildTask.create "PackPrerelease" [setPrereleaseTag; clean; build; runTests] { - if promptYesNo (sprintf "package tag will be %s OK?" prereleaseTag ) +let packDotNetPrerelease = BuildTask.create "PackDotNetPrerelease" [setPrereleaseTag; clean; build; runTests] { + if promptYesNo (sprintf "[.NET] creating prerelease package with version %s OK?" prereleaseTag ) then !! "src/**/*.*proj" -- "src/bin/*" @@ -61,4 +61,30 @@ let packPrerelease = BuildTask.create "PackPrerelease" [setPrereleaseTag; clean; )) else failwith "aborted" -} \ No newline at end of file +} + +module BundleJs = + let bundle (versionTag) = + run npm "run bundle" "" + Fake.IO.File.readAsString "package.json" + |> fun t -> + let t = t.Replace(ProjectInfo.stableVersionTag, versionTag) + Fake.IO.File.writeString false $"{ProjectInfo.npmPkgDir}/package.json" t + "" // "fable-library.**/**" + |> Fake.IO.File.writeString false $"{ProjectInfo.npmPkgDir}/fable_modules/.npmignore" + +let packJS = BuildTask.create "PackJS" [clean; build; runTests] { + if promptYesNo (sprintf "[NPM] creating stable package with version %s OK?" ProjectInfo.stableVersionTag ) + then + BundleJs.bundle ProjectInfo.stableVersionTag + else failwith "aborted" +} + +let packJSPrerelease = BuildTask.create "PackJSPrerelease" [setPrereleaseTag; clean; build; runTests] { + if promptYesNo (sprintf "[NPM] creating prerelease package with version %s OK?" ProjectInfo.prereleaseTag ) then + BundleJs.bundle ProjectInfo.prereleaseTag + else failwith "aborted" + } +let pack = BuildTask.createEmpty "Pack" [packDotNet; packJS] + +let packPrerelease = BuildTask.createEmpty "PackPrerelease" [packDotNetPrerelease;packJSPrerelease] \ No newline at end of file diff --git a/build/ProjectInfo.fs b/build/ProjectInfo.fs index 9cd8db73..2be9d678 100644 --- a/build/ProjectInfo.fs +++ b/build/ProjectInfo.fs @@ -22,6 +22,7 @@ let gitHome = $"https://github.com/{gitOwner}" let projectRepo = $"https://github.com/{gitOwner}/{project}" let pkgDir = "pkg" +let npmPkgDir = "dist" // Create RELEASE_NOTES.md if not existing. Or "release" would throw an error. Fake.Extensions.Release.ReleaseNotes.ensure() diff --git a/build/ReleaseNotesTasks.fs b/build/ReleaseNotesTasks.fs index 92a0f244..2a4c4c6d 100644 --- a/build/ReleaseNotesTasks.fs +++ b/build/ReleaseNotesTasks.fs @@ -15,7 +15,7 @@ let updateReleaseNotes = BuildTask.createFn "ReleaseNotes" [] (fun config -> let semVer = Fake.Core.ReleaseNotes.load "RELEASE_NOTES.md" - |> fun x -> x.SemVer.AsString + |> fun x -> sprintf "%i.%i.%i" x.SemVer.Major x.SemVer.Minor x.SemVer.Patch // Update Version in src/Nfdi4Plants.Fornax.Template/package.json let p = "package.json" diff --git a/build/ReleaseTasks.fs b/build/ReleaseTasks.fs index 965c9646..0c4cf609 100644 --- a/build/ReleaseTasks.fs +++ b/build/ReleaseTasks.fs @@ -35,7 +35,7 @@ let createPrereleaseTag = BuildTask.create "CreatePrereleaseTag" [setPrereleaseT let publishNuget = BuildTask.create "PublishNuget" [clean; build; runTests; pack] { let targets = (!! (sprintf "%s/*.*pkg" pkgDir )) for target in targets do printfn "%A" target - let msg = sprintf "release package with version %s?" stableVersionTag + let msg = sprintf "[.NET] release package with version %s?" stableVersionTag if promptYesNo msg then let source = "https://api.nuget.org/v3/index.json" let apikey = Environment.environVar "NUGET_KEY" @@ -48,7 +48,7 @@ let publishNuget = BuildTask.create "PublishNuget" [clean; build; runTests; pack let publishNugetPrerelease = BuildTask.create "PublishNugetPrerelease" [clean; build; runTests; packPrerelease] { let targets = (!! (sprintf "%s/*.*pkg" pkgDir )) for target in targets do printfn "%A" target - let msg = sprintf "release package with version %s?" prereleaseTag + let msg = sprintf "[.NET] release package with version %s?" prereleaseTag if promptYesNo msg then let source = "https://api.nuget.org/v3/index.json" let apikey = Environment.environVar "NUGET_KEY" @@ -58,6 +58,24 @@ let publishNugetPrerelease = BuildTask.create "PublishNugetPrerelease" [clean; b else failwith "aborted" } +let publishNPM = BuildTask.create "PublishNPM" [clean; build; runTests; packJS] { + let msg = sprintf "[NPM] release package with version %s?" stableVersionTag + if promptYesNo msg then + let apikey = Environment.environVarOrNone "NPM_KEY" + let otp = if apikey.IsSome then $" --otp + {apikey.Value}" else "" + run npm $"publish --access public{otp}" ProjectInfo.npmPkgDir + else failwith "aborted" +} + +let publishNPMPrerelease = BuildTask.create "PublishNPMPrerelease" [clean; build; runTests; packJSPrerelease] { + let msg = sprintf "[NPM] release package with version %s?" prereleaseTag + if promptYesNo msg then + let apikey = Environment.environVarOrNone "NPM_KEY" + let otp = if apikey.IsSome then $" --otp {apikey.Value}" else "" + run npm $"publish --access public --tag next{otp}" ProjectInfo.npmPkgDir + else failwith "aborted" +} + let releaseDocs = BuildTask.create "ReleaseDocs" [buildDocs] { let msg = sprintf "release docs for version %s?" stableVersionTag if promptYesNo msg then diff --git a/build/TestTasks.fs b/build/TestTasks.fs index f0774b63..62fdc78f 100644 --- a/build/TestTasks.fs +++ b/build/TestTasks.fs @@ -9,104 +9,6 @@ open BasicTasks [] let FableTestPath_input = "tests/FsSpreadsheet.Tests" -[] -module private Helper = - - open Fake - open Fake.Core - - let createProcess exe arg dir = - CreateProcess.fromRawCommandLine exe arg - |> CreateProcess.withWorkingDirectory dir - |> CreateProcess.ensureExitCode - - module Proc = - - module Parallel = - - open System - - let locker = obj() - - let colors = [| - ConsoleColor.DarkYellow - ConsoleColor.DarkCyan - ConsoleColor.Magenta - ConsoleColor.Blue - ConsoleColor.Cyan - ConsoleColor.DarkMagenta - ConsoleColor.DarkBlue - ConsoleColor.Yellow - |] - - let print color (colored: string) (line: string) = - lock locker - (fun () -> - let currentColor = Console.ForegroundColor - Console.ForegroundColor <- color - Console.Write colored - Console.ForegroundColor <- currentColor - Console.WriteLine line) - - let onStdout index name (line: string) = - let color = colors.[index % colors.Length] - if isNull line then - print color $"{name}: --- END ---" "" - else if String.isNotNullOrEmpty line then - print color $"{name}: " line - - let onStderr name (line: string) = - let color = ConsoleColor.Red - if isNull line |> not then - print color $"{name}: " line - - let redirect (index, (name, createProcess)) = - createProcess - |> CreateProcess.redirectOutputIfNotRedirected - |> CreateProcess.withOutputEvents (onStdout index name) (onStderr name) - - let printStarting indexed = - for (index, (name, c: CreateProcess<_>)) in indexed do - let color = colors.[index % colors.Length] - let wd = - c.WorkingDirectory - |> Option.defaultValue "" - let exe = c.Command.Executable - let args = c.Command.Arguments.ToStartInfo - print color $"{name}: {wd}> {exe} {args}" "" - - let run cs = - cs - |> Seq.toArray - |> Array.indexed - |> fun x -> printStarting x; x - |> Array.map redirect - |> Array.Parallel.map Proc.run - - let dotnet = createProcess "dotnet" - - let npm = - let npmPath = - match ProcessUtils.tryFindFileOnPath "npm" with - | Some path -> path - | None -> - "npm was not found in path. Please install it and make sure it's available from your path. " + - "See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info" - |> failwith - - createProcess npmPath - - let run proc arg dir = - proc arg dir - |> Proc.run - |> ignore - - let runParallel processes = - processes - |> Proc.Parallel.run - |> ignore - - module RunTests = /// runs `npm test` in root.