1 |
|
2 | const path = require('path');
|
3 | const fs = require('fs-extra');
|
4 | const child_process = require('child_process');
|
5 | const projectPath = process.cwd();
|
6 | const argv= process.argv;
|
7 | const utils = require('../utils');
|
8 | const themePath = path.resolve(projectPath, 'theme');
|
9 |
|
10 | module.exports = {
|
11 | setOptions: function () {},
|
12 | run: function () {
|
13 |
|
14 | let themeName;
|
15 |
|
16 | if(argv.length >= 4) {
|
17 | themeName = argv[3];
|
18 | console.log(`Start install ${themeName}......` );
|
19 | child_process.execSync(`npm install --save-dev ${themeName}`, function(err){
|
20 | if(err) {
|
21 | throw err;
|
22 | } else {
|
23 | console.log(`Install the theme ${themeName} success` );
|
24 | }
|
25 |
|
26 | });
|
27 | } else {
|
28 | return utils.log.error('The theme is not exists.')
|
29 | }
|
30 |
|
31 |
|
32 | if (argv.length === 5 && (argv[4] === '--copy' || argv[4] === '-c')) {
|
33 | if(!fs.existsSync(themePath)) {
|
34 | fs.mkdirSync(themePath)
|
35 | }
|
36 | let themeFile = path.resolve(themePath, `${themeName}`);
|
37 | if(!fs.existsSync(themeFile)) {
|
38 | fs.mkdirSync(themeFile)
|
39 | }
|
40 | let modules = path.resolve(process.cwd(), 'node_modules');
|
41 | let themeModuleDir = path.resolve(modules, `./${themeName}`);
|
42 | utils.mergeCopyFiles(path.resolve(themeModuleDir, "./theme"), themeFile);
|
43 | }
|
44 | utils.log.ok('Install a theme success')
|
45 | },
|
46 | desc: 'Install a theme'
|
47 | } |
\ | No newline at end of file |