javascript - 你如何运行多个 grunt scripts.postinstall?

标签 javascript node.js gruntjs bower

我正在尝试从 grunt 的 scripts.postinstall 运行多个 CLI 命令。我不知道如何让两者都运行。如果我添加第二个命令都不会运行。它们分别在安装后和控制台中工作。

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

"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 的精简版本,我剪掉了上面的代码示例,主要是为了提供上下文。

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

关于javascript - 你如何运行多个 grunt scripts.postinstall?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24440792/

相关文章:

Javascript:使用 jquery 编辑预览

javascript - Nodejs : Good practice to just use the index. js 导出?

gruntjs - 使用grunt-contrib-connect-具有添加的上下文路径的打开页面URL

javascript - Grunt Wiredep 不更新脚本标签

javascript - 如何让 JavaScript 进入 IE 内置调试​​器 (F12) 而不是 Visual Studio 调试器?

javascript - GSM 扩展无法在 Web 浏览器上播放

javascript - Jquery Ajax 无法在 Firefox 中运行(在以前的版本中可以运行),但可以在 Chrome 中运行

node.js - 无法使用 npm 在我的 Windows 上安装 socket.io

node.js - 通过socket.io向所有连接到nodejs服务器的客户端广播更新的数据

css - Grunt php 和 css 生成