如何编写跨平台工作的 Npm 脚本命令
How to write a Npm Script Command that works cross platform
我正在尝试编写一个与 openshift 配合使用的安装后命令来安装 bower 依赖项。我已经设法让它工作了,这很棒。
"scripts": {
"postinstall": "HOME=$OPENSHIFT_REPO_DIR bower install"
}
我现在正在尝试改进该命令,以便我可以 运行 在我的 windows PC 上本地执行以下命令。
npm install
它抛出一个错误:
PS D:\dev\cgb14\code\trunk\solution\App> npm install
> warcher_app@1.0.0 postinstall D:\dev\cgb14\code\trunk\solution\App
> HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install
'HOME' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "D:\Program Files\nodejs\\node.exe" "D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "ins
tall"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code ELIFECYCLE
npm ERR! warcher_app@1.0.0 postinstall: `HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the warcher_app@1.0.0 postinstall script 'HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install'.
npm ERR! This is most likely a problem with the warcher_app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install
npm ERR! You can get their info via:
npm ERR! npm owner ls warcher_app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\dev\cgb14\code\trunk\solution\App\npm-debug.log
有谁知道如何改进安装后脚本以使其也适用于 windows?
我一直在搜索有关 npm 命令可以执行的操作的文档,并查看是否存在跨平台 if exists 语句。我在想它应该是这样的,如果 $OPENSHIFT_REPO_DIR 存在,就这样做...否则做其他事情...
好的,在我发布这篇文章 5 分钟后,我想到了一些我还没有尝试过的东西。命令中的简单 OR 起作用了。我现在可以在 Windows 和 Openshift
上 运行
"scripts": {
"postinstall": "HOME=$OPENSHIFT_REPO_DIR bower install || bower install"
}
我正在尝试编写一个与 openshift 配合使用的安装后命令来安装 bower 依赖项。我已经设法让它工作了,这很棒。
"scripts": {
"postinstall": "HOME=$OPENSHIFT_REPO_DIR bower install"
}
我现在正在尝试改进该命令,以便我可以 运行 在我的 windows PC 上本地执行以下命令。
npm install
它抛出一个错误:
PS D:\dev\cgb14\code\trunk\solution\App> npm install
> warcher_app@1.0.0 postinstall D:\dev\cgb14\code\trunk\solution\App
> HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install
'HOME' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "D:\Program Files\nodejs\\node.exe" "D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "ins
tall"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code ELIFECYCLE
npm ERR! warcher_app@1.0.0 postinstall: `HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the warcher_app@1.0.0 postinstall script 'HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install'.
npm ERR! This is most likely a problem with the warcher_app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! HOME=$OPENSHIFT_REPO_DIR node_modules/.bin/bower install
npm ERR! You can get their info via:
npm ERR! npm owner ls warcher_app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\dev\cgb14\code\trunk\solution\App\npm-debug.log
有谁知道如何改进安装后脚本以使其也适用于 windows?
我一直在搜索有关 npm 命令可以执行的操作的文档,并查看是否存在跨平台 if exists 语句。我在想它应该是这样的,如果 $OPENSHIFT_REPO_DIR 存在,就这样做...否则做其他事情...
好的,在我发布这篇文章 5 分钟后,我想到了一些我还没有尝试过的东西。命令中的简单 OR 起作用了。我现在可以在 Windows 和 Openshift
上 运行"scripts": {
"postinstall": "HOME=$OPENSHIFT_REPO_DIR bower install || bower install"
}