| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #! /usr/bin/env node
- // Node Cli 应用入口文件必须要有这样的文件头
- // 如果是 Linux 或者 macos 系统还需要修改此文件的读写权限为 755
- // 具体是通过 chmod 755 cli.js 实现修改
- // console.log('working');
- // 脚手架的工作过程
- // 1.通过命令交互询问用户问题
- // 2.根据用户回答的结果生成文件
- // 在终端 执行 generate-code
- const inquirer = require('inquirer');
- const fs = require('fs');
- const path = require('path');
- const ejs = require('ejs');
- // 读取json
- const list = JSON.parse(fs.readFileSync('./generate-code/pc_menu_企业风管.json'));
- // 目标目录
- // const destDir = process.cwd();
- const destDir = path.join(process.cwd(), 'src');
- /*** ===================== 生成弹窗名枚举 ==================== ****/
- const enumPath = path.join(destDir, '/common/constants/modalNameEnum.ts');
- let name = `export enum ModalEnum {
- notice = 'notice', // 消息
- logout = 'logout', // 退出登录
- commomOrder = 'commom-order', // 下单通用界面
- detail = 'detail', // 详情`;
- function getModalEnum(arr, callback) {
- arr.forEach((el) => {
- const { code, title, children, type } = el;
- if (type === 2) {
- // 按钮类型
- fs.promises.readFile(enumPath).then((res) => {
- console.log(code);
- if (!name.includes(code)) {
- name += `
- ${code} = '${code}', // ${title}
- `;
- callback();
- }
- getModalEnum(children, callback);
- });
- } else {
- getModalEnum(children, callback);
- }
- });
- }
- getModalEnum(list, () => {
- const temp =
- name +
- `
- }`;
- fs.writeFileSync(enumPath, temp, { flag: 'w+' }, (err) => {
- // !err && console.log('写入文件成功!');
- });
- });
- /*** ===================== 生成单据组件名枚举 ==================== ****/
- const enumOrderPath = path.join(destDir, '/common/constants/enumOrderComponents.ts');
- let orderName = `// 组件名枚举
- export enum enumOrderComponents {`;
- function getOrderName(arr, callback) {
- arr.forEach((el) => {
- const { code, title, children, type } = el;
- if (type === 4) {
- // 单据类型
- fs.promises.readFile(enumOrderPath).then((res) => {
- if (!orderName.includes(code)) {
- orderName += `
- ${code} = '${code}', // ${title}
- `;
- callback();
- }
- getOrderName(children, callback);
- });
- } else {
- getOrderName(children, callback);
- }
- });
- }
- getOrderName(list, () => {
- const temp =
- orderName +
- `
- }`;
- fs.writeFileSync(enumOrderPath, temp, { flag: 'w+' }, (err) => {
- // !err && console.log('写入文件成功!');
- });
- });
|