我试图从scripts.postinstall grunt运行多个CLI命令。我无法弄清楚如何让两者都运行起来。如果我添加第二个命令既不运行。另外,他们都在postinstall和控制台上工作。
我尝试将它们包装成阵列:
"scripts": {
"postinstall": ["node_modules/.bin/bower install", "grunt setup"]
},
我尝试用分号分隔它们:
"scripts": {
"postinstall": "node_modules/.bin/bower install; grunt setup"
},
我似乎无法在NPM Scripts
上找到解决方案这些部分的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'
]);
如果它有帮助我的package.json的一个parred down版本,我剪断了上面的代码示例,主要是为了提供上下文。
{
"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@me.com"
},
"license": "MIT",
"homepage": "https://someurl.com",
"bugs": {
"url": "someurl.com"
},
"devDependencies": {
"grunt": "^0.4.5",
"bower" : "~1.3.5",
etc
}
}
答案 0 :(得分:44)
你可以使用&&在npm脚本部分中运行多个命令
"scripts": {
"postinstall": "bower install && grunt setup"
},
答案 1 :(得分:10)
您可以尝试编写执行这两个命令的Bash脚本,然后运行它。
post_install.sh:
#!/bin/bash
node_modules/.bin/bower install
grunt setup
的package.json:
"scripts": {
"postinstall": "./post_install.sh"
},