这可能是不可能的(因为这是 JSON 而不是 JavaScript)。我只是在想最简单的方法来从 npm 命令在字符串中插入日期戳,而不增加另一个任务运行器等的开销:
"scripts": {
"deploy" : "git add -A; git commit -m \"automated deployment {DateStamp}\"; git push deployment browse --force;"
},
而且不用因为使用 --force
而责备我 ;)
最佳答案
NPM 脚本只是 bash 脚本。使用 bash 功能为某些提交消息添加时间戳。示例:
"scripts": {
"deploy" : "git add -A; timestamp=$(date \"+%s\") && git commit -m \"automated deployment $timestamp\"; git push deployment browse --force;"
},
关于javascript - 如何将时间戳添加到 package.json 中的脚本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33151617/