1 | const signale = require('signale');
|
2 | const semver = require('semver');
|
3 | const path = require('path')
|
4 | const lodash = require('lodash');
|
5 | const client = require('./core');
|
6 | const config = require('../bin/config');
|
7 | const debug = require('debug')(`dingtalk-cli-pro:cli`)
|
8 | const updater = require('update-notifier');
|
9 | const chalk = require('chalk');
|
10 | const pkg = require('../package.json');
|
11 | const spawn = require('./util/spawn-command');
|
12 | const cwd = process.cwd();
|
13 |
|
14 |
|
15 | updater({ pkg, updateCheckInterval: config.UPDATE_CHECK_INTERVAL} ).notify({ defer: true });
|
16 |
|
17 | const nodeVersion = process.versions.node;
|
18 | if (semver.satisfies(nodeVersion, '< 8.9')) {
|
19 | signale.error(`Node version must >= 8.9, but got ${nodeVersion}`);
|
20 | process.exit(1);
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 | client.executeSystemPlugin();
|
26 |
|
27 |
|
28 | let clientConfig = lodash.merge({ pluginPath: ''}, pkg[config.brandName])
|
29 |
|
30 | if (client.fs.exists(path.join(cwd, `.${config.brandName}rc.js`))) {
|
31 | lodash.merge(clientConfig, require(path.resolve(cwd, `.${config.brandName}rc.js`)));
|
32 | } else if (client.fs.exists(path.join(cwd, `${config.brandName}rc.js`))) {
|
33 | lodash.merge(clientConfig, require(path.resolve(cwd, `${config.brandName}rc.js`)));
|
34 | } else if (client.fs.readJSON(path.join(cwd, `.${config.brandName}rc`))) {
|
35 | lodash.merge(clientConfig, client.fs.readJSON(path.join(cwd, `.${config.brandName}rc`)));
|
36 | }
|
37 |
|
38 |
|
39 | if (config.env === 'prod') {
|
40 | client.loaderInstalledPlugin(path.resolve(config.npmRoot, `./${config.npmName}/node_modules`));
|
41 | }
|
42 |
|
43 |
|
44 | client.loaderInstalledPlugin(config.npmRoot);
|
45 |
|
46 |
|
47 | if (clientConfig.plugins && clientConfig.plugins.length && lodash.isArray(clientConfig.plugins)) {
|
48 | client.loaderConfigPluginFiles(clientConfig.plugins, cwd);
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | client.program
|
55 | .version(pkg.version)
|
56 | .on('command:*', () => {
|
57 | console.log(`${client.randomEmoji()} Invalid command: ${chalk.red(client.program.args.join(' '))} \n See --help for a list of available commands.`);
|
58 | process.exit(1);
|
59 | })
|
60 | .parse(process.argv);
|
61 |
|