UNPKG

2.21 kBJavaScriptView Raw
1const signale = require('signale');
2const semver = require('semver');
3const path = require('path')
4const lodash = require('lodash');
5const client = require('./core');
6const config = require('../bin/config');
7const debug = require('debug')(`dingtalk-cli-pro:cli`)
8const updater = require('update-notifier');
9const chalk = require('chalk');
10const pkg = require('../package.json');
11const spawn = require('./util/spawn-command');
12const cwd = process.cwd();
13
14// 检查版本,每隔个小时
15updater({ pkg, updateCheckInterval: config.UPDATE_CHECK_INTERVAL} ).notify({ defer: true });
16// Node version check
17const nodeVersion = process.versions.node;
18if (semver.satisfies(nodeVersion, '< 8.9')) {
19 signale.error(`Node version must >= 8.9, but got ${nodeVersion}`);
20 process.exit(1);
21}
22
23
24// execute system plugin: install, list, publish, dev
25client.executeSystemPlugin();
26
27
28let clientConfig = lodash.merge({ pluginPath: ''}, pkg[config.brandName])
29
30if (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// loader install plugin from dingtalk-cli-pro node_modules for system folder
39if (config.env === 'prod') {
40 client.loaderInstalledPlugin(path.resolve(config.npmRoot, `./${config.npmName}/node_modules`));
41}
42
43// loader installed plugin from system folder
44client.loaderInstalledPlugin(config.npmRoot);
45// loader point plugins from config
46
47if (clientConfig.plugins && clientConfig.plugins.length && lodash.isArray(clientConfig.plugins)) {
48 client.loaderConfigPluginFiles(clientConfig.plugins, cwd);
49}
50
51
52
53// parse argv
54client.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