1 | #!/usr/bin/env node
|
2 | 'use strict'
|
3 |
|
4 | const path = require('path')
|
5 | const program = require('commander')
|
6 | const PATH = require('../util/path')
|
7 | const check = require('../util/check')
|
8 | const config = require('../util/config')
|
9 | const logger = require('../util/logger')
|
10 | const chalk = require('chalk')
|
11 | const banner = require('../util/banner');
|
12 | banner()
|
13 | console.log()
|
14 | process.on('exit', () => console.log())
|
15 |
|
16 | check.initPluginPackage()
|
17 | config.init()
|
18 |
|
19 | try {
|
20 | check.checkPermission()
|
21 | } catch(_) {
|
22 | logger.fatal(`chalk.yellow('permission denied')
|
23 | 尝试使用 ${chalk.cyan('sudo')} 或者执行下面指令修改访问权限
|
24 |
|
25 | ${chalk.cyan('sudo chown -R $USER:$(id -gn $USER) ' + PATH.PLUGIN_PATH)}
|
26 | `)
|
27 | }
|
28 |
|
29 | if (config.get('updateCheck')) {
|
30 | check.checkVersion()
|
31 | }
|
32 |
|
33 | // hack
|
34 | // https://gist.github.com/branneman/8048520#6-the-hack
|
35 | process.env['NODE_PATH'] = (process.env['NODE_PATH'] || '') + [
|
36 | '',
|
37 | path.join(PATH.CWD_PATH, 'node_modules'),
|
38 | PATH.LIB_PATH,
|
39 | path.join(PATH.ROOT_PATH, 'node_modules'),
|
40 | path.join(PATH.PLUGIN_PATH, 'node_modules'),
|
41 | ].join(path.delimiter)
|
42 |
|
43 | require('module').Module._initPaths()
|
44 |
|
45 | // initPath
|
46 | process.env.XDC_PATH = [
|
47 | 'node_modules',
|
48 | path.join(PATH.CWD_PATH, 'node_modules'),
|
49 | path.join(PATH.PLUGIN_PATH, 'node_modules'),
|
50 | path.join(PATH.ROOT_PATH, 'node_modules')
|
51 | ].join(',')
|
52 |
|
53 | program
|
54 | .usage('<command> [options]')
|
55 | .version(require('../package.json').version)
|
56 | .command('config <option>', '查看当前项目的配置信息')
|
57 | .command('init <template>', '初始化一个空项目,例如 vue')
|
58 | .command('create <project-name> <template>', '创建一个空项目文件夹并初始化')
|
59 | .command('import <plugin>', '安装插件/脚手架')
|
60 | .command('update <plugin>', '更新插件/脚手架')
|
61 | .command('remove <plugin>', '卸载插件/脚手架')
|
62 | .command('list', '查看已安装的插件/脚手架')
|
63 | .command('watch', '开发模式 development')
|
64 | .command('build', '生产模式 production')
|
65 | .command('book', '查看xdc使用文档')
|
66 |
|
67 | // 加载动态指令
|
68 | require('../util/load-command')(program)
|
69 | program.parse(process.argv)
|
70 |
|
71 | if (!process.argv.slice(2).length) {
|
72 | program.outputHelp()
|
73 | }
|