[英]Automatically update package.json version and read it in code
I have logger which is displaying some stuff in production and i want to add version to this logger so i got better clue if/when deployment is finished.我有一个记录器,它在生产中显示一些东西,我想向这个记录器添加版本,所以如果/何时部署完成,我会得到更好的线索。 Is it possible to:
是否有可能:
That will be really helpful这将非常有帮助
for the second question if you have access to process
you can read the version
property of package.json
like this:对于第二个问题,如果您有权访问
process
,您可以像这样阅读package.json
的version
属性:
process.env.npm_package_version
for the first question, that is a little tricky, you can use some packages such as husky to run some npm scripts
which you already add to package.json
.对于第一个问题,这有点棘手,您可以使用一些包(例如husky )来运行一些
npm scripts
,这些脚本已经添加到package.json
中。
so you would listen to git hooks such as commit
or merge
and using pre-
or post-
scripts to run a command before or after a hook is fired.所以你会听 git 钩子,例如
commit
或merge
,并使用pre-
或post-
置脚本在触发钩子之前或之后运行命令。
so I guess if you can combine these, you would get your desired result所以我想如果你能把这些结合起来,你会得到你想要的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.