你如何运行多个grunt脚本.postinstall?

mtp*_*ltz 18 javascript node.js gruntjs bower

我正在尝试从scripts.postinstall的grunt运行多个CLI命令.我无法弄清楚如何让两者都运行.如果我添加第二个命令既不运行.另外,他们都在postinstall和控制台上工作.

我已经尝试将它们包装在一个数组中:

"scripts": {
    "postinstall": ["node_modules/.bin/bower install", "grunt setup"]
},
Run Code Online (Sandbox Code Playgroud)

我尝试用分号分隔它们:

  "scripts": {
    "postinstall": "node_modules/.bin/bower install; grunt setup"
  },
Run Code Online (Sandbox Code Playgroud)

我似乎无法在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'
]);
Run Code Online (Sandbox Code Playgroud)

如果它有助于我的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
  }
}
Run Code Online (Sandbox Code Playgroud)

ken*_*ner 53

您可以使用&&在npm脚本部分中运行多个命令

"scripts": {
    "postinstall": "bower install && grunt setup"
},
Run Code Online (Sandbox Code Playgroud)


ctl*_*cko 10

您可以尝试编写执行这两个命令的Bash脚本,然后运行它.

post_install.sh:

#!/bin/bash
node_modules/.bin/bower install
grunt setup
Run Code Online (Sandbox Code Playgroud)

的package.json:

"scripts": {
    "postinstall": "./post_install.sh"
  },
Run Code Online (Sandbox Code Playgroud)