简体   繁体   中英

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

It may not be possible (because this is JSON not 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:

"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 ;)

NPM scripts are just bash scripts. Use bash features to add datestamp to some commit message.

Example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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