UNPKG

1.7 kBJavaScriptView Raw
1// 安装主题的时候,先执行npm install, 如果有copy, 然后再复制到theme文件夹下面
2const path = require('path');
3const fs = require('fs-extra');
4const child_process = require('child_process');
5const projectPath = process.cwd();
6const argv= process.argv;
7const utils = require('../utils');
8const themePath = path.resolve(projectPath, 'theme');
9
10module.exports = {
11 setOptions: function () {},
12 run: function () {
13 // 执行npm install testTheme
14 let themeName;
15 // console.log('------argv', argv);
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 // 新建一个theme的文件夹,把nodeModules中的文件复制出来
31 // console.log('+++++123', argv.length, argv[4] === '--copy', argv[4] === '-c')
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