dai-cli

自动化上传

2022/4/13 15:59:39

更改列表

desktop.ini 2(+1 -1)

index.js 76(+70 -6)

详细信息

diff --git a/.vscode/launch.json b/.vscode/launch.json
index 27b2eda..e4187da 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -12,7 +12,7 @@
                 "<node_internals>/**"
             ],
             "program": "${workspaceFolder}\\index.js",
-            "args": ["dev"]
+            "args": ["add"]
         }
     ]
 }
\ No newline at end of file

desktop.ini 2(+1 -1)

diff --git a/desktop.ini b/desktop.ini
index 85fe68f..6ebb601 100644
--- a/desktop.ini
+++ b/desktop.ini
@@ -1,5 +1,5 @@
 [.ShellClassInfo]
-InfoTip=���ּ�
+InfoTip=DaiVUE ���ּ�
 [ViewState]
 Mode=
 Vid=

index.js 76(+70 -6)

diff --git a/index.js b/index.js
index 70f5154..5b1d74c 100644
--- a/index.js
+++ b/index.js
@@ -9,7 +9,7 @@ import fs from 'fs/promises';
 
 const projectList = [
     { name: 'dai-vue-m', value: 'http://git.daicms.com/dai-vue-temp-m.git#master' },
-    { name: 'dai-web-w', value: 'http://git.daicms.com/dai-vue-temp-m.git#master' }
+    { name: 'dai-vue-w', value: 'http://git.daicms.com/dai-vue-temp-w.git#master' }
 ];
 //下载项目
 let downloadProject = function (answers) {
@@ -39,6 +39,33 @@ let downloadProject = function (answers) {
         });
     });
 };
+let downloadModule = function (options) {
+    return new Promise(function (a, b) {
+        const spinner = ora('下载中...');
+        spinner.start();
+        downloadGit('direct:' + options.url, options.path, { clone: true }, async (err) => {
+            if (err) {
+                spinner.fail();
+                // console.log(chalk.red(err));
+                b(err);
+            } else {
+                spinner.succeed();
+                // const fileName = './package.json';
+                // const meta = {
+                //     name: answers.name,
+                //     description: answers.description,
+                //     author: answers.author
+                // };
+                // let content = await fs.readFile(fileName);
+                // content = JSON.parse(content.toString());
+                // Object.assign(content, meta);
+                // await fs.writeFile(fileName, JSON.stringify(content, null, 4));
+                console.log(chalk.green('模块添加成功'));
+                a();
+            }
+        });
+    });
+};
 let runDev = function () {
     // debugger
     // var webpackDev = require('./src/webpack.dev.js');
@@ -74,6 +101,16 @@ let exec = function () {
                         message: '请选择项目类型',
                         choices: projectList
                     }
+                    //目录方式
+                    // {
+                    //     type: 'list',
+                    //     name: 'pathType',
+                    //     message: '请选择项目位置',
+                    //     choices: [
+                    //         { name: '当前目录', value: '0' },
+                    //         { name: '新建目录', value: '0' }
+                    //     ]
+                    // }
                 ]);
                 console.log(answers);
 
@@ -93,14 +130,41 @@ let exec = function () {
             .action(async () => {
                 let answers = await inquirer.prompt([
                     {
-                        type: 'list',
-                        name: 'url',
-                        message: '请选择模块类型',
-                        choices: [{ name: '独立模块', value: 'http://git.daicms.com/dai-vue-temp-m.git#master' }]
+                        name: 'name',
+                        message: '请输入功能模块名称(功能模块将添加到目录 modules 中)'
                     }
                 ]);
                 console.log(answers);
-                // await downloadProject(answers);
+                //检测目录是否存在
+                debugger;
+                let path = './modules/' + answers.name;
+                let dir;
+                try {
+                    dir = await fs.stat(path);
+                } catch (ex) {
+                    //没有则创建目录
+                    if (ex.errno == '-4058') {
+                        console.log(chalk.green('目录没找到,创建 ' + path));
+                        let dirFile = await fs.mkdir(path, { recursive: true });
+                        dir = await fs.stat(path);
+                    }
+                }
+                //判断是否为文件夹
+                if(!dir.isDirectory()){
+                    console.log(chalk.red('路径不是目录,模块添加失败'));
+                    return;
+                }
+                //判断目录是否为空
+                let list = await fs.readdir(path);
+                if (list.length > 0) {
+                    console.error(chalk.redBright('目录不为空,模块添加失败'));
+                    return;
+                }
+
+                await downloadModule({
+                    path,
+                    url: 'http://git.daicms.com/dai-vue-module-m.git.git#master'
+                });
             });
         program.command('dev').action(async () => {
             console.log('启动 dev 服务');