skip to Main Content

I’m setting up a composer.json file to run some tasks automatically when executed.

The scripts look something like this:

"scripts": {
  "post-update-cmd": [
    "@createDir",
    "@installSlate",
    "@installConcat"
  ],
  "createDir": "npm install -g @shopify/slate",
  "installSlate": "slate theme blank_theme",
  "installConcat": "npm install grunt-contrib-concat --save-dev"
}

This works but it installs the grunt plugin in the root folder and not within the blank_theme. I’ve tried adding;

"installConcat": "cd blank_theme npm install grunt-contrib-concat --save-dev"

or adding another command in to go the blank_theme directory so something like;

"scripts": {
  "post-update-cmd": [
    "@createDir",
    "@installSlate",
    "@moveDir",
    "@installConcat"
  ],
  "createDir": "npm install -g @shopify/slate",
  "installSlate": "slate theme blank_theme",
  "moveDir": "cd blank_theme",
  "installConcat": "npm install grunt-contrib-concat --save-dev"
}

But no luck. Any ideas how to achieve this?

2

Answers


  1. Chosen as BEST ANSWER

    I've solved it like this in the end, in case it helps anybody

    "installConcat": "npm install --prefix blank_theme  grunt-contrib-concat --save-dev"
    

  2. It happends because command: npm install package_name installing specified package in current directory or nearest parent directory where present package.json file.
    If you need to install someting in specified directory, you shoult to put there package.json file or run npm init in this directory, which will create this file there and all will work.

    As advice i can to say: remove –save-dev from your command. Confession of this subcommand is to add what you installed to package.json as dependency. Usually i use this command in development process when i am lazy write this dependency to package.json manually. In your composer.json
    you have no necessity in this subcommand;

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search