@lark-apaas/devtool-kits 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +50 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -38
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -555,6 +555,9 @@ function postprocessDrizzleSchema(targetPath) {
|
|
|
555
555
|
}
|
|
556
556
|
__name(postprocessDrizzleSchema, "postprocessDrizzleSchema");
|
|
557
557
|
|
|
558
|
+
// src/helpers/gen-nest-resource/generator.ts
|
|
559
|
+
var import_inflection = require("inflection");
|
|
560
|
+
|
|
558
561
|
// src/helpers/gen-nest-resource/utils.ts
|
|
559
562
|
function mapDrizzleTypeToTS(field) {
|
|
560
563
|
const typeMap = {
|
|
@@ -632,6 +635,10 @@ function toKebabCase(str) {
|
|
|
632
635
|
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replace(/[_\s]/g, "-");
|
|
633
636
|
}
|
|
634
637
|
__name(toKebabCase, "toKebabCase");
|
|
638
|
+
function toSnakeCase(str) {
|
|
639
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase().replace(/[-\s]/g, "_");
|
|
640
|
+
}
|
|
641
|
+
__name(toSnakeCase, "toSnakeCase");
|
|
635
642
|
|
|
636
643
|
// src/helpers/gen-nest-resource/generator.ts
|
|
637
644
|
function generateDTO(table) {
|
|
@@ -761,7 +768,8 @@ function generateValidationDecorators(field, { isUpdate = false, isResponse = fa
|
|
|
761
768
|
__name(generateValidationDecorators, "generateValidationDecorators");
|
|
762
769
|
function generateController(table) {
|
|
763
770
|
const className = toPascalCase(table.variableName);
|
|
764
|
-
const routePath = toKebabCase(table.variableName);
|
|
771
|
+
const routePath = toKebabCase((0, import_inflection.pluralize)(table.variableName));
|
|
772
|
+
const filePath = toSnakeCase(table.variableName);
|
|
765
773
|
const pkField = table.fields.find((f) => f.isPrimaryKey);
|
|
766
774
|
const pkType = pkField ? mapDrizzleTypeToTS(pkField) : "string";
|
|
767
775
|
const pkName = pkField ? pkField.name : "id";
|
|
@@ -787,8 +795,8 @@ import {
|
|
|
787
795
|
Create${className}Dto,
|
|
788
796
|
Update${className}Dto,
|
|
789
797
|
${className}ResponseDto
|
|
790
|
-
} from './dtos/${
|
|
791
|
-
import { ${className}Service } from './${
|
|
798
|
+
} from './dtos/${filePath}.dto';
|
|
799
|
+
import { ${className}Service } from './${filePath}.service';
|
|
792
800
|
|
|
793
801
|
@ApiTags('${toPascalCase(table.variableName)}')
|
|
794
802
|
@Controller('api/${routePath}')
|
|
@@ -861,7 +869,7 @@ export class ${className}Controller {
|
|
|
861
869
|
__name(generateController, "generateController");
|
|
862
870
|
function generateService(table) {
|
|
863
871
|
const className = toPascalCase(table.variableName);
|
|
864
|
-
const
|
|
872
|
+
const filePath = toSnakeCase(table.variableName);
|
|
865
873
|
const pkField = table.fields.find((f) => f.isPrimaryKey);
|
|
866
874
|
const pkType = pkField ? mapDrizzleTypeToTS(pkField) : "string";
|
|
867
875
|
const pkName = pkField ? pkField.name : "id";
|
|
@@ -875,7 +883,7 @@ import {
|
|
|
875
883
|
Create${className}Dto,
|
|
876
884
|
Update${className}Dto,
|
|
877
885
|
${className}ResponseDto
|
|
878
|
-
} from './dtos/${
|
|
886
|
+
} from './dtos/${filePath}.dto';
|
|
879
887
|
|
|
880
888
|
@Injectable()
|
|
881
889
|
export class ${className}Service {
|
|
@@ -952,11 +960,11 @@ export class ${className}Service {
|
|
|
952
960
|
__name(generateService, "generateService");
|
|
953
961
|
function generateModule(table) {
|
|
954
962
|
const className = toPascalCase(table.variableName);
|
|
955
|
-
const
|
|
963
|
+
const filePath = toSnakeCase(table.variableName);
|
|
956
964
|
const module2 = `
|
|
957
965
|
import { Module } from '@nestjs/common';
|
|
958
|
-
import { ${className}Controller } from './${
|
|
959
|
-
import { ${className}Service } from './${
|
|
966
|
+
import { ${className}Controller } from './${filePath}.controller';
|
|
967
|
+
import { ${className}Service } from './${filePath}.service';
|
|
960
968
|
|
|
961
969
|
@Module({
|
|
962
970
|
controllers: [${className}Controller],
|
|
@@ -1188,36 +1196,40 @@ async function parseAndGenerateNestResourceTemplate(options) {
|
|
|
1188
1196
|
tsConfigFilePath: options.tsConfigFilePath
|
|
1189
1197
|
});
|
|
1190
1198
|
const tables = parser.parseSchemaFile(options.schemaFilePath);
|
|
1191
|
-
|
|
1192
|
-
console.
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1199
|
+
if (tables.length === 0) {
|
|
1200
|
+
console.warn("\u672A\u89E3\u6790\u5230\u4EFB\u4F55\u6570\u636E\u5E93\u8868\uFF0C\u65E0\u9700\u751F\u6210 Nest.js \u6A21\u5757\u6A21\u677F");
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
tables.sort((a, b) => b.variableName.length - a.variableName.length);
|
|
1204
|
+
const table = tables[0];
|
|
1205
|
+
console.info(`\u751F\u6210 Nest.js ${table.variableName} \u6A21\u5757`);
|
|
1206
|
+
const filePath = toSnakeCase(table.variableName);
|
|
1207
|
+
const moduleDir = (0, import_path.join)(options.moduleOutputDir, filePath);
|
|
1208
|
+
if ((0, import_fs.existsSync)(moduleDir)) {
|
|
1209
|
+
console.info(`Nest.js \u6A21\u5757 ${filePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
const dto = generateDTO(table);
|
|
1213
|
+
const controller = generateController(table);
|
|
1214
|
+
const service = generateService(table);
|
|
1215
|
+
const moduleFilePath = (0, import_path.join)(moduleDir, `${filePath}.module.ts`);
|
|
1216
|
+
const module2 = generateModule(table);
|
|
1217
|
+
try {
|
|
1218
|
+
await (0, import_promises.mkdir)(moduleDir, {
|
|
1219
|
+
recursive: true
|
|
1220
|
+
});
|
|
1221
|
+
await (0, import_promises.mkdir)((0, import_path.join)(moduleDir, "dtos"), {
|
|
1222
|
+
recursive: true
|
|
1223
|
+
});
|
|
1224
|
+
await (0, import_promises.writeFile)((0, import_path.join)(moduleDir, "dtos", `${filePath}.dto.ts`), dto);
|
|
1225
|
+
await (0, import_promises.writeFile)((0, import_path.join)(moduleDir, `${filePath}.controller.ts`), controller);
|
|
1226
|
+
await (0, import_promises.writeFile)((0, import_path.join)(moduleDir, `${filePath}.service.ts`), service);
|
|
1227
|
+
await (0, import_promises.writeFile)(moduleFilePath, module2);
|
|
1228
|
+
} catch (err) {
|
|
1229
|
+
console.error(`\u751F\u6210 Nest.js ${filePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
|
|
1230
|
+
await (0, import_promises.rm)(moduleDir, {
|
|
1231
|
+
recursive: true
|
|
1232
|
+
});
|
|
1221
1233
|
}
|
|
1222
1234
|
}
|
|
1223
1235
|
__name(parseAndGenerateNestResourceTemplate, "parseAndGenerateNestResourceTemplate");
|