@lark-apaas/devtool-kits 1.2.2 → 1.2.4

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],
@@ -1151,18 +1159,19 @@ async function parseAndGenerateNestResourceTemplate(options) {
1151
1159
  console.warn("\u672A\u89E3\u6790\u5230\u4EFB\u4F55\u6570\u636E\u5E93\u8868\uFF0C\u65E0\u9700\u751F\u6210 Nest.js \u6A21\u5757\u6A21\u677F");
1152
1160
  return;
1153
1161
  }
1162
+ tables.sort((a, b) => b.variableName.length - a.variableName.length);
1154
1163
  const table = tables[0];
1155
1164
  console.info(`\u751F\u6210 Nest.js ${table.variableName} \u6A21\u5757`);
1156
- const routePath = toKebabCase(table.variableName);
1157
- const moduleDir = join(options.moduleOutputDir, routePath);
1165
+ const filePath = toSnakeCase(table.variableName);
1166
+ const moduleDir = join(options.moduleOutputDir, filePath);
1158
1167
  if (existsSync(moduleDir)) {
1159
- console.info(`Nest.js \u6A21\u5757 ${routePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
1168
+ console.info(`Nest.js \u6A21\u5757 ${filePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
1160
1169
  return;
1161
1170
  }
1162
1171
  const dto = generateDTO(table);
1163
1172
  const controller = generateController(table);
1164
1173
  const service = generateService(table);
1165
- const moduleFilePath = join(moduleDir, `${routePath}.module.ts`);
1174
+ const moduleFilePath = join(moduleDir, `${filePath}.module.ts`);
1166
1175
  const module = generateModule(table);
1167
1176
  try {
1168
1177
  await mkdir(moduleDir, {
@@ -1171,12 +1180,12 @@ async function parseAndGenerateNestResourceTemplate(options) {
1171
1180
  await mkdir(join(moduleDir, "dtos"), {
1172
1181
  recursive: true
1173
1182
  });
1174
- await writeFile(join(moduleDir, "dtos", `${routePath}.dto.ts`), dto);
1175
- await writeFile(join(moduleDir, `${routePath}.controller.ts`), controller);
1176
- await writeFile(join(moduleDir, `${routePath}.service.ts`), service);
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);
1177
1186
  await writeFile(moduleFilePath, module);
1178
1187
  } catch (err) {
1179
- console.error(`\u751F\u6210 Nest.js ${routePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
1188
+ console.error(`\u751F\u6210 Nest.js ${filePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
1180
1189
  await rm(moduleDir, {
1181
1190
  recursive: true
1182
1191
  });