@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.js CHANGED
@@ -514,6 +514,9 @@ function postprocessDrizzleSchema(targetPath) {
514
514
  }
515
515
  __name(postprocessDrizzleSchema, "postprocessDrizzleSchema");
516
516
 
517
+ // src/helpers/gen-nest-resource/generator.ts
518
+ import { pluralize } from "inflection";
519
+
517
520
  // src/helpers/gen-nest-resource/utils.ts
518
521
  function mapDrizzleTypeToTS(field) {
519
522
  const typeMap = {
@@ -591,6 +594,10 @@ function toKebabCase(str) {
591
594
  return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replace(/[_\s]/g, "-");
592
595
  }
593
596
  __name(toKebabCase, "toKebabCase");
597
+ function toSnakeCase(str) {
598
+ return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase().replace(/[-\s]/g, "_");
599
+ }
600
+ __name(toSnakeCase, "toSnakeCase");
594
601
 
595
602
  // src/helpers/gen-nest-resource/generator.ts
596
603
  function generateDTO(table) {
@@ -720,7 +727,8 @@ function generateValidationDecorators(field, { isUpdate = false, isResponse = fa
720
727
  __name(generateValidationDecorators, "generateValidationDecorators");
721
728
  function generateController(table) {
722
729
  const className = toPascalCase(table.variableName);
723
- const routePath = toKebabCase(table.variableName);
730
+ const routePath = toKebabCase(pluralize(table.variableName));
731
+ const filePath = toSnakeCase(table.variableName);
724
732
  const pkField = table.fields.find((f) => f.isPrimaryKey);
725
733
  const pkType = pkField ? mapDrizzleTypeToTS(pkField) : "string";
726
734
  const pkName = pkField ? pkField.name : "id";
@@ -746,8 +754,8 @@ import {
746
754
  Create${className}Dto,
747
755
  Update${className}Dto,
748
756
  ${className}ResponseDto
749
- } from './dtos/${routePath}.dto';
750
- import { ${className}Service } from './${routePath}.service';
757
+ } from './dtos/${filePath}.dto';
758
+ import { ${className}Service } from './${filePath}.service';
751
759
 
752
760
  @ApiTags('${toPascalCase(table.variableName)}')
753
761
  @Controller('api/${routePath}')
@@ -820,7 +828,7 @@ export class ${className}Controller {
820
828
  __name(generateController, "generateController");
821
829
  function generateService(table) {
822
830
  const className = toPascalCase(table.variableName);
823
- const routePath = toKebabCase(table.variableName);
831
+ const filePath = toSnakeCase(table.variableName);
824
832
  const pkField = table.fields.find((f) => f.isPrimaryKey);
825
833
  const pkType = pkField ? mapDrizzleTypeToTS(pkField) : "string";
826
834
  const pkName = pkField ? pkField.name : "id";
@@ -834,7 +842,7 @@ import {
834
842
  Create${className}Dto,
835
843
  Update${className}Dto,
836
844
  ${className}ResponseDto
837
- } from './dtos/${routePath}.dto';
845
+ } from './dtos/${filePath}.dto';
838
846
 
839
847
  @Injectable()
840
848
  export class ${className}Service {
@@ -911,11 +919,11 @@ export class ${className}Service {
911
919
  __name(generateService, "generateService");
912
920
  function generateModule(table) {
913
921
  const className = toPascalCase(table.variableName);
914
- const routePath = toKebabCase(table.variableName);
922
+ const filePath = toSnakeCase(table.variableName);
915
923
  const module = `
916
924
  import { Module } from '@nestjs/common';
917
- import { ${className}Controller } from './${routePath}.controller';
918
- import { ${className}Service } from './${routePath}.service';
925
+ import { ${className}Controller } from './${filePath}.controller';
926
+ import { ${className}Service } from './${filePath}.service';
919
927
 
920
928
  @Module({
921
929
  controllers: [${className}Controller],
@@ -1147,36 +1155,40 @@ async function parseAndGenerateNestResourceTemplate(options) {
1147
1155
  tsConfigFilePath: options.tsConfigFilePath
1148
1156
  });
1149
1157
  const tables = parser.parseSchemaFile(options.schemaFilePath);
1150
- for (const table of tables) {
1151
- console.info(`\u751F\u6210 Nest.js ${table.variableName} \u6A21\u5757`);
1152
- const routePath = toKebabCase(table.variableName);
1153
- const moduleDir = join(options.moduleOutputDir, routePath);
1154
- if (existsSync(moduleDir)) {
1155
- console.info(`Nest.js \u6A21\u5757 ${routePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
1156
- continue;
1157
- }
1158
- const dto = generateDTO(table);
1159
- const controller = generateController(table);
1160
- const service = generateService(table);
1161
- const moduleFilePath = join(moduleDir, `${routePath}.module.ts`);
1162
- const module = generateModule(table);
1163
- try {
1164
- await mkdir(moduleDir, {
1165
- recursive: true
1166
- });
1167
- await mkdir(join(moduleDir, "dtos"), {
1168
- recursive: true
1169
- });
1170
- await writeFile(join(moduleDir, "dtos", `${routePath}.dto.ts`), dto);
1171
- await writeFile(join(moduleDir, `${routePath}.controller.ts`), controller);
1172
- await writeFile(join(moduleDir, `${routePath}.service.ts`), service);
1173
- await writeFile(moduleFilePath, module);
1174
- } catch (err) {
1175
- console.error(`\u751F\u6210 Nest.js ${routePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
1176
- await rm(moduleDir, {
1177
- recursive: true
1178
- });
1179
- }
1158
+ if (tables.length === 0) {
1159
+ console.warn("\u672A\u89E3\u6790\u5230\u4EFB\u4F55\u6570\u636E\u5E93\u8868\uFF0C\u65E0\u9700\u751F\u6210 Nest.js \u6A21\u5757\u6A21\u677F");
1160
+ return;
1161
+ }
1162
+ tables.sort((a, b) => b.variableName.length - a.variableName.length);
1163
+ const table = tables[0];
1164
+ console.info(`\u751F\u6210 Nest.js ${table.variableName} \u6A21\u5757`);
1165
+ const filePath = toSnakeCase(table.variableName);
1166
+ const moduleDir = join(options.moduleOutputDir, filePath);
1167
+ if (existsSync(moduleDir)) {
1168
+ console.info(`Nest.js \u6A21\u5757 ${filePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
1169
+ return;
1170
+ }
1171
+ const dto = generateDTO(table);
1172
+ const controller = generateController(table);
1173
+ const service = generateService(table);
1174
+ const moduleFilePath = join(moduleDir, `${filePath}.module.ts`);
1175
+ const module = generateModule(table);
1176
+ try {
1177
+ await mkdir(moduleDir, {
1178
+ recursive: true
1179
+ });
1180
+ await mkdir(join(moduleDir, "dtos"), {
1181
+ recursive: true
1182
+ });
1183
+ await writeFile(join(moduleDir, "dtos", `${filePath}.dto.ts`), dto);
1184
+ await writeFile(join(moduleDir, `${filePath}.controller.ts`), controller);
1185
+ await writeFile(join(moduleDir, `${filePath}.service.ts`), service);
1186
+ await writeFile(moduleFilePath, module);
1187
+ } catch (err) {
1188
+ console.error(`\u751F\u6210 Nest.js ${filePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
1189
+ await rm(moduleDir, {
1190
+ recursive: true
1191
+ });
1180
1192
  }
1181
1193
  }
1182
1194
  __name(parseAndGenerateNestResourceTemplate, "parseAndGenerateNestResourceTemplate");