如何在package.json中的脚本中添加时间戳? [英] How can I add a timestamp into a script in package.json?

查看:487
本文介绍了如何在package.json中的脚本中添加时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能无法实现(因为这是JSON而不是JavaScript)。我只是想想一个从npm命令在字符串中插入日期戳的最简单方法,而不增加另一个任务运行器的开销等:

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;"
},

无需责备我使用 - -force ;)

推荐答案

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

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

示例:

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

这篇关于如何在package.json中的脚本中添加时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆