首页 前端知识 Running NPM scripts sequentially

Running NPM scripts sequentially

2025-02-24 13:02:08 前端知识 前端哥 201 665 我要收藏

题意

顺序运行 NPM 脚本

问题背景:

Let's say I have

假设我有

"scripts": {
    "pre-build": "echo \"Welcome\" && exit 1",
    "build_logic": "start cmd.exe @cmd /k \"yo esri-appbuilder-js:widget && exit 1\"",
    "post_build":  "start C:\\WebAppBuilderForArcGIS\\startupShortcut",
    "exit" : "start cmd.exe @cmd /k \"echo \"goodbye\" && exit 1\""
  },

What NPM command can I run to let all of these scripts launch sequentially. When I use pre/post fixing they launch sequentially but they don't wait for the parent script to finish before executing. I am assuming the only solution is like: 

我可以运行什么 NPM 命令来让所有这些脚本顺序启动。当我使用 pre/post 修饰时,它们会顺序启动,但在执行之前不会等待父脚本完成。我假设唯一的解决方案是这样的:How do I get Gulp tasks to fire sequentially when firing shell commands in an async.series helper function? 

? I know this can be done with Gulp but I would like to stick with NPM for now to explore its capabilities. Thanks for any help!

我知道这可以通过 Gulp 完成,但我现在想继续使用 NPM 来探索它的功能。感谢任何帮助!

问题解决:

Invoke these scripts via npm run and chain them with double ampersand &&:

通过 npm run 调用这些脚本,并使用双和号 && 将它们串联起来:

npm run pre-build && npm run build_logic && npm run post_build && npm run exit

You can either run the above command directly on the command line, or you can set it as another script like this:

你可以直接在命令行上运行上述命令,或者可以像下面这样将其设置为另一个脚本:

"scripts": {
    ...
    "build": "npm run pre-build && npm run build_logic && npm run post_build && npm run exit",
}

And then run the whole list via npm run build.

然后通过 npm run build 运行整个列表。

Explanation:  解释:

  • Use && (double ampersand) for sequential execution.
    (Some early versions of Windows Powershell did not support this syntax, but recent versions should.)   

    使用 &&(双和号)进行顺序执行。
    (一些早期版本的 Windows Powershell 不支持这种语法,但最近的版本应该支持。)

  • Use & (single ampersand) for parallel execution. Test carefully as commands earlier in the list may be run in background and you may potentially lose the output including any error messages (depending on your platform/shell).   使用 &(单个和号)进行并行执行。请小心测试,因为列表中的早期命令可能会在后台运行,你可能会丢失输出,包括任何错误消息(取决于你的平台/ shell)。

转载请注明出处或者链接地址:https://www.qianduange.cn//article/21119.html
标签
评论
发布的文章

C/C | 每日一练 (2)

2025-02-24 13:02:49

Linux性能监控工具汇总

2025-02-24 13:02:48

Python常见面试题的详解16

2025-02-24 13:02:48

QQ登录测试用例报告

2025-02-24 13:02:47

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!