Files
TsxVueClassApi/bin/service-code-generation/index.js
编码猿 dc70b5fc26 rr
2025-08-29 22:07:01 +08:00

34 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 () => {
// 读取配置文件中,注释 start 和 end 中间的 对象代码
let readApi = new readApiList(config.apiListPath)
let res = await readApi.getFileList()
console.log("getFileList: ", res)
// 处理读取到的 字符串数组将多个key方法进行分类归入不同的class文件中
// 比如 Car_carList 和 Car_addCar应该同属 Car.service.ts
// carList 和 addCar 则为文件中class的方法
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()