如何在知道退出代码的npm中运行post脚本

时间:2017-02-19 09:59:21

标签: npm

我想在NPM RUN中运行一个知道脚本是否失败的帖子脚本。

现在,post脚本的行为是在主脚本成功时运行。所以我可以做一些事情on success

但是,我还要运行脚本on failure。我该怎么做?

1 个答案:

答案 0 :(得分:0)

我也一直在寻找这个问题的答案,而我能做的最好的就是使用bash脚本来始终运行post命令。这是我的libuv

df.groupBy($"id")
  .agg(collect_set("value"), max($"value").as("max_value"))
  .filter($"max_value" <= 5)
  .show(false)

为帮助尽可能多地保留在npmbash中,您可以执行定义为在主脚本之后运行的后脚本(例如#!/usr/bin/env bash # # Use this to catch control-c and cleanup. Won't run on Windows except in git bash or similar. # # Pass args you'd normally pass to npm - eg. npm run dev # - if the args contain 'dev' or 'test' then the mongodb will be started up and shut down # after it completes or control-c is pressed. isDevOrTest=false setIsDevOrTest() { for i in "$@"; do if [[ $i =~ "dev|test" ]] then echo "has dev or test" isDevOrTest=true fi done } # Trap control-c trap 'ctrl_c' INT function ctrl_c() { shutdown exit 0 } function shutdown() { echo shutdown isDevOrTest: $isDevOrTest if [[ $isDevOrTest ]] then echo Its dev or test so shut down mongo mongo admin --eval 'db.shutdownServer()' fi } function startup() { echo startup } function run() { echo npm "$@" npm "$@" } setIsDevOrTest "$@" startup run "$@" shutdown npm):

poststart

但是在成功的情况下,您需要确保只运行一次后记(例如,start中的function shutdown() { npm run poststart } 默认在poststart之后运行-类似{{ 1}}在它之前运行-https://docs.npmjs.com/misc/scripts)。应该很简单:

npm

运行方式:

start