重要:
由于这是我认为许多人想要做的事情,我为FAKE添加了一个帮助程序:http://fsharp.github.io/FAKE/apidocs/fake-npmhelper.html
问题从这里开始:
我试图从假冒中运行NPM,但由于某种原因它不会起作用。
我的假目标看起来像这样:
Target "Web" (fun _ ->
let result =
ExecProcess (fun info ->
info.FileName <- "npm.cmd"
info.Arguments <- "install ./src/FAKESimple.Web/"
info.WorkingDirectory <- "."
) (System.TimeSpan.FromMinutes 1.0)
if result <> 0 then failwith "Operation failed or timed out"
trace "Hello World from FAKE"
)
我得到的错误信息是:
module.js:338
throw err;
^
Error: Cannot find module 'C:\dev\git\FAKESimpleDemo\node_modules\npm\bin\npm-
cli.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Running build failed.
Error:
System.Exception: Operation failed or timed out
at FSI_0001.clo@62-10.Invoke(Unit _arg2) in C:\Dev\git\FAKESimpleDemo\build
.fsx:line 69
at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 483
默认npm.cmd
如下所示:
:: Created by npm, please don't edit manually.
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
) ELSE (
node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
)
所以似乎%~dp0
被解析为ExecProcess
的工作目录,而不是npm.cmd
目标文件夹的路径。
如何解决这个问题或者如何从FAKE运行npm?
更新
我有一个示例项目,在此处说明:https://github.com/mastoj/FAKESimpleDemo/commit/1066c6d78cd0c8d8ab261f647118b30d15487c2f
它要求安装节点。
更新2:
我想我现在正在发生什么,但不知道如何解决它。如果从常规命令行运行npm
,一切正常,但如果运行"npm"
(注意引号),则会出现相同的错误。出于某种原因,%~dp0
会根据调用的内容进行不同的解析,这会发现很奇怪。
答案 0 :(得分:0)
我正在使用FAKE和PAKET来构建Angular 6应用并将其打包在NuGet包中。构建我的应用程序的目标如下:
Target.create "BuildAngular"( fun _ ->
Trace.setBuildNumber (CreateInformationalVersion versionInfo)
Npm.run "buildproductive" (fun o -> { o with WorkingDirectory = "./src"})
Directory.Move("./src/dist/", dirAngularOutput)
ZipFile.CreateFromDirectory (dirAngularOutput, dirBuildOutput @@ "gui.zip")
)
参数“ buildproductive”是我在scripts数组中的package.json中定义的目标:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"buildproductive": "node_modules/.bin/ng build --prod",
"test": "ng test",
"test:ci": "node_modules/.bin/ng test --karma-config=src/karma.ci.conf.js",
"test:headless": "node_modules/.bin/ng test --karma-config=src/karma.headless.conf.js",
"lint": "ng lint",
"e2e": "ng e2e"
}