@biuxiu/codegen 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/README.md +11 -0
  2. package/dist/code/nest.d.ts +11 -0
  3. package/dist/code/nest.js +229 -0
  4. package/dist/compile.d.ts +1 -0
  5. package/dist/compile.js +58 -0
  6. package/dist/config.d.ts +11 -0
  7. package/dist/config.js +53 -0
  8. package/dist/format/api.d.ts +8 -0
  9. package/dist/format/api.js +122 -0
  10. package/dist/format/base.d.ts +10 -0
  11. package/dist/format/base.js +56 -0
  12. package/dist/format/dto.d.ts +8 -0
  13. package/dist/format/dto.js +116 -0
  14. package/dist/format/entity.d.ts +7 -0
  15. package/dist/format/entity.js +68 -0
  16. package/dist/format/service.d.ts +8 -0
  17. package/dist/format/service.js +93 -0
  18. package/dist/gen-type.d.ts +1 -0
  19. package/dist/gen-type.js +66 -0
  20. package/dist/index.d.ts +4 -0
  21. package/dist/index.js +48 -0
  22. package/dist/libs/index.d.ts +1 -0
  23. package/dist/libs/index.js +30 -0
  24. package/dist/libs/nest-lib.d.ts +5 -0
  25. package/dist/libs/nest-lib.js +41 -0
  26. package/dist/libs/vue-lib.d.ts +1 -0
  27. package/dist/libs/vue-lib.js +30 -0
  28. package/dist/render.d.ts +3 -0
  29. package/dist/render.js +32 -0
  30. package/dist/types.d.ts +28 -0
  31. package/dist/types.js +16 -0
  32. package/dist/util.d.ts +2 -0
  33. package/dist/util.js +48 -0
  34. package/package.json +39 -0
  35. package/pkg/README.md +11 -0
  36. package/sources/base-type.txt +6 -0
  37. package/sources/controller.btpl +8 -0
  38. package/sources/create-dto.btpl +4 -0
  39. package/sources/entity.btpl +8 -0
  40. package/sources/module.btpl +13 -0
  41. package/sources/nest-type.txt +88 -0
  42. package/sources/service.btpl +11 -0
  43. package/sources/update-dto.btpl +4 -0
  44. package/sources/vue-type.txt +27 -0
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@biuxiu/codegen",
3
+ "version": "0.1.1",
4
+ "description": "代码生成工具",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test:dev": "tsx scripts/dev.ts",
8
+ "test:rm": "tsx scripts/dev.ts -d",
9
+ "test:prod": "node scripts/prod.js",
10
+ "build:script": "tsx scripts/build.ts",
11
+ "build:wasm": "wasm-pack build --target nodejs --release",
12
+ "publish:x": "xiu -o -c -h 'npm run build:script' -n"
13
+ },
14
+ "files": [
15
+ "bin",
16
+ "dist",
17
+ "pkg",
18
+ "sources",
19
+ "README.md"
20
+ ],
21
+ "keywords": [],
22
+ "author": "dgzhuya",
23
+ "license": "ISC",
24
+ "devDependencies": {
25
+ "@types/node": "^20.14.2",
26
+ "@types/shelljs": "^0.8.15",
27
+ "esbuild": "^0.21.5",
28
+ "esbuild-plugin-d.ts": "^1.2.3",
29
+ "tsx": "^4.15.1",
30
+ "typescript": "^5.4.5"
31
+ },
32
+ "dependencies": {
33
+ "@biuxiu/template": "^1.2.3",
34
+ "module-alias": "^2.2.3",
35
+ "prettier": "^3.3.2",
36
+ "shelljs": "^0.8.5",
37
+ "ts-morph": "^22.0.0"
38
+ }
39
+ }
package/pkg/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # lua codegen
2
+
3
+ ### 使用lua+nodejs实现项目代码生成功能
4
+
5
+ - 初始化项目
6
+ ```sh
7
+ # 安装依赖
8
+ pnpm i
9
+ # 初始化模板类型信息
10
+ pnpm template-init
11
+ ```
@@ -0,0 +1,6 @@
1
+ --- @meta Base
2
+
3
+ --- @alias FieldType 'string' | 'number' | 'bool'
4
+
5
+ --- 打印输出
6
+ function logger(...) end
@@ -0,0 +1,8 @@
1
+ import { {%up@name%}Service } from './{%name%}.service'
2
+ {%importInfo%}
3
+
4
+ @Controller('{%name%}')
5
+ export class {%up@name%}Controller {
6
+ constructor(private readonly {%name%}Service: {%up@name%}Service) {}
7
+ {%content%}
8
+ }
@@ -0,0 +1,4 @@
1
+ {%importInfo%}
2
+ export class Create{%up@name%}Dto {
3
+ {%content%}
4
+ }
@@ -0,0 +1,8 @@
1
+ import { BaseEntity } from '@api/common/entities/base.entity'
2
+ import { Column, Entity } from 'typeorm'
3
+ {%importInfo%}
4
+
5
+ @Entity('w_{%name%}')
6
+ export class {%up@name%}Entity extends BaseEntity {
7
+ {%content%}
8
+ }
@@ -0,0 +1,13 @@
1
+ import { Module } from '@nestjs/common'
2
+ import { {%up@name%}Service } from './{%name%}.service'
3
+ import { {%up@name%}Controller } from './{%name%}.controller'
4
+ import { TypeOrmModule } from '@nestjs/typeorm'
5
+ import { {%up@name%}Entity } from './entities/{%name%}.entity'
6
+
7
+ @Module({
8
+ imports: [TypeOrmModule.forFeature([{%up@name%}Entity])],
9
+ controllers: [{%up@name%}Controller],
10
+ providers: [{%up@name%}Service],
11
+ exports: [{%up@name%}Service]
12
+ })
13
+ export class {%up@name%}Module {}
@@ -0,0 +1,88 @@
1
+ --- @meta NestJs
2
+
3
+ --- @class NestJs
4
+ NestJs = {}
5
+
6
+ --- @alias SetTblFn fun(tbl: table)
7
+
8
+ --- 生成限制规则
9
+ ---
10
+ --- @param msg string 消息提示
11
+ --- @param min number | nil 最小值
12
+ --- @param max number | nil 最大值
13
+ --- @return SetTblFn
14
+ function NestJs.createLimitRule(msg, min, max) end
15
+
16
+ --- @alias SimpleRuleType 'isOptional' | 'notEmpty' | 'isInt' | 'isNumber'
17
+
18
+ --- 生成简单规则
19
+ ---
20
+ --- @param key SimpleRuleType 规则类型
21
+ --- @param msg string | true 消息提示
22
+ --- @return SetTblFn
23
+ function NestJs.createSimpleRule(key, msg) end
24
+
25
+ --- @class DtoField
26
+ --- @field key string
27
+ --- @field type FieldType
28
+
29
+ --- 生成DTO字段信息
30
+ ---
31
+ --- @param key string 字段名
32
+ --- @param type FieldType 字段类型
33
+ --- @param ... SetTblFn 字段规则函数
34
+ --- @return DtoField
35
+ function NestJs.creteDtoField(key, type, ...) end
36
+
37
+ --- @alias SimpleColumnType 'isExclude' | 'comment' | 'length' | 'nullable' | 'name'
38
+
39
+ --- 创建数据表字段特征
40
+ ---
41
+ --- @param key SimpleColumnType 特征名
42
+ --- @param value number | string | true 字段值
43
+ --- @return SetTblFn
44
+ function NestJs.createSimpleColumn(key, value) end
45
+
46
+ --- 创建字段表类型
47
+ ---
48
+ --- @param type 'int' | 'datetime' | 'varchar' | 'tinyint' 表类型
49
+ --- @return SetTblFn
50
+ function NestJs.creteColumnType(type) end
51
+
52
+ --- @class EntityField
53
+ --- @field key string
54
+ --- @field type FieldType
55
+ --- @field column number
56
+
57
+ --- 生成Entity字段信息
58
+ ---
59
+ --- @param key string 字段名
60
+ --- @param type FieldType 字段类型
61
+ --- @param ... SetTblFn 字段数据库类型
62
+ --- @return EntityField
63
+ function NestJs.creteEntityField(key, type, ...) end
64
+
65
+ --- @alias ApiServiceFieldKey 'get' | 'all' | 'delete' | 'update' | 'add'
66
+
67
+ --- @class ApiServiceField
68
+ --- @field key ApiServiceFieldKey
69
+ --- @field interceptor true
70
+
71
+ --- 创建请求API和服务结构体
72
+ ---
73
+ --- @param key ApiServiceFieldKey
74
+ --- @param interceptor true | nil
75
+ --- @return ApiServiceField
76
+ function NestJs.createApiService(key, interceptor) end
77
+
78
+ --- @class RenderConfig
79
+ --- @field name string
80
+ --- @field path? string
81
+
82
+ --- 创建后端代码
83
+ ---
84
+ --- @param config RenderConfig 模块名
85
+ --- @param dto DtoField[] dto数据结构
86
+ --- @param entity EntityField[] entity数据结构
87
+ --- @param apiService ApiServiceField[] entity数据结构
88
+ function NestJs.renderToCode(config, dto, entity, apiService) end
@@ -0,0 +1,11 @@
1
+ import { Injectable } from '@nestjs/common'
2
+ import { InjectRepository } from '@nestjs/typeorm'
3
+ import { Repository } from 'typeorm'
4
+ {%importInfo%}import { {%up@name%}Entity } from './entities/{%name%}.entity'
5
+
6
+ @Injectable()
7
+ export class {%up@name%}Service {
8
+ constructor(@InjectRepository({%up@name%}Entity) private readonly {%name%}Repository: Repository<{%up@name%}Entity>) {}
9
+
10
+ {%content%}
11
+ }
@@ -0,0 +1,4 @@
1
+ import { PartialType } from '@nestjs/mapped-types'
2
+ import { Create{%up@name%}Dto } from './create-{%name%}.dto'
3
+
4
+ export class Update{%up@name%}Dto extends PartialType(Create{%up@name%}Dto) {}
@@ -0,0 +1,27 @@
1
+ ---@meta VueJs
2
+
3
+ --- @class VueJs
4
+ VueJs = {}
5
+
6
+ --- @class WebRoute 前端路由信息
7
+ --- @field path string 路由路径
8
+ --- @field name string 路由名
9
+ --- @field title string 路由标题
10
+ --- @field icon string 路由图标
11
+
12
+ --- @class WebTable 前端表格信息
13
+
14
+ --- @class WebForm 前端表单信息
15
+
16
+ --[[
17
+ --- 接收路由信息,并生成前端代码
18
+ ---
19
+ --- @param route WebRoute 路由信息
20
+ --- @param tbl WebTable 表展示数据
21
+ --- @param form WebForm 表单展示数据
22
+ --- @param name string 模块名,使用`.`分隔上下级模块
23
+ ]]
24
+
25
+
26
+
27
+ function VueJs.genWebCode(route, tbl) end