-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathcli-main.js
executable file
·66 lines (55 loc) · 1.97 KB
/
cli-main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
// Node module: @loopback/cli
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
const pkg = require('../package.json');
const semver = require('semver');
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const {
tabCompletionCommands,
runTabCompletionCommand,
} = require('../lib/tab-completion');
// Make sure node version meets the requirement. This code intentionally only
// uses ES5 features so that it can be run with lower versions of Node
// to report the version requirement.
const nodeVer = process.versions.node;
const requiredVer = pkg.engines.node;
const ok = semver.satisfies(nodeVer, requiredVer);
if (!ok) {
const format =
'Node.js "%s" is not supported. Please use a version that satisfies "%s".';
console.warn(chalk.red(format), nodeVer, requiredVer);
}
// Intentionally have a separate `main.js` which can use JS features
// supported by required version of Node
const minimist = require('minimist');
const opts = minimist(process.argv.slice(2), {
alias: {
version: 'v', // --version or -v: print versions
commands: 'l', // --commands or -l: print commands
help: 'h', // --help or -h: help
},
});
const args = opts._;
const originalCommand = args[0];
if (tabCompletionCommands.includes(originalCommand)) {
const yoJsonFile = path.join(__dirname, '../.yo-rc.json');
const config = fs.readJsonSync(yoJsonFile);
return runTabCompletionCommand(config.commands, originalCommand, console.log);
}
const main = require('../lib/cli');
// Force version check with `lb4 --version`
const interval = opts.version ? 0 : undefined;
import('update-notifier')
.then(({default: updateNotifier}) => {
updateNotifier({
pkg: pkg,
updateCheckInterval: interval,
}).notify({isGlobal: true});
})
.catch(() => {});
main(opts);