javascript - 如何在 npm 版本期间运行脚本

标签 javascript npm

有没有办法在 npm version 期间运行脚本,该脚本在版本号增加之后但在创建和推送 git 标签之前运行?

最佳答案

您可以创建一个 version 脚本,一旦包版本增加但在提交和标记之前将被调用。

"scripts": {
  "version": "./your_script"
}

根据npm version查看执行顺序文档。您可以在下面看到有趣的摘录,特别是第 4 点:

  1. Check to make sure the git working directory is clean before we get started. Your scripts may add files to the commit in future steps. This step is skipped if the --force flag is set.
  2. Run the preversion script. These scripts have access to the old version in package.json. A typical use would be running your full test suite before deploying. Any files you want added to the commit should be explicitly added using git add.
  3. Bump version in package.json as requested (patch, minor, major, etc).
  4. Run the version script. These scripts have access to the new version in package.json (so they can incorporate it into file headers in generated files for example). Again, scripts should explicitly add generated files to the commit using git add.
  5. Commit and tag.
  6. Run the postversion script. Use it to clean up the file system or automatically push the commit and/or tag.

此功能是在 npm v2.13.0 中引入的.参见 version: allow scripts to add files to the commit了解更多信息。

关于javascript - 如何在 npm 版本期间运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31160527/

相关文章:

npm - 如何使 project.json 脚本的构建失败

javascript - Nice编辑点击问题

javascript - meteor js如何从服务器将文件写入本地磁盘?

javascript 检查动态元素的 onchange 函数

node.js - 有条件地指向 package.json 中的主要字段

node.js - 在基于 Angular 6 的项目中更新 npm 时出现错误

javascript - 点击 Node.js 站点时偶尔出现 ERR_CONNECTION_RESET 错误

javascript - 通过jqxGrid中一个单元格的值选择一行

node.js - 发布 npm 包时排除开发依赖

mysql - Node.js - 我可以在 PhoneGap/Cordova 应用程序上安装 NPM 包吗?