@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 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/${routePath}.dto';
791
- import { ${className}Service } from './${routePath}.service';
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 routePath = toKebabCase(table.variableName);
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/${routePath}.dto';
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 routePath = toKebabCase(table.variableName);
963
+ const filePath = toSnakeCase(table.variableName);
956
964
  const module2 = `
957
965
  import { Module } from '@nestjs/common';
958
- import { ${className}Controller } from './${routePath}.controller';
959
- import { ${className}Service } from './${routePath}.service';
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
- for (const table of tables) {
1192
- console.info(`\u751F\u6210 Nest.js ${table.variableName} \u6A21\u5757`);
1193
- const routePath = toKebabCase(table.variableName);
1194
- const moduleDir = (0, import_path.join)(options.moduleOutputDir, routePath);
1195
- if ((0, import_fs.existsSync)(moduleDir)) {
1196
- console.info(`Nest.js \u6A21\u5757 ${routePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
1197
- continue;
1198
- }
1199
- const dto = generateDTO(table);
1200
- const controller = generateController(table);
1201
- const service = generateService(table);
1202
- const moduleFilePath = (0, import_path.join)(moduleDir, `${routePath}.module.ts`);
1203
- const module2 = generateModule(table);
1204
- try {
1205
- await (0, import_promises.mkdir)(moduleDir, {
1206
- recursive: true
1207
- });
1208
- await (0, import_promises.mkdir)((0, import_path.join)(moduleDir, "dtos"), {
1209
- recursive: true
1210
- });
1211
- await (0, import_promises.writeFile)((0, import_path.join)(moduleDir, "dtos", `${routePath}.dto.ts`), dto);
1212
- await (0, import_promises.writeFile)((0, import_path.join)(moduleDir, `${routePath}.controller.ts`), controller);
1213
- await (0, import_promises.writeFile)((0, import_path.join)(moduleDir, `${routePath}.service.ts`), service);
1214
- await (0, import_promises.writeFile)(moduleFilePath, module2);
1215
- } catch (err) {
1216
- console.error(`\u751F\u6210 Nest.js ${routePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
1217
- await (0, import_promises.rm)(moduleDir, {
1218
- recursive: true
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");