first commit
This commit is contained in:
1
bin/.pydio
Normal file
1
bin/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
a06d094b-d1c2-4adc-8c5c-0a9986f5aea8
|
||||
1
bin/config/.pydio
Normal file
1
bin/config/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
97f1b24f-9aff-44d4-b3af-c8a5ea6943c7
|
||||
94
bin/config/index.js
Normal file
94
bin/config/index.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2020. bmy
|
||||
*/
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
public async created() {
|
||||
await 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";
|
||||
|
||||
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 } {
|
||||
}
|
||||
`
|
||||
}
|
||||
}
|
||||
1
bin/service-code-generation/.pydio
Normal file
1
bin/service-code-generation/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
1331c103-912a-4f75-9045-03aaa69824f8
|
||||
1
bin/service-code-generation/config/.pydio
Normal file
1
bin/service-code-generation/config/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
8bb6e31a-650f-4f25-9e76-72e5118f6438
|
||||
6
bin/service-code-generation/config/index.js
Normal file
6
bin/service-code-generation/config/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
// 需要被监听的api地址路径
|
||||
apiListPath: "F:\\desktop\\vue-class-api-tsx\\src\\core\\config\\configure.config.ts",
|
||||
// 生成的service层代码存放路径
|
||||
outPutServicePath: "F:\\desktop\\vue-class-api-tsx\\src\\core\\service"
|
||||
}
|
||||
29
bin/service-code-generation/index.js
Normal file
29
bin/service-code-generation/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const config = require('./config')
|
||||
const readApiList = require('./utils/ReadApiList')
|
||||
const file = require('./utils/File')
|
||||
let ServerMap = new Map();
|
||||
// Map(3) {
|
||||
// 'Car' => Map(2) { 'IndexTest' => 'IndexTest', 'carList' => 'carList' },
|
||||
// 'Index' => Map(1) { 'reg' => 'reg' },
|
||||
// 'Order' => Map(1) { 'test' => 'test' }
|
||||
// }
|
||||
let main = async () => {
|
||||
let readApi = new readApiList(config.apiListPath)
|
||||
let res = await readApi.getFileList()
|
||||
|
||||
res.forEach(v => {
|
||||
// [ 'Car', 'IndexTest' ]
|
||||
let key = v.split(":")[0].split("_")
|
||||
if (!ServerMap.get(key[0])) {
|
||||
ServerMap.set(key[0], new Map())
|
||||
}
|
||||
ServerMap.get(key[0]).set(key[1],key[1])
|
||||
});
|
||||
|
||||
// 根据接口对象的配置文件,自动生成service文件和代码
|
||||
ServerMap.forEach((value,key) => {
|
||||
file.createdService(key,value)
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
1
bin/service-code-generation/utils/.pydio
Normal file
1
bin/service-code-generation/utils/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
7fcbe2a8-4ef1-42fd-8123-b5ed331cbd41
|
||||
59
bin/service-code-generation/utils/File.js
Normal file
59
bin/service-code-generation/utils/File.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const { writeFileSync, existsSync } = require("fs");
|
||||
const config = require("../config");
|
||||
|
||||
class File {
|
||||
|
||||
createdService(ServiceName, ServiceMethods) {
|
||||
let fullPath = `${config.outPutServicePath}\\${ServiceName}.service.ts`
|
||||
if (!existsSync(fullPath)) {
|
||||
let mArray = Array.from(ServiceMethods, ([name, value]) => ({ name, value }));
|
||||
writeFileSync(fullPath, this.stripIndent`
|
||||
// @ts-nocheck
|
||||
import { GET, Mapper, POST, PUT, DELETE } from "@ann/Http.annotation";
|
||||
import { property, defaultValue, deserialize } from "@ann/JsonToClass";
|
||||
|
||||
// 建议用工具json-class-desktop生成这个类 类型
|
||||
export class ResponseType {
|
||||
@property("id")
|
||||
user_id!: number;
|
||||
}
|
||||
|
||||
export class ${ServiceName}Service {
|
||||
${mArray.map(v => {
|
||||
return `
|
||||
@GET()
|
||||
@Mapper(ResponseType)
|
||||
public async ${v.name} (params: object): Promise<ResponseType[]> {}
|
||||
`
|
||||
}).toString().replaceAll(",", "")
|
||||
}
|
||||
}
|
||||
`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stripIndent(template, ...expressions) {
|
||||
let result = template.reduce((prev, next, i) => {
|
||||
let expression = expressions[i - 1];
|
||||
if ( Array.isArray(expression)) {
|
||||
expression = expression.join('');
|
||||
}
|
||||
return prev + expression + next;
|
||||
});
|
||||
|
||||
const match = result.match(/^[^\S\n]*(?=\S)/gm);
|
||||
const indent = match && Math.min(...match.map(el => el.length));
|
||||
|
||||
if (indent) {
|
||||
const regexp = new RegExp(`^.{${indent}}`, 'gm');
|
||||
result = result.replace(regexp, '');
|
||||
}
|
||||
|
||||
result = result.replace(/^[^\S\n]+/gm, ' ');
|
||||
result = result.trim();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new File
|
||||
61
bin/service-code-generation/utils/ReadApiList.js
Normal file
61
bin/service-code-generation/utils/ReadApiList.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const { createReadStream } = require('fs')
|
||||
|
||||
class ReadApiList {
|
||||
apiListPath = "";
|
||||
lineLength = 0;
|
||||
textArr = [];
|
||||
lineBuffer = Buffer.alloc(4096);
|
||||
text = "";
|
||||
|
||||
constructor(path) {
|
||||
this.apiListPath = path
|
||||
}
|
||||
|
||||
getFileList() {
|
||||
this.text = createReadStream(this.apiListPath)
|
||||
return new Promise((s, e) => {
|
||||
this.textArr = [];
|
||||
let status = false
|
||||
this.text.on('data', (data) => {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if (data[i] == 10 || data[i] == 13) {
|
||||
if (data[i] == 10) {
|
||||
try {
|
||||
var line = this.lineBuffer.slice(0, this.lineLength);
|
||||
if (line.length != 0) {
|
||||
let str = line.toString('utf8')
|
||||
.replace(/^\s+|\s+$/g, '')
|
||||
.replace(/\'/g, "")
|
||||
.replace(/,/g, "")
|
||||
|
||||
if (str.includes("start -")) {
|
||||
status = true
|
||||
continue;
|
||||
}
|
||||
if (str.includes("end -")) {
|
||||
status = false
|
||||
break;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
// console.log("str: ", str.split(":"))
|
||||
this.textArr.push(str);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.lineLength = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.lineBuffer[this.lineLength] = data[i];
|
||||
this.lineLength++;
|
||||
}
|
||||
}
|
||||
|
||||
s(this.textArr)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReadApiList
|
||||
105
bin/tinit
Executable file
105
bin/tinit
Executable 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");
|
||||
|
||||
var isWin = /^win/.test(process.platform);
|
||||
const RootPath = process.cwd();
|
||||
|
||||
program
|
||||
.requiredOption('-t, --file-type <type>', '文件类型: [page,logic,service,impl,less]')
|
||||
.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
|
||||
|
||||
// tsx 页面路径
|
||||
let PagePath = isWin ? `${ RootPath }\\src\\application\\page\\${ UpperCase(programOptions.fileName) }.tsx` : `${ RootPath }/src/application/page/${ UpperCase(programOptions.fileName) }.tsx`;
|
||||
// logic 页面路径
|
||||
let LogicPath = isWin ? `${ RootPath }\\src\\application\\logic\\page\\${ UpperCase(programOptions.fileName) }.logic.ts` : `${ RootPath }/src/application/logic/page/${ UpperCase(programOptions.fileName) }.logic.ts`;
|
||||
// service 页面路径
|
||||
let ServicePath = isWin ? `${ RootPath }\\src\\core\\service\\${ UpperCase(programOptions.fileName) }.service.ts` : `${ RootPath }/src/core/service/${ UpperCase(programOptions.fileName) }.service.ts`;
|
||||
// Impl 页面路径
|
||||
let ImplPath = isWin ? `${ RootPath }\\src\\core\\service\\impl\\${ UpperCase(programOptions.fileName) }.service.impl.ts` : `${ RootPath }/src/core/service/impl/${ UpperCase(programOptions.fileName) }.service.impl.ts`;
|
||||
// Less 页面路径
|
||||
let LessPath = isWin ? `${ RootPath }\\src\\application\\assets\\less\\page\\${ UpperCase(programOptions.fileName) }.less` : `${ RootPath }/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)
|
||||
}
|
||||
Reference in New Issue
Block a user