Skip to content

Commit

Permalink
Save WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Oct 31, 2023
1 parent ab42348 commit 9648c11
Show file tree
Hide file tree
Showing 164 changed files with 28,001 additions and 132 deletions.
1 change: 1 addition & 0 deletions .fantomasignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/**
tests/**
tests_external/**
!src/Fable.Build/**
3 changes: 2 additions & 1 deletion src/Fable.Build/Fable.Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
<Compile Include="FableLibrary/TypeScript.fs" />
<Compile Include="FableLibrary/JavaScript.fs" />
<Compile Include="FableLibrary/Rust.fs" />
<Compile Include="Standalone.fs" />
<Compile Include="Test/Standalone.fs" />
<Compile Include="Test/JavaScript.fs" />
<Compile Include="Test/Python.fs" />
<Compile Include="Test/Rust.fs" />
<Compile Include="Test/Dart.fs" />
<Compile Include="Test/TypeScript.fs" />
<Compile Include="Test/Integration.fs" />
<Compile Include="Test/CompilerJs.fs" />
<Compile Include="Quicktest/Core.fs" />
<Compile Include="Quicktest/TypeScript.fs" />
<Compile Include="Quicktest/JavaScript.fs" />
<Compile Include="Quicktest/Python.fs" />
<Compile Include="Quicktest/Rust.fs" />
<Compile Include="Quicktest/Dart.fs" />
<Compile Include="FcsRepo.fs" />
<Compile Include="Standalone.fs" />
<Compile Include="Publish.fs" />
<Compile Include="GithubRelease.fs" />
<Compile Include="Main.fs" />
Expand Down
1 change: 1 addition & 0 deletions src/Fable.Build/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ let main argv =
| "rust" :: args -> Test.Rust.handle args
| "integration" :: args -> Test.Integration.handle args
| "standalone" :: _ -> Test.Standalone.handle args
| "compiler-js" :: _ -> Test.CompilerJs.handle args
| _ -> printHelp ()
| "quicktest" :: args ->
match args with
Expand Down
97 changes: 45 additions & 52 deletions src/Fable.Build/Standalone.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,68 @@ open SimpleExec
open Build.Utils
open BlackFox.CommandLine
open System.IO
open Build.FableLibrary

let private projectDir = Path.Resolve("src", "fable-standalone", "src")
let private projectDir = Path.Resolve("src", "fable-standalone")

let private buildDir = Path.Resolve("temp", "fable-standalone")
let private buildDir = Path.Combine(projectDir, "temp")

let private distDir = Path.Resolve("src", "fable-standalone", "dist")
let private distDir = Path.Combine(projectDir, "dist")

let handle (args: string list) =
let minify = args |> List.contains "--no-minify" |> not
let isWatch = args |> List.contains "--watch"

let rollupOutput =
match isWatch, minify with
| true, _ -> failwith "Not supported yet"
| false, true -> distDir </> "bundle.min.js"
| false, false -> buildDir </> "bundle.js"

let rollupArgs =
CmdLine.empty
|> CmdLine.appendRaw (buildDir </> "bundle/Main.js")
|> CmdLine.appendPrefix "--output" rollupOutput
|> CmdLine.appendPrefix "--format" "umd"
|> CmdLine.appendPrefix "--name" "__FABLE_STANDALONE__"
|> CmdLine.toString
let build () =

let fableArgs =
CmdLine.concat [
CmdLine.empty
|> CmdLine.appendPrefix "--outDir" (buildDir </> "bundle")
|> CmdLine.appendRaw "src"
|> CmdLine.appendPrefix "--outDir" buildDir
|> CmdLine.appendPrefix "--lang" "javascript"

if isWatch then
CmdLine.empty
|> CmdLine.appendRaw "--watch"
|> CmdLine.appendPrefix "--run" "rollup"
|> CmdLine.appendRaw rollupArgs
|> CmdLine.appendRaw "--watch"
// if isWatch then
// CmdLine.empty
// |> CmdLine.appendRaw "--watch"
// |> CmdLine.appendPrefix "--run" "rollup"
// // |> CmdLine.appendRaw rollupArgs
// |> CmdLine.appendRaw "--watch"
]

// Clean destination folders and ensure they exist
Directory.clean buildDir
Directory.clean distDir

if isWatch then
failwith "Not supported yet"
else
// Build standalone bundle
Command.Fable(fableArgs, workingDirectory = projectDir)

Command.Run("npx", $"rollup {rollupArgs}")
// Build standalone bundle
Command.Fable(fableArgs, workingDirectory = projectDir)

if minify then
Command.Run(
"npx",
CmdLine.empty
|> CmdLine.appendRaw "terser"
|> CmdLine.appendPrefix "--output" (distDir </> "bundle.min.js")
|> CmdLine.appendRaw "--mangle"
|> CmdLine.appendRaw "--compress"
|> CmdLine.toString
)

// let printFileSize (fileName: string) =
// let fileInfo = FileInfo(distDir </> fileName)
// Compile project as a library using Vite
Command.Run(
"npx",
CmdLine.empty
|> CmdLine.appendRaw "rollup"
|> CmdLine.appendRaw (buildDir </> "Main.js")
|> CmdLine.appendPrefix "-o" (distDir </> "bundle.js")
|> CmdLine.appendPrefix "--format" "umd"
|> CmdLine.appendPrefix "--name" "__FABLE_STANDALONE__"
|> CmdLine.toString,
workingDirectory = projectDir
)

// let size =
// float (fileInfo.Length) / 1000.0
Command.Run(
"npx",
CmdLine.empty
|> CmdLine.appendRaw "esbuild"
|> CmdLine.appendRaw (distDir </> "bundle.js")
|> CmdLine.appendRaw "--bundle"
|> CmdLine.appendRaw $"""--outfile={(distDir </> "bundle.js")}"""
|> CmdLine.appendRaw "--format=esm"
|> CmdLine.appendRaw "--platform=node"
|> CmdLine.appendRaw "--minify"
|> CmdLine.appendRaw "--overwrite"
|> CmdLine.toString,
workingDirectory = projectDir
)

// printfn $"Bundle size: %.2f{size} KB"
let handle (args: string list) =
let minify = args |> List.contains "--no-minify" |> not
let isWatch = args |> List.contains "--watch"

// printFileSize "bundle.min.js"
// printFileSize "working.min.js"
build ()
55 changes: 55 additions & 0 deletions src/Fable.Build/Test/CompilerJs.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Build.Test.CompilerJs

open Build.FableLibrary
open System.IO
open System
open BlackFox.CommandLine
open Build.Utils
open Build
open SimpleExec
open Fake.IO


let private mainTestProject =
Path.Resolve("tests", "Js", "Main", "Fable.Tests.fsproj")

let private fableCompilerJsDir = Path.Resolve("src", "fable-compiler-js")
let private buildDir = Path.Combine(fableCompilerJsDir, "temp")
let private distDir = Path.Combine(fableCompilerJsDir, "dist")

module private FableLib =

let source = Path.Resolve("temp", "fable-library")
let destination = Path.Combine(fableCompilerJsDir, "fable-library")

module private FableMetadata =

let source = Path.Resolve("src", "fable-metadata", "lib")
let destination = Path.Combine(fableCompilerJsDir, "fable-metadata")

let handle (args: string list) =
// BuildFableLibraryJavaScript().Run()

// Standalone.build ()

// Clean up temp folders
Directory.clean buildDir
Directory.clean distDir
// Clean up destination folders and make sure they exist
Directory.clean FableLib.destination
Directory.clean FableMetadata.destination

Command.Fable(
CmdLine.empty
|> CmdLine.appendRaw "src"
|> CmdLine.appendPrefix "--outDir" buildDir
|> CmdLine.appendPrefix "--exclude" "Fable.Core",
workingDirectory = fableCompilerJsDir
)

Command.Run("npx", "vite build", workingDirectory = fableCompilerJsDir)

Shell.copyRecursive FableLib.source FableLib.destination true |> ignore

Shell.copyRecursive FableMetadata.source FableMetadata.destination true
|> ignore
2 changes: 1 addition & 1 deletion src/Fable.Build/Test/Standalone.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let handleStandaloneFast () =
)

// Make sure the projects are restored
// Otherwise, on a first VM dependencies can be missing
// Otherwise, on a first VM run dependencies can be missing
Command.Run("dotnet", $"restore {mainTestProject}")

Command.Run(
Expand Down
Loading

0 comments on commit 9648c11

Please sign in to comment.