|
|
@@ -13,6 +13,8 @@ const inquirer = require('inquirer');
|
|
|
const fs = require('fs');
|
|
|
const path = require('path');
|
|
|
const ejs = require('ejs');
|
|
|
+const { tmpdir } = require('os');
|
|
|
+const { createPartiallyEmittedExpression } = require('typescript');
|
|
|
|
|
|
// 读取json
|
|
|
const list = JSON.parse(fs.readFileSync('./generate-code/pc_menu_企业风管.json'));
|
|
|
@@ -28,6 +30,8 @@ function hasFile(url, code) {
|
|
|
fs.statSync(temp);
|
|
|
return true;
|
|
|
} catch (error) {
|
|
|
+ console.log(temp);
|
|
|
+ console.log(error);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -37,11 +41,12 @@ const tempDir = path.join(__dirname, 'templates');
|
|
|
|
|
|
function writeFile(url, code) {
|
|
|
if (!hasFile(url, code)) {
|
|
|
+ const temp = path.join(url, `/${code}`);
|
|
|
+ console.log(temp);
|
|
|
return fs.promises.mkdir(temp);
|
|
|
}
|
|
|
- return Promise.resolve();
|
|
|
+ return Promise.resolve(false);
|
|
|
}
|
|
|
-
|
|
|
list.forEach((el) => {
|
|
|
const { code, children } = el;
|
|
|
writeFile(destDir, code).then(() => {
|
|
|
@@ -50,19 +55,45 @@ list.forEach((el) => {
|
|
|
writeFile(path.join(destDir, `/${code}`), item.code).then(() => {
|
|
|
if (item.children) {
|
|
|
item.children.forEach((e) => {
|
|
|
- writeFile(path.join(destDir, `/${code}/${item.code}`), e.code).then(() => {
|
|
|
- if (!hasFile(path.join(destDir, `/${code}/${item.code}`), 'index.vue')) {
|
|
|
- const obj = { code: e.code };
|
|
|
- // ejs.renderFile(tempDir, obj, (err, result) => {
|
|
|
- // if (err) throw err;
|
|
|
- // // fs.writeFileSync(path.join(destDir, `/${code}/${item.code}/${e.code}`), result);
|
|
|
- // });
|
|
|
- fs.writeFileSync(
|
|
|
- path.join(destDir, `/${code}/${item.code}/${e.code}/index.vue`),
|
|
|
- ''
|
|
|
- );
|
|
|
+ const path1 = `/${code}/${item.code}`;
|
|
|
+ writeFile(path.join(destDir, path1), e.code).then(() => {
|
|
|
+ const path2 = `${path1}/${e.code}`;
|
|
|
+ // index.vue
|
|
|
+ if (!hasFile(path.join(destDir, path2), 'index.vue')) {
|
|
|
+ const template = `
|
|
|
+
|
|
|
+ `;
|
|
|
+ fs.writeFileSync(path.join(destDir, `${path2}/index.vue`), template);
|
|
|
}
|
|
|
- writeFile(path.join(destDir, `/${code}/${item.code}/${e.code}`), 'components');
|
|
|
+ // components
|
|
|
+ writeFile(path.join(destDir, `${path2}`), 'components').then(() => {
|
|
|
+ if (e.children) {
|
|
|
+ const path3 = `${path2}/components`;
|
|
|
+ e.children.forEach((ele) => {
|
|
|
+ writeFile(path.join(destDir, path3), ele.code).then((res) => {
|
|
|
+ if (res) {
|
|
|
+ if (
|
|
|
+ !hasFile(
|
|
|
+ path.join(destDir, `${path3}/${ele.code}`),
|
|
|
+ 'index.vue'
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ const template = `
|
|
|
+ `;
|
|
|
+ fs.writeFileSync(
|
|
|
+ path.join(destDir, `${path3}${ele.code}/index.vue`),
|
|
|
+ template
|
|
|
+ ).then(res => {
|
|
|
+ if (res) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
@@ -71,35 +102,3 @@ list.forEach((el) => {
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
-// console.log(list);
|
|
|
-// inquirer
|
|
|
-// .prompt([
|
|
|
-// {
|
|
|
-// type: 'input',
|
|
|
-// name: 'name',
|
|
|
-// message: 'Project name'
|
|
|
-// }`
|
|
|
-// ])
|
|
|
-// .then((ansers) => {
|
|
|
-// // console.log(ansers);
|
|
|
-// // 根据用户回答的结果生成文件
|
|
|
-
|
|
|
-// // 模板目录
|
|
|
-// const tempDir = path.join(__dirname, 'templates');
|
|
|
-// // 目标目录
|
|
|
-// const destDir = process.cwd();
|
|
|
-
|
|
|
-// // 将模板下的文件全部转换到目标下目录
|
|
|
-// fs.readdir(tempDir, (err, files) => {
|
|
|
-// if (err) throw err;
|
|
|
-// files.forEach((file) => {
|
|
|
-// // 通过目标引擎渲染文件
|
|
|
-// ejs.renderFile(path.join(tempDir, file), ansers, (err, result) => {
|
|
|
-// if (err) throw err;
|
|
|
-// // 将结果写入目标文件路径
|
|
|
-// // fs.writeFileSync(path.join(destDir, file), result);
|
|
|
-// });
|
|
|
-// });
|
|
|
-// });
|
|
|
-// });
|