1.1.0 • Published 7 years ago

cli-autoupdater v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

cli-autoupdater

Autoupdating library for node based cli tools

Some Possible Use Cases

Installation

# npm
npm install cli-autoupdater --save

# yarn
yarn add cli-autoupdater

Usage

autoupdater is called by passing in the "options" object and a Promise is returned. The result is a boolean value representing if an update was performed or not. So just wrap your application logic with the call to autoupdater!

autoupdater(require('./package.json');).then((updated) => {
  if (updated) {
    // The application was updated, so exit
    console.log('You may rerun the last command');
    process.exit();
  } else {
    // No update occurred, so just run the application
    run(); // Or whatever your application usually does here
  }
}).catch((e) => {
  // An error has occurred so
  console.log(e);
  process.exit()
});

You could pass in your own configuration object or just use your package.json file. The fields in use are:

{
  "name": "myApp",
  "version": "1.0.0",
  "autoupdater": {
    "updateMessage": "Would you like to update now?",
    "checkCommand": "npm show myApp version",
    "installCommand": "npm install -g myApp",
    "promptUser": true
  }
}

All autoupdater options are completely optional and usually the defaults are good enough.

The autoupdater simply looks at the version and compares it to the version in npm. If there is a newer version, the user is prompted to update. If promptUser is false, then the update is automatic.

License

cli-autoupdater is licensed under the MIT License.