【问题标题】:How to print out multi-line message from npm script如何从 npm 脚本打印出多行消息
【发布时间】:2021-03-08 17:08:05
【问题描述】:

是否可以从 npm 脚本中打印出多行消息?

我的团队有一个替代脚本需要代替 npm publish 运行。 因此,我们应该运行npm run publish:lib,而不是从终端运行npm publish。但是,一些团队成员忘记了替代脚本,最终只运行npm publish

所以到目前为止我所做的就是将它添加到我的 package.json 中:

"scripts": {
    "postpublish": "node -e \"console.log('Did you mean npm run publish:lib?')\"",
}

这样,当他们运行 npm publish 时,他们会被提醒有关替代脚本的信息。但是,我对它并不满意,因为它不是很明显,而且 console.log 的字样也被打印出来了,这有点难看。

我的目标是打印出如下所示的内容:

【问题讨论】:

    标签: node.js npm


    【解决方案1】:

    我最终使用的解决方案如下:

    package.json

    "scripts": {
        "postpublish": "node publishWarning.js"
    }
    

    publishWarning.js

    console.log('***************************************')
    console.log('***************************************')
    console.log('** Did you mean npm run publish:lib? **')
    console.log('***************************************')
    console.log('***************************************')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 2016-07-15
      • 2012-10-09
      • 2020-02-23
      相关资源
      最近更新 更多