【问题标题】:Is there a way to open a Visual Studio Code internal powershell window from NPM Script?有没有办法从 NPM 脚本打开 Visual Studio Code 内部 powershell 窗口?
【发布时间】:2021-10-04 16:00:50
【问题描述】:

我目前正在使用 npm 脚本做一些工作,但在网上找不到我的问题的答案!

我想通过输入一个命令来运行 3 个 NPM 脚本。这里是脚本:

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

请注意,最后一个命令没有像我希望的那样工作,因为它在第一个 ng serve “完成”后停止。我也用一个& 尝试了相同的命令,但这具有相同的效果

我找到了一个打开 3 个单独的 Powershell 窗口的解决方案:

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

问题是这会打开普通的“独立”Powershell 窗口,说实话真的很难看,我习惯于看到 VS Code 内部的 Powershell 窗口(同时 3 个),因为如果出现问题,很容易发现。 像这样:

因此,如果有办法从 npm 脚本打开这些“内部”Powershell 窗口,我将不胜感激。

(我知道有一种方法可以在一个内部窗口中运行所有三个脚本,但这不是我想要的!)

【问题讨论】:

    标签: powershell npm visual-studio-code


    【解决方案1】:

    好的,经过一番研究,我找到了另一种解决方案。

    它不包含 NPM 脚本,但它实际上是更好的解决方案。

    我个人对该问题的解决方案是使用 VS Code Tasks 和 dependsOn 连接所有三个命令:

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

    所以现在我可以运行任务startAllJson,它会打开 3 个 VSCode 终端并运行这些命令。

    我知道这可能不是我问题的完美答案,但它是我在短时间内找到的最佳解决方案。

    【讨论】:

      猜你喜欢
      • 2021-08-20
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-04
      • 2011-06-05
      • 1970-01-01
      相关资源
      最近更新 更多