如何运行多个grunt脚本



我试图从脚本运行多个CLI命令。grunt的后期安装。我不知道怎么让两个都跑。如果我添加第二个命令,两者都不会运行。它们分别在安装后和控制台中工作。

我试着把它们包装在一个数组中:

"scripts": {
    "postinstall": ["node_modules/.bin/bower install", "grunt setup"]
},

我试着用分号把它们分开:

  "scripts": {
    "postinstall": "node_modules/.bin/bower install; grunt setup"
  },

我似乎找不到NPM脚本的解决方案

这些部分的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'
]);

如果它有帮助,这里是我的软件包的精简版本。我截取了上面的代码示例,主要是提供上下文。

{
  "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
  }
}

你可以使用&&要在NPM脚本部分运行多个命令

"scripts": {
    "postinstall": "bower install && grunt setup"
},

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

post_install.sh:

#!/bin/bash
node_modules/.bin/bower install
grunt setup

package.json:

"scripts": {
    "postinstall": "./post_install.sh"
  },

最新更新