简体   繁体   English

如何在package.json中的脚本中添加时间戳?

[英]How can I add a timestamp into a script in package.json?

It may not be possible (because this is JSON not JavaScript). 它可能是不可能的(因为这是JSON而不是JavaScript)。 I'm just trying to think of the simplest way to insert a datestamp in a string from an npm command without adding the overhead of another task runner etc: 我只是想想一个从npm命令在字符串中插入日期戳的最简单方法,而不增加另一个任务运行器的开销等:

"scripts": {
    "deploy" : "git add -A; git commit -m \"automated deployment {DateStamp}\"; git push deployment browse --force;"
},

And no need to chide me for using --force ;) 并且无需责备我使用--force ;)

NPM scripts are just bash scripts. NPM脚本只是bash脚本。 Use bash features to add datestamp to some commit message. 使用bash功能将datestamp添加到某个提交消息中。

Example: 例:

  "scripts": {
    "deploy" : "git add -A; timestamp=$(date \"+%s\") && git commit -m \"automated deployment $timestamp\"; git push deployment browse --force;"
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM