Skip to content

Commit

Permalink
Add check for updates to common execution targets
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Sep 11, 2017
1 parent b9546e5 commit 7ed0d05
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
11 changes: 9 additions & 2 deletions bin/medic-conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

const checkForUpdates = require('../src/lib/check-for-updates');
const error = require('../src/lib/log').error;
const fs = require('../src/lib/sync-fs');
const info = require('../src/lib/log').info;
Expand All @@ -12,7 +13,10 @@ const warn = require('../src/lib/log').warn;
let args = process.argv.slice(2);
const shift = n => args = args.slice(n || 1);

if(!args.length) return usage(0);
if(!args.length) {
return checkForUpdates({ nonFatal:true })
.then(() => usage(0));
}

let instanceUrl;

Expand Down Expand Up @@ -100,12 +104,15 @@ info(`Processing config in ${projectName} for ${instanceUrl}.`);
info('Actions:\n -', actions.join('\n - '));
info('Extra args:', extraArgs);

const initialPromise = actions.includes('check-for-updates') ?
Promise.resolve() : checkForUpdates({ nonFatal:true });

return actions.reduce((promiseChain, action) =>
promiseChain
.then(() => info(`Starting action: ${action}…`))
.then(() => require(`../src/fn/${action}`)('.', couchUrl, extraArgs))
.then(() => info(`${action} complete.`)),
Promise.resolve())
initialPromise)
.then(() => { if(actions.length > 1) info('All actions completed.'); })
.catch(e => {
error(e);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic-configurer-beta",
"version": "1.5.10",
"version": "1.5.11",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
26 changes: 2 additions & 24 deletions src/fn/check-for-updates.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
const info = require('../lib/log').info;
const request = require('request-promise-native');
const warn = require('../lib/log').warn;
const checkForUpdates = require('../lib/check-for-updates');

module.exports = () => request
.get('https://registry.npmjs.org/medic-configurer-beta')
.then(res => {
const json = JSON.parse(res);
const latest = json['dist-tags'].latest;
const current = require('../../package').version;

info(`Current version: ${current}`);
if(latest === current) {
info('You are already on the latest version :¬)');
} else {
warn(`New version available!
${current} -> ${latest}
To install:
npm install -g medic-configurer-beta
`);
}
});
module.exports = () => checkForUpdates();
35 changes: 35 additions & 0 deletions src/lib/check-for-updates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const info = require('../lib/log').info;
const request = require('request-promise-native');
const warn = require('../lib/log').warn;

module.exports = (options) => {
if(!options) options = {};

return request
.get('https://registry.npmjs.org/medic-configurer-beta')
.then(res => {
const json = JSON.parse(res);
const latest = json['dist-tags'].latest;
const current = require('../../package').version;

info(`Current version: ${current}`);
if(latest === current) {
info('You are already on the latest version :¬)');
} else {
warn(`New version available!
${current} -> ${latest}
To install:
npm install -g medic-configurer-beta
`);
}
})
.catch(err => {
if(options.nonFatal && err.cause && err.cause.code === 'ENOTFOUND') {
warn('Could not check NPM for updates. You may be offline.');
} else throw err;
})
;
}

0 comments on commit 7ed0d05

Please sign in to comment.