Skip to content

Commit 7ae0f6a

Browse files
committed
Add update notifications for cli, addresses #51
1 parent e43df1a commit 7ae0f6a

File tree

4 files changed

+242
-5
lines changed

4 files changed

+242
-5
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"package": "pkg --targets node8.3.0-linux-x64,node8.3.0-win-x64,node8.3.0-macos-x64 -o exoframe index.js"
1616
},
1717
"dependencies": {
18+
"boxen": "^1.2.1",
1819
"chalk": "^2.1.0",
1920
"cli-table": "^0.3.1",
2021
"got": "^7.1.0",
@@ -26,6 +27,7 @@
2627
"opn": "^5.1.0",
2728
"ora": "^1.3.0",
2829
"tar-fs": "^1.15.3",
30+
"update-notifier": "^2.2.0",
2931
"yargs": "^8.0.2"
3032
},
3133
"devDependencies": {

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// npm packages
22
const yargs = require('yargs');
33

4+
// our packages
5+
const checkUpdate = require('./util/checkUpdate');
6+
47
// version
58
const pkg = require('../package.json');
69

10+
// check for updates on start
11+
checkUpdate(pkg);
12+
713
// our packages
814
const login = require('./commands/login');
915
const deploy = require('./commands/deploy');

src/util/checkUpdate.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// npm packages
2+
const chalk = require('chalk');
3+
const boxen = require('boxen');
4+
const updateNotifier = require('update-notifier');
5+
6+
// boxen options
7+
const boxenOpts = {
8+
padding: 1,
9+
margin: 1,
10+
align: 'center',
11+
borderColor: 'yellow',
12+
borderStyle: 'round',
13+
};
14+
// packaged script path
15+
const pkgPath = '/snapshot/exoframe-cli/src/util';
16+
17+
// check function
18+
module.exports = pkg => {
19+
// Checks for available update and returns an instance
20+
const notifier = updateNotifier({
21+
pkg,
22+
updateCheckInterval: 1000,
23+
});
24+
// show message if update is available
25+
if (notifier.update) {
26+
const {update} = notifier;
27+
const isPackaged = __dirname === pkgPath;
28+
const upNpmMsg = `Run ${chalk.cyan('npm i -g exoframe')} to update`;
29+
const upPkgMsg = `Download from ${chalk.cyan('https://github.com/exoframejs/exoframe/releases')}`;
30+
const upmsg = isPackaged ? upPkgMsg : upNpmMsg;
31+
const message = `Update available ${chalk.dim(update.current)} ${chalk.reset(' → ')} ${chalk.green(
32+
update.latest
33+
)}\n${upmsg}`;
34+
console.log(`\n${boxen(message, boxenOpts)}`);
35+
}
36+
};

0 commit comments

Comments
 (0)