Skip to content

Commit 13f417d

Browse files
committed
FEATURE: Integrate a update prompt if the globally installed CLI is outdated - solves #33
1 parent 7edf3af commit 13f417d

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

packages/create-react-microservice/.bin/create-react-microservice

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,48 @@ var path = require('path');
66
var pkg = require(path.join(__dirname, './../package.json'));
77

88
require('check-engines')(pkg, function (err) {
9+
var ora = require('ora');
10+
var spinner = ora().start(`Checking for updates and validating the system context.`);
11+
912
if (err) {
1013
console.log(err);
11-
require('ora')().fail(`System binaries do not meet constraints: ${JSON.stringify(pkg.engines)}.`);
14+
spinner.fail(`System binaries do not meet constraints: ${JSON.stringify(pkg.engines)}.`);
1215
process.exit(1);
1316

1417
return;
1518
}
1619

17-
const meow = require('meow');
18-
const ora = require('ora');
19-
const cli = meow({pkg, autoHelp: false});
20-
const commandsByName = {
21-
default: require('./../dist/commands/default.js')
22-
};
23-
const commandName = cli.input.join(' ');
24-
const Command = commandsByName[commandName] || commandsByName.default;
25-
const instance = new Command({
26-
pkg,
27-
input: cli.input,
28-
flags: cli.flags
29-
});
30-
31-
instance.exec().catch(e => {
32-
console.error(e);
20+
(async function() {
21+
const meow = require('meow');
22+
const latestVersion = require('latest-version');
23+
const version = await latestVersion(pkg.name);
3324

34-
process.exit(1);
35-
});
25+
if (version !== pkg.version && pkg.version !== '0.0.0-development') {
26+
spinner.fail(`Oudated version of "${pkg.name}" found. Please update your global installation by executing "yarn global upgrade ${pkg.name}@${version}".`);
27+
28+
return process.exit(1);
29+
}
30+
31+
spinner.stop();
32+
33+
const cli = meow({pkg, autoHelp: false});
34+
const commandsByName = {
35+
default: require('./../dist/commands/default.js')
36+
};
37+
const commandName = cli.input.join(' ');
38+
const Command = commandsByName[commandName] || commandsByName.default;
39+
const instance = new Command({
40+
pkg,
41+
input: cli.input,
42+
flags: cli.flags
43+
});
44+
45+
try {
46+
await instance.exec()
47+
} catch (e) {
48+
console.error(e);
49+
50+
process.exit(1);
51+
}
52+
})()
3653
});

packages/create-react-microservice/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"private": false,
55
"author": "Immonet dev team <aegaeon@immonet.de> (https://immonet.de)",
66
"license": "MIT",
7-
"description": "Create highly scalable and universal React microservices/applications within seconds.",
7+
"description":
8+
"Create highly scalable and universal React microservices/applications within seconds.",
89
"bin": {
910
"create-react-microservice": "./.bin/create-react-microservice"
1011
},
@@ -19,14 +20,16 @@
1920
"jest:watch": "yarn run jest -- --watch",
2021
"jest:coverage": "yarn run jest -- --coverage",
2122
"build:clean": "rimraf dist",
22-
"build:babel": "NODE_ENV=production babel src --out-dir dist --ignore spec.js",
23+
"build:babel":
24+
"NODE_ENV=production babel src --out-dir dist --ignore spec.js",
2325
"build:flow": "flow-copy-source -v src dist --ignore='*.spec.js'",
2426
"build:watch": "yarn run build:babel -- -w",
2527
"prebuild": "yarn run build:clean",
2628
"build": "yarn run build:babel && yarn run build:flow",
2729
"flow": "flow",
2830
"flow-typed": "flow-typed",
29-
"flow-typed-install": "flow-typed install --ignoreDeps=bundled peer --overwrite"
31+
"flow-typed-install":
32+
"flow-typed install --ignoreDeps=bundled peer --overwrite"
3033
},
3134
"devDependencies": {
3235
"@immowelt/babel-preset-immowelt-node": "1.1.0",
@@ -50,6 +53,7 @@
5053
"create-react-microservice-scaffold": "0.0.0-development",
5154
"execa": "0.8.0",
5255
"find-node-modules": "1.0.4",
56+
"latest-version": "^3.1.0",
5357
"meow": "4.0.0",
5458
"node-emoji": "1.8.1",
5559
"ora": "1.3.0",

yarn.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,12 @@ kind-of@^6.0.0:
35813581
version "6.0.1"
35823582
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.1.tgz#4948e6263553ac3712fc44d305b77851d9e40ea4"
35833583

3584+
latest-version@^3.1.0:
3585+
version "3.1.0"
3586+
resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-3.1.0.tgz#a205383fea322b33b5ae3b18abee0dc2f356ee15"
3587+
dependencies:
3588+
package-json "^4.0.0"
3589+
35843590
lazy-cache@^1.0.3:
35853591
version "1.0.4"
35863592
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
@@ -4508,7 +4514,7 @@ p-timeout@^1.1.1:
45084514
dependencies:
45094515
p-finally "^1.0.0"
45104516

4511-
package-json@^4.0.1:
4517+
package-json@^4.0.0, package-json@^4.0.1:
45124518
version "4.0.1"
45134519
resolved "https://registry.yarnpkg.com/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed"
45144520
dependencies:

0 commit comments

Comments
 (0)