简体   繁体   中英

Is there a way to open a Visual Studio Code internal powershell window from NPM Script?

I am currently doing some work with npm scripts and can't find an answer to my question online!

I want to run 3 NPM scripts by typing one command. Here the scripts:

"start-jsonserver:platform": "ng serve --configuration jsonserver"

"start:corePlugins": "ng serve corePlugins",

"start:jsonserver": "cd../json-server & npm run start",

"start:allJsonEnvironment": "npm run start-jsonserver:platform && npm run start:corePlugins && npm run start:jsonserver",

Note that the last command is not working as I want it to as it stops after the first ng serve is "done". I have also tried the same command with just one & but this has the same effect

I have found a solution which is opening 3 seperate Powershell windows:

"start:allJsonEnvironment": "start powershell npm run start-jsonserver:platform && start powershell npm run start:corePlugins && start powershell npm run start:jsonserver"

The Problem is this opens the normal 'standalone' Powershell windows which, to be honest is really ugly and I am used to seeing the VS Code internal Powershell windows (3 at the same time) since its easy to spot if something went wrong. Like that:

在此处输入图像描述

So if there is a way to open these 'internal' Powershell windows from the npm script I would really appreciate help.

(I know there is a way to run all three scripts in one internal window but that is not what I am looking for!)

Okay after some research I have found another solution.

Its not envolving NPM scripts but it is actually the better solution.

My personal solution to the Problem was to use the VS Code Tasks and dependsOn to connect all three commands:

{
    "version": "2.0.0",
    "tasks": 
        [
        {
            "label": "corePlugins",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/frontend"
            },
            "command": "ng serve corePlugins"
        },
        {
            "label": "serve_conf_json",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/frontend"
            },
            "command": "ng serve --configuration jsonserver"
        },
        {
            "label": "json-server",
            "group": "test",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/json-server"
            },
            "command": "npm run start"
        },
        {
            "label": "startAllJson",
            "dependsOn": [
                "json-server",
                "corePlugins",
                "serve_conf_json",
            ]
        }
    ]
}

So now I can just run the Task startAllJson and it opens 3 VSCode Terminals and runs those commands.

I know this might not be the perfect answer to my question but it was the best solution I found in a short amount of time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM