我如何添加一个时间戳到package.json中的脚本?

这可能是不可能的(因为这是JSON而不是JavaScript)。 我只是想从npm命令中插入一个string中的date戳的最简单的方法,而不会增加另一个任务亚军等的开销:

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

而且不需要指望我使用--force ;)

NPM脚本只是bash脚本。 使用bashfunction将datestamp添加到某个提交消息。

例:

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