當前我們有個問題皮获,npm包更新后锭吨,可能業(yè)務部門感知不到初家,升級有延遲。
為了解決該問題少辣,可參考如下步驟:
- npm install npm-check-updates
- 在pacage.json中凌摄,做如下變更:覆蓋即可
"scripts": {
"checkv": "node .\checkUpdate.js",
"dev": "set NODE_ENV=development && npm run checkv && YYYY",
},
xxxx是用正則匹配出想檢測更新的業(yè)務npm名稱規(guī)則
YYYY是其他命令
腳本如下:
const ncu = require('npm-check-updates');
const chalk = require('chalk');
const execa = require('execa');
const ora = require('ora');
function install(packages) {
const installer = 'npm'
const color = chalk.supportsColor ? '--color=always' : null;
const npmArgs = ['install']
.concat(packages)
.concat(color)
.filter(Boolean);
console.log('');
console.log(`$ ${chalk.green(installer)} ${chalk.green(npmArgs.join(' '))}`);
const spinner = ora(`Installing using ${chalk.green(installer)}...`);
spinner.enabled = true
spinner.start();
return execa(installer, npmArgs, {}).then(output => {
spinner.stop();
console.log(output.stdout);
console.log(output.stderr);
// return currentState;
}).catch(err => {
spinner.stop();
throw err;
});
}
ncu.run({
upgrade:true,
filter:"/^@teld/.*$/"
}).then(function(upgraded){
let udpateList =[]
for(var npmName in upgraded){
var npmVersion = upgraded[npmName].substring(1)
var installAgrs = npmName+'@'+npmVersion
udpateList.push(installAgrs)
}
if(udpateList.length > 0)install(udpateList)
})