Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run multiple grunt scripts.postinstall?

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.

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

My gruntfile.js for these sections look like this:

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.

{
  "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
  }
}
like image 203
mtpultz Avatar asked Jun 26 '14 21:06

mtpultz


2 Answers

You can use && to run multiple commands in the npm scripts section

"scripts": {
    "postinstall": "bower install && grunt setup"
},
like image 187
kenwarner Avatar answered Oct 07 '22 23:10

kenwarner


You could try writing a Bash script that executes those two commands and run that instead.

post_install.sh:

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

package.json:

"scripts": {
    "postinstall": "./post_install.sh"
  },
like image 24
ctlacko Avatar answered Oct 07 '22 22:10

ctlacko