0

I am trying to create a task for the npm script configured in package.json. So, here are the files:

package.json

....
scripts : {
    "migrate": "node_modules/.bin/migrate-mongo",
    "migrate:create": "npm run migrate create" // --> this command needs input (file name)
}
....

Now when I have to run the migrate:create command I have to go to shell and run like this:

$> npm run migrate:craete filename

And it works fine.

Now I want to create a task for the same. For that I did some research and taking the idea from: https://stackoverflow.com/a/53846572/1227940 created the tasks.json as:

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "Create a db migration script.",
      "command": "npm run migrate create ${input:migrationName}",
      
    }
  ],
  "inputs": [
    {
      "type": "promptString",
      "id": "migrationName",
      "description": "Name your migration script?",
      "default": "create"
    }
  ]
}

But somehow it is not giving me a text box to input anything and directly going inside and firing a command: npm run migrate:create which is failing since filename is missed.

Can anyone please shed some light, what I lacked and what I missed, please let me know?

Thanks in advance, happy coding :)

Ankur Verma
  • 5,793
  • 12
  • 57
  • 93

1 Answers1

0

So, finally I did some research and found the solution and here it is:

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "Create Migration Script",
            "command": "npm run migrate:create ${input:migrationName}",
            "problemMatcher": []
        }
    ],
    "inputs": [
        {
            "type": "promptString",
            "id": "migrationName",
            "description": "Name your migration script (prefix with create-, update-, delete-, insert-)?"
        }
    ]
}

Here the command is the actual script I configured in pacakage.json as:

package.json

....
scripts : {
    "migrate": "node_modules/.bin/migrate-mongo",
    "migrate:create": "npm run migrate create",
}
....

In the command of tasks.json I mentioned the npm run script which is configured in package.json.

Thanks and happy coding :)

Ankur Verma
  • 5,793
  • 12
  • 57
  • 93