1 | #!/usr/bin/env node
|
2 | var commander = require('commander');
|
3 | var htmlBundler = require('../src/index.js');
|
4 | var logger = require('../src/utils/logger.js');
|
5 | var process = require('process');
|
6 | var fs = require('fs-extra');
|
7 | var path = require('path');
|
8 | var version = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8')).version;
|
9 | var currentPath = process.cwd();
|
10 |
|
11 | const DEFAULT_CONFIG = path.join(__dirname, '../src/config.example.js');
|
12 | const REAL_CONFIG = path.join(currentPath, './html-bundler.config.js');
|
13 | const DEFAULT_WEBPACK_CONFIG = path.join(__dirname, '../src/webpack.config.example.js');
|
14 | const REAL_WEBPACK_CONFIG = path.join(currentPath, './webpack.config.js');
|
15 | const DEFAULT_DLL_CONFIG = path.join(__dirname, '../src/webpack.dll.example.js');
|
16 | const REAL_DLL_CONFIG = path.join(currentPath, './webpack.dll.js');
|
17 | const DEFAULT_STRUCTURE = path.join(__dirname, '../src/structure');
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | commander.version(version)
|
24 |
|
25 |
|
26 | commander.command('init')
|
27 | .description('if your project rootpath has not `html-bundler.config.js` & `webpack.config.js`, this command will create these files')
|
28 | .option('-w --webpack')
|
29 | .action(function(webpack) {
|
30 | if (!fs.existsSync(REAL_CONFIG)) {
|
31 | fs.copySync(DEFAULT_CONFIG, REAL_CONFIG);
|
32 | logger.info('html-bundler配置文件创建成功, 请根据项目情况进行配置');
|
33 | }
|
34 | if (!fs.existsSync(REAL_WEBPACK_CONFIG) && webpack.webpack) {
|
35 | fs.copySync(DEFAULT_WEBPACK_CONFIG, REAL_WEBPACK_CONFIG);
|
36 | fs.copySync(DEFAULT_DLL_CONFIG, path.join(currentPath, './webpack.dll.js'));
|
37 | logger.info('webpack配置文件创建成功, 请根据项目情况进行修改并安装依赖');
|
38 | }
|
39 |
|
40 | })
|
41 |
|
42 |
|
43 |
|
44 | commander.command('create [project]')
|
45 | .description('create a empty project')
|
46 | .option('-w --webpack')
|
47 | .action(function(project, webpack) {
|
48 | fs.copySync(DEFAULT_STRUCTURE, path.join(currentPath, project));
|
49 | fs.copySync(DEFAULT_CONFIG, path.join(currentPath, project, './html-bundler.config.js'));
|
50 | logger.notice('项目' + project + '创建成功');
|
51 | if (webpack.webpack) {
|
52 | fs.copySync(DEFAULT_WEBPACK_CONFIG, path.join(currentPath, project, './webpack.config.js'));
|
53 | fs.copySync(DEFAULT_DLL_CONFIG, path.join(currentPath, project, './webpack.dll.js'));
|
54 | logger.info('webpack配置文件创建成功, 请根据项目情况进行修改并安装依赖');
|
55 | }
|
56 | })
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | commander.command('dev')
|
62 | .description('dev')
|
63 | .option('-p --port <port>')
|
64 | .action(function(port) {
|
65 | htmlBundler('dev', port.port);
|
66 | })
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | commander.command('dest')
|
72 | .description('dest')
|
73 | .action(function() {
|
74 | htmlBundler('dest');
|
75 | })
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | commander.command('qa')
|
81 | .description('qa')
|
82 | .action(function() {
|
83 | htmlBundler('qa');
|
84 | })
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | commander.command('rd')
|
90 | .description('rd')
|
91 | .action(function() {
|
92 | htmlBundler('rd');
|
93 | })
|
94 |
|
95 | commander.parse(process.argv); |
\ | No newline at end of file |