first commit

This commit is contained in:
编码猿
2024-09-27 01:28:38 +08:00
commit a9bde91e8e
2653 changed files with 701970 additions and 0 deletions

View File

@@ -0,0 +1 @@
7c0d9e22-1922-439e-bd5a-07762a61811c

View File

@@ -0,0 +1 @@
6ed708f3-a582-4bbc-a7dd-4bff992d1ee7

View File

@@ -0,0 +1,92 @@
module.exports = {
pageConfig: (name) => {
return `
import "@pageLess/${name}.less";
import { Component, Vue } from 'vue-property-decorator';
import { ${name}Logic } from "@logic/page/${name}.logic";
import { Route, RawLocation } from 'vue-router';
import { BaseLayout, RouterMeta } from "@layout/base.layout";
@Component
export default class ${name} extends BaseLayout {
private service: ${name}Logic = new ${name}Logic(this);
private RouterMeta: RouterMeta = {
title: '${name}',
showNav: true,
isLogin: true
};
created() {
this.service.StartUp();
};
// 路由拦截器
beforeRouteEnter(to: Route, from: Route, next: (to?: RawLocation | false | ((vm: Vue) => void)) => void) {
next();
}
protected render() {
return (
<div class="${name}">
${name}
</div>
)
}
}
`
},
logicConfig: (name) => {
return `
import { BaseLogic, VueType, Methods } from "@logic/Base.logic";
import { Inject } from "@ann/Ioc.annotation";
import { UserServiceImpl } from "@impl/User.service.impl";
import { Vue } from "vue-property-decorator";
import { MessageBox } from 'element-ui';
export class ${name}Logic extends BaseLogic implements Methods {
@Inject()
public readonly UserServiceImpl!: UserServiceImpl;
constructor(point: any) {
super();
this.VueApp = point;
}
public async StartUp(): Promise<void> {
}
}
`
},
serviceConfig: (name) => {
return `
export interface ${name}Service {
IndexClass(params: object): Promise<any>;
}
`
},
implPathConfig: (name) => {
return`
import { ${name}Service } from "@service/${name}.service";
import { Injectable } from "@ann/Ioc.annotation";
import { GET } from "@ann/Http.annotation";
@Injectable()
export class ${name}ServiceImpl implements ${name}Service {
@GET({ useHandle: false })
public async IndexClass(params: object): Promise<any> { }
}
`
},
lessConfig: (name) => {
return `
@import "../color/index";
@import "../mixin/index";
.${name} {
}
`
}
}

View File

@@ -0,0 +1,105 @@
#!/usr/bin/env node
const { program } = require('commander');
const packageConfig = require("../package.json");
const fs = require("fs");
const path = require('path');
const Config = require("./config");
program
.requiredOption('-t, --file-type <type>', '文件类型: [pagelogicserviceimplless]')
.option('-n, --file-name <name>', '被创建的文件名称')
.option('-i, --is-create <is>', '是否为 -t 参数自动创建相关文件类型', false);
program.version(packageConfig.version, '-v, --version', '显示当前的版本');
program.parse(process.argv);
// 存储终端的参数
let programOptions = program.opts();
let OtherFileType = program.parse(process.argv).args
console.log("programOptions: ", programOptions)
console.log("OtherFileType: ", OtherFileType)
// tsx 页面路径
let PagePath = pathJoin(`../src/application/page/${UpperCase(programOptions.fileName)}.tsx`);
// logic 页面路径
let LogicPath = pathJoin(`../src/application/logic/page/${UpperCase(programOptions.fileName)}.logic.ts`);
// service 页面路径
let ServicePath = pathJoin(`../src/core/service/${UpperCase(programOptions.fileName)}.service.ts`);
// Impl 页面路径
let ImplPath = pathJoin(`../src/core/service/impl/${UpperCase(programOptions.fileName)}.service.impl.ts`);
// Less 页面路径
let LessPath = pathJoin(`../src/application/assets/less/page/${UpperCase(programOptions.fileName)}.less`);
// 需要创建的文件类型
let FileList = ['page', 'logic', 'service', 'impl', 'less'];
// 是否需要为 controller 联合创建所有文件
if (programOptions.isCreate) {
FileList.forEach(val => replaceTplText(val));
console.log("成功创建所有文件...");
} else {
// 循环创建多个文件
if (OtherFileType.length !=0 ) {
[...OtherFileType, programOptions.fileType].forEach(v => replaceTplText(v))
} else {
replaceTplText(programOptions.fileType)
}
console.log("成功创建单个文件...");
}
/**
* 替换模板的内容,并将内容写入文件。
*/
let FileText = ""
function replaceTplText (action) {
switch (action) {
case 'page':
fs.writeFileSync(PagePath, Config.pageConfig(UpperCase(programOptions.fileName)));
break;
case 'logic':
fs.writeFileSync(LogicPath, Config.logicConfig(UpperCase(programOptions.fileName)));
break;
case 'service':
fs.writeFileSync(ServicePath, Config.serviceConfig(UpperCase(programOptions.fileName)));
break;
case 'impl':
fs.writeFileSync(ImplPath, Config.implPathConfig(UpperCase(programOptions.fileName)));
break;
case 'less':
fs.writeFileSync(LessPath, Config.lessConfig(UpperCase(programOptions.fileName)));
break;
default:
break
}
}
/**
* 单词首字母大写
* @param str
* @returns {void | string | *}
* @constructor
*/
function UpperCase (str) {
return str.replace(str[0],str[0].toUpperCase())
}
/**
* 读取文件内容
* @param path
* @returns {*}
* @constructor
*/
function GetFileText (path) {
return (fs.readFileSync( pathJoin(path), 'utf-8' )).toString();
}
/**
* 拼接路径
* @param paths
* @returns {string}
*/
function pathJoin (paths) {
return path.join(__dirname, paths)
}