Skip to content

Commit

Permalink
Added --fableLib arg
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave authored and alfonsogarciacaro committed Nov 16, 2020
1 parent 00aadd5 commit 5ded459
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Fable.Cli/Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ module Imports =
let importPath =
if importPath.StartsWith("${outDir}")
// NOTE: Path.Combine in Fable Prelude trims / at the start
// of the 2nd argument, unline .NET IO.Path.Combine
// of the 2nd argument, unlike .NET IO.Path.Combine
then Path.Combine(outDir, importPath.Replace("${outDir}", ""))
else importPath
let sourceDir = Path.GetDirectoryName(sourcePath)
Expand Down
2 changes: 1 addition & 1 deletion src/fable-compiler-js/src/Platform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Fable.Core.JsInterop

type CmdLineOptions = {
outDir: string option
// fableDir: string option
libDir: string option
benchmark: bool
optimize: bool
// sourceMaps: bool
Expand Down
16 changes: 8 additions & 8 deletions src/fable-compiler-js/src/app.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ module Imports =
let importPath =
if importPath.StartsWith("${outDir}")
// NOTE: Path.Combine in Fable Prelude trims / at the start
// of the 2nd argument, unline .NET IO.Path.Combine
then Path.Combine(outDir, importPath.Replace("${outDir}", ""))
// of the 2nd argument, unlike .NET IO.Path.Combine
then Path.Combine(outDir, importPath.Replace("${outDir}", "")) |> normalizeFullPath
else importPath
let sourceDir = Path.GetDirectoryName(sourcePath)
let targetDir = Path.GetDirectoryName(targetPath)
Expand Down Expand Up @@ -151,7 +151,7 @@ let parseFiles projectFileName options =

// Fable (F# to JS)
let projDir = projectFileName |> normalizeFullPath |> Path.GetDirectoryName
let libDir = getFableLibDir() |> normalizeFullPath
let libDir = options.libDir |> Option.defaultValue (getFableLibDir()) |> normalizeFullPath
let parseFable (res, fileName) =
fable.CompileToBabelAst(libDir, res, fileName,
typedArrays = options.typedArrays,
Expand Down Expand Up @@ -201,15 +201,15 @@ let parseFiles projectFileName options =
writeAllText outPath writer.Result
} |> runAsync

let argValue key (args: string[]) =
let argValue keys (args: string[]) =
args
|> Array.pairwise
|> Array.tryPick (fun (k, v) ->
if k = key && not (v.StartsWith("-"))
if (List.contains k keys) && not (v.StartsWith("-"))
then Some v else None)

let tryFlag flag (args: string[]) =
match argValue flag args with
match argValue [flag] args with
| Some flag ->
match System.Boolean.TryParse(flag) with
| true, flag -> Some flag
Expand All @@ -231,8 +231,8 @@ let run opts projectFileName outDir =
let runArgs = opts.[i+1..] |> String.concat " "
sprintf "node %s %s" scriptFile runArgs)
let options = {
outDir = opts |> argValue "--outDir" |> Option.orElse outDir
// fableDir = opts |> argValue "--fableDir"
outDir = opts |> argValue ["--outDir"; "-o"] |> Option.orElse outDir
libDir = opts |> argValue ["--fableLib"]
benchmark = opts |> hasFlag "--benchmark"
optimize = opts |> hasFlag "--optimize"
// sourceMaps = opts |> hasFlag "--sourceMaps"
Expand Down
2 changes: 1 addition & 1 deletion src/fable-standalone/test/bench-compiler/Platform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Fable.Compiler.Platform

type CmdLineOptions = {
outDir: string option
// fableDir: string option
libDir: string option
benchmark: bool
optimize: bool
// sourceMaps: bool
Expand Down
20 changes: 8 additions & 12 deletions src/fable-standalone/test/bench-compiler/app.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ module Imports =
let importPath =
if importPath.StartsWith("${outDir}")
// NOTE: Path.Combine in Fable Prelude trims / at the start
// of the 2nd argument, unline .NET IO.Path.Combine
then Path.Combine(outDir, importPath.Replace("${outDir}", ""))
// of the 2nd argument, unlike .NET IO.Path.Combine
then Path.Combine(outDir, importPath.Replace("${outDir}", "")) |> normalizeFullPath
else importPath
let sourceDir = Path.GetDirectoryName(sourcePath)
let targetDir = Path.GetDirectoryName(targetPath)
Expand Down Expand Up @@ -141,11 +141,7 @@ let parseFiles projectFileName options =

// Fable (F# to JS)
let projDir = projectFileName |> normalizeFullPath |> Path.GetDirectoryName
let libDir =
// special case for fable-library, the libDir is the outDir
if options.typescript && projectFileName.EndsWith("Fable.Library.fsproj") && Option.isSome options.outDir
then options.outDir.Value |> normalizeFullPath
else getFableLibDir() |> normalizeFullPath
let libDir = options.libDir |> Option.defaultValue (getFableLibDir()) |> normalizeFullPath

let parseFable (res, fileName) =
fable.CompileToBabelAst(libDir, res, fileName,
Expand Down Expand Up @@ -196,15 +192,15 @@ let parseFiles projectFileName options =
writeAllText outPath writer.Result
} |> runAsync

let argValue key (args: string[]) =
let argValue keys (args: string[]) =
args
|> Array.pairwise
|> Array.tryPick (fun (k, v) ->
if k = key && not (v.StartsWith("-"))
if (List.contains k keys) && not (v.StartsWith("-"))
then Some v else None)

let tryFlag flag (args: string[]) =
match argValue flag args with
match argValue [flag] args with
| Some flag ->
match System.Boolean.TryParse(flag) with
| true, flag -> Some flag
Expand All @@ -226,8 +222,8 @@ let run opts projectFileName outDir =
let runArgs = opts.[i+1..] |> String.concat " "
sprintf "node %s %s" scriptFile runArgs)
let options = {
outDir = opts |> argValue "--outDir" |> Option.orElse outDir
// fableDir = opts |> argValue "--fableDir"
outDir = opts |> argValue ["--outDir"; "-o"] |> Option.orElse outDir
libDir = opts |> argValue ["--fableLib"]
benchmark = opts |> hasFlag "--benchmark"
optimize = opts |> hasFlag "--optimize"
// sourceMaps = opts |> hasFlag "--sourceMaps"
Expand Down
8 changes: 4 additions & 4 deletions src/fable-standalone/test/bench-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"scripts": {
"build-cli": "dotnet run -c Release -p ../../../Fable.Cli -- bench-compiler.fsproj --outDir out-node",
"postbuild-cli": "npm run rollup-bundle",

"prebuild-dotnet": "git clean -fdx",
"build-dotnet": "dotnet run -c Release bench-compiler.fsproj out-node",
Expand All @@ -24,10 +25,10 @@
"terser-bundle": "npm run terser -- dist/bundle.js -o dist/bundle.min.js --mangle --compress",
"webpack-bundle": "npm run webpack -- -p --entry ./out-node/app.js --output ./dist/bundle.min.js --target node",

"prebuild-lib-dotnet": "git clean -fdx",
"build-lib-dotnet": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib",
"prebuild-lib-dotnet": "git clean -fdx && npm run tsc -- -p ../../../fable-library --outDir ./out-lib",
"build-lib-dotnet": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --fableLib out-lib",
"prebuild-lib-dotnet-ts": "git clean -fdx && mkdir out-lib && cp -R ../../../fable-library/*.ts out-lib",
"build-lib-dotnet-ts": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --typescript",
"build-lib-dotnet-ts": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --typescript --fableLib out-lib",
"tsc-lib-init": "npm run tsc -- --init --target es2020 --module es2020 --allowJs",
"tsc-lib": "npm run tsc -- -p ./out-lib --outDir ./out-lib-js",

Expand All @@ -39,7 +40,6 @@
"build-test-node-ts": "node out-node/app.js ../../../../../fable-test/fable-test.fsproj out-test --typescript",
"test-node": "node ./out-test/src/test.js",

"prebuild-tests-dotnet": "git clean -fdx",
"build-tests-dotnet": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests",
"build-tests-dotnet-ts": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests --typescript",
"build-tests-dotnet-opt": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests --optimize",
Expand Down

0 comments on commit 5ded459

Please sign in to comment.