javascript 你如何运行多个 grunt scripts.postinstall?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24440792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you run multiple grunt scripts.postinstall?
提问by mtpultz
I'm trying to run multiple CLI commands from scripts.postinstall of grunt. I can't figure out how to get both to run. If I add the second command neither run. Separately they both work on postinstall and in the console.
我正在尝试从 grunt 的 scripts.postinstall 运行多个 CLI 命令。我不知道如何让两者都运行。如果我添加第二个命令既不运行。它们分别在安装后和控制台中工作。
I've tried wrapping them in an array:
我试过将它们包装在一个数组中:
"scripts": {
"postinstall": ["node_modules/.bin/bower install", "grunt setup"]
},
I tried separating them with a semi-colon:
我尝试用分号分隔它们:
"scripts": {
"postinstall": "node_modules/.bin/bower install; grunt setup"
},
I can't seem to find the solution on NPM Scripts
我似乎无法在NPM Scripts上找到解决方案
My gruntfile.js for these sections look like this:
这些部分的 gruntfile.js 如下所示:
mkdir: {
setup: {
options: {
create: [
'app/main/source/www', 'app/main/build', 'app/main/docs', 'app/main/tests',
'app/development',
'app/releases'
]
}
}
}
grunt.registerTask('setup', [
'mkdir:setup',
'bowercopy:wordpress'
]);
In case it helps here's a parred down version of my package.json that I snipped the above code examples, mostly to provide context.
如果它有帮助,这里有一个我的 package.json 的精简版本,我剪掉了上面的代码示例,主要是为了提供上下文。
{
"name": "webapp",
"version": "0.1.0",
"description": "A web app using bower and grunt",
"main": "gruntfile.js",
"scripts": {
"postinstall": "node_modules/.bin/bower install"
},
"repository": {
"type": "git",
"url": "someurl.com"
},
"keywords": [
"web", "app"
],
"author": {
"company": "somecompany",
"name": "somename",
"email": "[email protected]"
},
"license": "MIT",
"homepage": "https://someurl.com",
"bugs": {
"url": "someurl.com"
},
"devDependencies": {
"grunt": "^0.4.5",
"bower" : "~1.3.5",
etc
}
}
回答by kenwarner
You can use && to run multiple commands in the npm scripts section
您可以使用 && 在 npm 脚本部分运行多个命令
"scripts": {
"postinstall": "bower install && grunt setup"
},
回答by ctlacko
You could try writing a Bash script that executes those two commands and run that instead.
您可以尝试编写一个 Bash 脚本来执行这两个命令并运行它。
post_install.sh:
post_install.sh:
#!/bin/bash
node_modules/.bin/bower install
grunt setup
package.json:
包.json:
"scripts": {
"postinstall": "./post_install.sh"
},