首页 > npm 包 检查有新版本了 自动更新到最新版本

npm 包 检查有新版本了 自动更新到最新版本

在开发 npm 包工具的 时候, 每次有新版本了,

还要手动告诉同事,npm 包更新了, 重新安装一下 npm

这样感觉很麻烦,有木有可以 npm 包 在使用的时候,自动更新自己呢

想想

在执行 npm 工具前,先检查当前工具包的版本 和 https://www.npmjs.com 上的版本是否一致,不一致就执行

npm i -g xxx

install 遇到问题

var spawn = require('child_process').spawn;

var status = spawn('npm', ['install', '-g','git']);

    status.stdout.on('data', function(data){           
       console.log(data.toString());    
    });
    
    status.on('close', function(){         
        console.log("完成")         
    })

结果是报错了, npm 命令是不能执行的

报错信息

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: spawn npm ENOENT
    at exports._errnoException (util.js:874:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at doNTCallback2 (node.js:439:9)
    at process._tickCallback (node.js:353:17)

https://github.com/dylang/npm-check

PS: 如果是github上的项目可以用 greenkeeper

【热门文章】
【热门文章】