@tsed/cli-plugin-typeorm 3.19.5 → 3.20.1

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.
@@ -4,13 +4,11 @@ exports.CliPluginTypeORMModule = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const cli_core_1 = require("@tsed/cli-core");
6
6
  const di_1 = require("@tsed/di");
7
- const TypeORMCmd_1 = require("./commands/TypeORMCmd");
8
7
  const TypeORMGenerateHook_1 = require("./hooks/TypeORMGenerateHook");
9
8
  const TypeORMInitHook_1 = require("./hooks/TypeORMInitHook");
10
9
  let CliPluginTypeORMModule = class CliPluginTypeORMModule {
11
10
  install() {
12
11
  this.packageJson.addDependencies({
13
- "@tsed/typeorm": this.packageJson.dependencies["@tsed/common"],
14
12
  typeorm: "latest"
15
13
  });
16
14
  }
@@ -27,7 +25,7 @@ tslib_1.__decorate([
27
25
  ], CliPluginTypeORMModule.prototype, "install", null);
28
26
  CliPluginTypeORMModule = tslib_1.__decorate([
29
27
  cli_core_1.Module({
30
- imports: [TypeORMInitHook_1.TypeORMInitHook, TypeORMGenerateHook_1.TypeORMGenerateHook, TypeORMCmd_1.TypeORMCmd]
28
+ imports: [TypeORMInitHook_1.TypeORMInitHook, TypeORMGenerateHook_1.TypeORMGenerateHook]
31
29
  })
32
30
  ], CliPluginTypeORMModule);
33
31
  exports.CliPluginTypeORMModule = CliPluginTypeORMModule;
@@ -1 +1 @@
1
- {"version":3,"file":"CliPluginTypeORMModule.js","sourceRoot":"","sources":["../src/CliPluginTypeORMModule.ts"],"names":[],"mappings":";;;;AAAA,6CAAiE;AACjE,iCAAgC;AAChC,sDAAiD;AACjD,qEAAgE;AAChE,6DAAwD;AAKxD,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAKjC,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;YAC/B,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC;YAC9D,OAAO,EAAE,QAAQ;SAClB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AATC;IADC,WAAM,EAAE;sCACI,6BAAkB;2DAAC;AAGhC;IADC,gBAAK,CAAC,0BAA0B,CAAC;;;;qDAMjC;AAVU,sBAAsB;IAHlC,iBAAM,CAAC;QACN,OAAO,EAAE,CAAC,iCAAe,EAAE,yCAAmB,EAAE,uBAAU,CAAC;KAC5D,CAAC;GACW,sBAAsB,CAWlC;AAXY,wDAAsB","sourcesContent":["import {Module, OnAdd, ProjectPackageJson} from \"@tsed/cli-core\";\nimport {Inject} from \"@tsed/di\";\nimport {TypeORMCmd} from \"./commands/TypeORMCmd\";\nimport {TypeORMGenerateHook} from \"./hooks/TypeORMGenerateHook\";\nimport {TypeORMInitHook} from \"./hooks/TypeORMInitHook\";\n\n@Module({\n imports: [TypeORMInitHook, TypeORMGenerateHook, TypeORMCmd]\n})\nexport class CliPluginTypeORMModule {\n @Inject()\n packageJson: ProjectPackageJson;\n\n @OnAdd(\"@tsed/cli-plugin-typeorm\")\n install() {\n this.packageJson.addDependencies({\n \"@tsed/typeorm\": this.packageJson.dependencies[\"@tsed/common\"],\n typeorm: \"latest\"\n });\n }\n}\n"]}
1
+ {"version":3,"file":"CliPluginTypeORMModule.js","sourceRoot":"","sources":["../src/CliPluginTypeORMModule.ts"],"names":[],"mappings":";;;;AAAA,6CAAiE;AACjE,iCAAgC;AAChC,qEAAgE;AAChE,6DAAwD;AAKxD,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAKjC,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;YAC/B,OAAO,EAAE,QAAQ;SAClB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AARC;IADC,WAAM,EAAE;sCACI,6BAAkB;2DAAC;AAGhC;IADC,gBAAK,CAAC,0BAA0B,CAAC;;;;qDAKjC;AATU,sBAAsB;IAHlC,iBAAM,CAAC;QACN,OAAO,EAAE,CAAC,iCAAe,EAAE,yCAAmB,CAAC;KAChD,CAAC;GACW,sBAAsB,CAUlC;AAVY,wDAAsB","sourcesContent":["import {Module, OnAdd, ProjectPackageJson} from \"@tsed/cli-core\";\nimport {Inject} from \"@tsed/di\";\nimport {TypeORMGenerateHook} from \"./hooks/TypeORMGenerateHook\";\nimport {TypeORMInitHook} from \"./hooks/TypeORMInitHook\";\n\n@Module({\n imports: [TypeORMInitHook, TypeORMGenerateHook]\n})\nexport class CliPluginTypeORMModule {\n @Inject()\n packageJson: ProjectPackageJson;\n\n @OnAdd(\"@tsed/cli-plugin-typeorm\")\n install() {\n this.packageJson.addDependencies({\n typeorm: \"latest\"\n });\n }\n}\n"]}
@@ -1,16 +1,13 @@
1
1
  import { GenerateCmdContext, ProvidersInfoService } from "@tsed/cli";
2
2
  import { CliDockerComposeYaml, ProjectPackageJson, SrcRendererService, Tasks } from "@tsed/cli-core";
3
- import { CliTypeORM } from "../services/CliTypeORM";
4
3
  export interface TypeORMGenerateOptions extends GenerateCmdContext {
5
- typeormConnection: string;
6
- connectionName: string;
4
+ typeormDataSource: string;
5
+ datasourceName: string;
7
6
  }
8
7
  export declare class TypeORMGenerateHook {
9
8
  private providersInfoService;
10
- projectPackageJson: ProjectPackageJson;
11
- srcRenderService: SrcRendererService;
12
- cliTypeORM: CliTypeORM;
13
- packages: any[];
9
+ protected projectPackageJson: ProjectPackageJson;
10
+ protected srcRenderService: SrcRendererService;
14
11
  protected cliDockerComposeYaml: CliDockerComposeYaml;
15
12
  constructor(providersInfoService: ProvidersInfoService);
16
13
  onGeneratePrompt(): Promise<{
@@ -24,5 +21,8 @@ export declare class TypeORMGenerateHook {
24
21
  }[]>;
25
22
  }[]>;
26
23
  onGenerateExec(ctx: TypeORMGenerateOptions): Tasks;
27
- private mapOptions;
24
+ generateDataSourceTasks(ctx: TypeORMGenerateOptions): {
25
+ title: string;
26
+ task: () => Promise<void>;
27
+ }[];
28
28
  }
@@ -6,15 +6,14 @@ const tslib_1 = require("tslib");
6
6
  const cli_1 = require("@tsed/cli");
7
7
  const cli_core_1 = require("@tsed/cli-core");
8
8
  const di_1 = require("@tsed/di");
9
- const change_case_1 = require("change-case");
10
- const CliTypeORM_1 = require("../services/CliTypeORM");
9
+ const templateDir_1 = require("../utils/templateDir");
11
10
  let TypeORMGenerateHook = TypeORMGenerateHook_1 = class TypeORMGenerateHook {
12
11
  constructor(providersInfoService) {
13
12
  this.providersInfoService = providersInfoService;
14
13
  providersInfoService.add({
15
- name: "TypeORM Connection",
16
- value: "typeorm:connection",
17
- model: "{{symbolName}}.connection"
14
+ name: "TypeORM Datasource",
15
+ value: "typeorm:datasource",
16
+ model: "{{symbolName}}.datasource"
18
17
  }, TypeORMGenerateHook_1);
19
18
  }
20
19
  async onGeneratePrompt() {
@@ -27,10 +26,10 @@ let TypeORMGenerateHook = TypeORMGenerateHook_1 = class TypeORMGenerateHook {
27
26
  return [
28
27
  {
29
28
  type: "autocomplete",
30
- name: "typeormConnection",
31
- message: "Which passport package ?",
29
+ name: "typeormDataSource",
30
+ message: "Which database type?",
32
31
  when(state) {
33
- return ["typeorm:connection"].includes(state.type);
32
+ return state.type === "typeorm:datasource";
34
33
  },
35
34
  source: async (state, keyword) => {
36
35
  if (keyword) {
@@ -42,37 +41,39 @@ let TypeORMGenerateHook = TypeORMGenerateHook_1 = class TypeORMGenerateHook {
42
41
  ];
43
42
  }
44
43
  onGenerateExec(ctx) {
45
- var _a;
46
44
  if (this.providersInfoService.isMyProvider(ctx.type, TypeORMGenerateHook_1)) {
47
- ctx = this.mapOptions(ctx);
48
- const { typeormConnection, symbolPath } = ctx;
49
- const connection = cli_1.FEATURES_TYPEORM_CONNECTION_TYPES.find((item) => item.value.type === typeormConnection);
50
- if ((_a = connection === null || connection === void 0 ? void 0 : connection.value) === null || _a === void 0 ? void 0 : _a.dependencies) {
51
- this.projectPackageJson.addDependencies((connection === null || connection === void 0 ? void 0 : connection.value.dependencies) || {});
52
- }
53
- const database = ctx.typeormConnection.split(":")[1];
54
- return [
55
- {
56
- title: `Generate TypeORM connection file to '${symbolPath}.ts'`,
57
- task: () => this.cliTypeORM.generateConnection(ctx.name, ctx)
58
- },
59
- {
60
- title: `Generate TypeORM configuration file to '${ctx.connectionName}.config.json'`,
61
- task: () => this.cliTypeORM.writeConfig(ctx.connectionName, database)
62
- },
63
- {
64
- title: "Generate docker-compose configuration",
65
- task: async () => this.cliDockerComposeYaml.addDatabaseService(ctx.name, database)
66
- }
67
- ];
45
+ return this.generateDataSourceTasks(ctx);
68
46
  }
69
47
  return [];
70
48
  }
71
- mapOptions(options) {
72
- return {
73
- ...options,
74
- connectionName: change_case_1.paramCase(options.name).replace("-connection", "")
75
- };
49
+ generateDataSourceTasks(ctx) {
50
+ var _a;
51
+ const { typeormDataSource, symbolPath, name } = ctx;
52
+ const connection = cli_1.FEATURES_TYPEORM_CONNECTION_TYPES.find((item) => item.value.type === typeormDataSource);
53
+ if ((_a = connection === null || connection === void 0 ? void 0 : connection.value) === null || _a === void 0 ? void 0 : _a.dependencies) {
54
+ this.projectPackageJson.addDependencies((connection === null || connection === void 0 ? void 0 : connection.value.dependencies) || {});
55
+ }
56
+ const database = typeormDataSource.split(":").at(-1);
57
+ return [
58
+ {
59
+ title: `Generate TypeORM connection file to '${symbolPath}.ts'`,
60
+ task: () => {
61
+ return this.srcRenderService.render("datasource.hbs", {
62
+ name,
63
+ database,
64
+ symbolName: ctx.symbolName.replace("Datasource", "DataSource")
65
+ }, {
66
+ templateDir: templateDir_1.TEMPLATE_DIR,
67
+ output: `${ctx.symbolPath}.ts`,
68
+ rootDir: this.srcRenderService.rootDir
69
+ });
70
+ }
71
+ },
72
+ {
73
+ title: "Generate docker-compose configuration",
74
+ task: async () => this.cliDockerComposeYaml.addDatabaseService(name, database)
75
+ }
76
+ ];
76
77
  }
77
78
  };
78
79
  tslib_1.__decorate([
@@ -83,10 +84,6 @@ tslib_1.__decorate([
83
84
  cli_core_1.Inject(),
84
85
  tslib_1.__metadata("design:type", cli_core_1.SrcRendererService)
85
86
  ], TypeORMGenerateHook.prototype, "srcRenderService", void 0);
86
- tslib_1.__decorate([
87
- cli_core_1.Inject(),
88
- tslib_1.__metadata("design:type", CliTypeORM_1.CliTypeORM)
89
- ], TypeORMGenerateHook.prototype, "cliTypeORM", void 0);
90
87
  tslib_1.__decorate([
91
88
  cli_core_1.Inject(),
92
89
  tslib_1.__metadata("design:type", cli_core_1.CliDockerComposeYaml)
@@ -1 +1 @@
1
- {"version":3,"file":"TypeORMGenerateHook.js","sourceRoot":"","sources":["../../src/hooks/TypeORMGenerateHook.ts"],"names":[],"mappings":";;;;;AAAA,mCAAsG;AACtG,6CAA6H;AAC7H,iCAAoC;AACpC,6CAAsC;AACtC,uDAAkD;AAQlD,IAAa,mBAAmB,2BAAhC,MAAa,mBAAmB;IAe9B,YAAoB,oBAA0C;QAA1C,yBAAoB,GAApB,oBAAoB,CAAsB;QAC5D,oBAAoB,CAAC,GAAG,CACtB;YACE,IAAI,EAAE,oBAAoB;YAC1B,KAAK,EAAE,oBAAoB;YAC3B,KAAK,EAAE,2BAA2B;SACnC,EACD,qBAAmB,CACpB,CAAC;IACJ,CAAC;IAGD,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,GAAG,uCAAiC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YAC1D,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO;YACL;gBACE,IAAI,EAAE,cAAc;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,0BAA0B;gBACnC,IAAI,CAAC,KAAU;oBACb,OAAO,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC;gBACD,MAAM,EAAE,KAAK,EAAE,KAAU,EAAE,OAAe,EAAE,EAAE;oBAC5C,IAAI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C,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC;iBACtE;gBACD;oBACE,KAAK,EAAE,uCAAuC;oBAC9C,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;iBACnF;aACF,CAAC;SACH;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,UAAU,CAAC,OAA+B;QAChD,OAAO;YACL,GAAG,OAAO;YACV,cAAc,EAAE,uBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;SACnE,CAAC;IACJ,CAAC;CACF,CAAA;AA1FC;IADC,iBAAM,EAAE;sCACW,6BAAkB;+DAAC;AAGvC;IADC,iBAAM,EAAE;sCACS,6BAAkB;6DAAC;AAGrC;IADC,iBAAM,EAAE;sCACG,uBAAU;uDAAC;AAKvB;IADC,iBAAM,EAAE;sCACuB,+BAAoB;iEAAC;AAcrD;IADC,mBAAQ,CAAC,UAAU,CAAC;;;;2DA0BpB;AAGD;IADC,iBAAM,CAAC,UAAU,CAAC;;;;yDA8BlB;AApFU,mBAAmB;IAD/B,eAAU,EAAE;6CAgB+B,0BAAoB;GAfnD,mBAAmB,CA4F/B;AA5FY,kDAAmB","sourcesContent":["import {FEATURES_TYPEORM_CONNECTION_TYPES, GenerateCmdContext, ProvidersInfoService} from \"@tsed/cli\";\nimport {CliDockerComposeYaml, Inject, OnExec, OnPrompt, ProjectPackageJson, SrcRendererService, Tasks} from \"@tsed/cli-core\";\nimport {Injectable} from \"@tsed/di\";\nimport {paramCase} from \"change-case\";\nimport {CliTypeORM} from \"../services/CliTypeORM\";\n\nexport interface TypeORMGenerateOptions extends GenerateCmdContext {\n typeormConnection: string;\n connectionName: string;\n}\n\n@Injectable()\nexport class TypeORMGenerateHook {\n @Inject()\n projectPackageJson: ProjectPackageJson;\n\n @Inject()\n srcRenderService: SrcRendererService;\n\n @Inject()\n cliTypeORM: CliTypeORM;\n\n packages: any[];\n\n @Inject()\n protected cliDockerComposeYaml: CliDockerComposeYaml;\n\n constructor(private providersInfoService: ProvidersInfoService) {\n providersInfoService.add(\n {\n name: \"TypeORM Connection\",\n value: \"typeorm:connection\",\n model: \"{{symbolName}}.connection\"\n },\n TypeORMGenerateHook\n );\n }\n\n @OnPrompt(\"generate\")\n async onGeneratePrompt() {\n const list = FEATURES_TYPEORM_CONNECTION_TYPES.map((item) => {\n return {\n name: item.name,\n value: item.value.type\n };\n });\n\n return [\n {\n type: \"autocomplete\",\n name: \"typeormConnection\",\n message: \"Which passport package ?\",\n when(state: any) {\n return [\"typeorm:connection\"].includes(state.type);\n },\n source: async (state: any, keyword: string) => {\n if (keyword) {\n return list.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));\n }\n\n return list;\n }\n }\n ];\n }\n\n @OnExec(\"generate\")\n onGenerateExec(ctx: TypeORMGenerateOptions): Tasks {\n if (this.providersInfoService.isMyProvider(ctx.type, TypeORMGenerateHook)) {\n ctx = this.mapOptions(ctx);\n const {typeormConnection, symbolPath} = ctx;\n const connection = FEATURES_TYPEORM_CONNECTION_TYPES.find((item) => item.value.type === typeormConnection);\n\n if (connection?.value?.dependencies) {\n this.projectPackageJson.addDependencies(connection?.value.dependencies || {});\n }\n\n const database = ctx.typeormConnection.split(\":\")[1];\n\n return [\n {\n title: `Generate TypeORM connection file to '${symbolPath}.ts'`,\n task: () => this.cliTypeORM.generateConnection(ctx.name, ctx)\n },\n {\n title: `Generate TypeORM configuration file to '${ctx.connectionName}.config.json'`,\n task: () => this.cliTypeORM.writeConfig(ctx.connectionName, database)\n },\n {\n title: \"Generate docker-compose configuration\",\n task: async () => this.cliDockerComposeYaml.addDatabaseService(ctx.name, database)\n }\n ];\n }\n\n return [];\n }\n\n private mapOptions(options: TypeORMGenerateOptions) {\n return {\n ...options,\n connectionName: paramCase(options.name).replace(\"-connection\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I,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC;aAC/E;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA3FC;IADC,iBAAM,EAAE;sCACqB,6BAAkB;+DAAC;AAGjD;IADC,iBAAM,EAAE;sCACmB,6BAAkB;6DAAC;AAG/C;IADC,iBAAM,EAAE;sCACuB,+BAAoB;iEAAC;AAcrD;IADC,mBAAQ,CAAC,UAAU,CAAC;;;;2DA0BpB;AAGD;IADC,iBAAM,CAAC,UAAU,CAAC;;;;yDAOlB;AAxDU,mBAAmB;IAD/B,eAAU,EAAE;6CAW+B,0BAAoB;GAVnD,mBAAmB,CA6F/B;AA7FY,kDAAmB","sourcesContent":["import {FEATURES_TYPEORM_CONNECTION_TYPES, GenerateCmdContext, ProvidersInfoService} from \"@tsed/cli\";\nimport {CliDockerComposeYaml, Inject, OnExec, OnPrompt, ProjectPackageJson, SrcRendererService, Tasks} from \"@tsed/cli-core\";\nimport {Injectable} from \"@tsed/di\";\nimport {TEMPLATE_DIR} from \"../utils/templateDir\";\n\nexport interface TypeORMGenerateOptions extends GenerateCmdContext {\n typeormDataSource: string;\n datasourceName: string;\n}\n\n@Injectable()\nexport class TypeORMGenerateHook {\n @Inject()\n protected projectPackageJson: ProjectPackageJson;\n\n @Inject()\n protected srcRenderService: SrcRendererService;\n\n @Inject()\n protected cliDockerComposeYaml: CliDockerComposeYaml;\n\n constructor(private providersInfoService: ProvidersInfoService) {\n providersInfoService.add(\n {\n name: \"TypeORM Datasource\",\n value: \"typeorm:datasource\",\n model: \"{{symbolName}}.datasource\"\n },\n TypeORMGenerateHook\n );\n }\n\n @OnPrompt(\"generate\")\n async onGeneratePrompt() {\n const list = FEATURES_TYPEORM_CONNECTION_TYPES.map((item) => {\n return {\n name: item.name,\n value: item.value.type\n };\n });\n\n return [\n {\n type: \"autocomplete\",\n name: \"typeormDataSource\",\n message: \"Which database type?\",\n when(state: any) {\n return state.type === \"typeorm:datasource\";\n },\n source: async (state: any, keyword: string) => {\n if (keyword) {\n return list.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));\n }\n\n return list;\n }\n }\n ];\n }\n\n @OnExec(\"generate\")\n onGenerateExec(ctx: TypeORMGenerateOptions): Tasks {\n if (this.providersInfoService.isMyProvider(ctx.type, TypeORMGenerateHook)) {\n return this.generateDataSourceTasks(ctx);\n }\n\n return [];\n }\n\n generateDataSourceTasks(ctx: TypeORMGenerateOptions) {\n const {typeormDataSource, symbolPath, name} = ctx;\n const connection = FEATURES_TYPEORM_CONNECTION_TYPES.find((item) => item.value.type === typeormDataSource);\n\n if (connection?.value?.dependencies) {\n this.projectPackageJson.addDependencies(connection?.value.dependencies || {});\n }\n\n const database = typeormDataSource.split(\":\").at(-1)!;\n\n return [\n {\n title: `Generate TypeORM connection file to '${symbolPath}.ts'`,\n task: () => {\n return this.srcRenderService.render(\n \"datasource.hbs\",\n {\n name,\n database,\n symbolName: ctx.symbolName.replace(\"Datasource\", \"DataSource\")\n },\n {\n templateDir: TEMPLATE_DIR,\n output: `${ctx.symbolPath}.ts`,\n rootDir: this.srcRenderService.rootDir\n }\n );\n }\n },\n {\n title: \"Generate docker-compose configuration\",\n task: async () => this.cliDockerComposeYaml.addDatabaseService(name, database)\n }\n ];\n }\n}\n"]}
@@ -1,16 +1,12 @@
1
1
  import { InitCmdContext } from "@tsed/cli";
2
- import { CliDockerComposeYaml, ProjectPackageJson, RootRendererService, SrcRendererService } from "@tsed/cli-core";
3
- import { CliTypeORM } from "../services/CliTypeORM";
2
+ import { CliDockerComposeYaml, CliService, ProjectPackageJson, RootRendererService, SrcRendererService } from "@tsed/cli-core";
4
3
  export declare class TypeORMInitHook {
5
- cliTypeORM: CliTypeORM;
4
+ protected cliService: CliService;
6
5
  protected packageJson: ProjectPackageJson;
7
6
  protected rootRenderer: RootRendererService;
8
7
  protected srcRenderer: SrcRendererService;
9
8
  protected cliDockerComposeYaml: CliDockerComposeYaml;
10
- onExec(ctx: InitCmdContext): {
11
- title: string;
12
- task: () => Promise<void>;
13
- }[];
9
+ onExec(ctx: InitCmdContext): Promise<any[]> | never[];
14
10
  addScripts(): void;
15
11
  addDependencies(ctx: InitCmdContext): void;
16
12
  addDevDependencies(ctx: InitCmdContext): void;
@@ -4,7 +4,7 @@ exports.TypeORMInitHook = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const cli_core_1 = require("@tsed/cli-core");
6
6
  const di_1 = require("@tsed/di");
7
- const CliTypeORM_1 = require("../services/CliTypeORM");
7
+ const change_case_1 = require("change-case");
8
8
  function getDatabase(ctx) {
9
9
  var _a;
10
10
  return ((_a = ctx.features.find(({ type }) => type.includes("typeorm:"))) === null || _a === void 0 ? void 0 : _a.type.split(":")[1]) || "";
@@ -18,27 +18,15 @@ let TypeORMInitHook = class TypeORMInitHook {
18
18
  if (!database) {
19
19
  return [];
20
20
  }
21
- return [
22
- {
23
- title: `Generate TypeORM connection file`,
24
- task: async () => this.cliTypeORM.generateConnection("default", {
25
- symbolPath: "DefaultConnection",
26
- symbolName: "DefaultConnection"
27
- })
28
- },
29
- {
30
- title: "Generate TypeORM configuration",
31
- task: async () => this.cliTypeORM.writeConfig("default", database)
32
- },
33
- {
34
- title: "Generate docker-compose configuration",
35
- task: async () => this.cliDockerComposeYaml.addDatabaseService(database, database)
36
- }
37
- ];
21
+ return this.cliService.getTasks("generate", {
22
+ ...ctx,
23
+ type: "typeorm:dataSource",
24
+ name: change_case_1.pascalCase(database)
25
+ });
38
26
  }
39
27
  addScripts() {
40
28
  this.packageJson.addScripts({
41
- typeorm: "tsed typeorm"
29
+ typeorm: "typeorm-ts-node-commonjs"
42
30
  });
43
31
  }
44
32
  addDependencies(ctx) {
@@ -50,8 +38,8 @@ let TypeORMInitHook = class TypeORMInitHook {
50
38
  };
51
39
  tslib_1.__decorate([
52
40
  cli_core_1.Inject(),
53
- tslib_1.__metadata("design:type", CliTypeORM_1.CliTypeORM)
54
- ], TypeORMInitHook.prototype, "cliTypeORM", void 0);
41
+ tslib_1.__metadata("design:type", cli_core_1.CliService)
42
+ ], TypeORMInitHook.prototype, "cliService", void 0);
55
43
  tslib_1.__decorate([
56
44
  cli_core_1.Inject(),
57
45
  tslib_1.__metadata("design:type", cli_core_1.ProjectPackageJson)
@@ -1 +1 @@
1
- {"version":3,"file":"TypeORMInitHook.js","sourceRoot":"","sources":["../../src/hooks/TypeORMInitHook.ts"],"names":[],"mappings":";;;;AACA,6CAAiI;AACjI,iCAAoC;AACpC,uDAAkD;AAElD,SAAS,WAAW,CAAC,GAAmB;;IACtC,OAAO,CAAA,MAAA,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAC,IAAI,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,0CAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,KAAI,EAAE,CAAC;AAC5F,CAAC;AAGD,IAAa,eAAe,GAA5B,MAAa,eAAe;IAiB1B,MAAM,CAAC,GAAmB;QACxB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAE7B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,EAAE,CAAC;SACX;QAED,OAAO;YACL;gBACE,KAAK,EAAE,kCAAkC;gBACzC,IAAI,EAAE,KAAK,IAAI,EAAE,CACf,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,SAAS,EAAE;oBAC5C,UAAU,EAAE,mBAAmB;oBAC/B,UAAU,EAAE,mBAAmB;iBAChC,CAAC;aACL;YACD;gBACE,KAAK,EAAE,gCAAgC;gBACvC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC;aACnE;YACD;gBACE,KAAK,EAAE,uCAAuC;gBAC9C,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC;aACnF;SACF,CAAC;IACJ,CAAC;IAED,UAAU;QACR,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC;YAC1B,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,GAAmB;QACjC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC;IAED,kBAAkB,CAAC,GAAmB;QACpC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;CACF,CAAA;AA3DC;IADC,iBAAM,EAAE;sCACG,uBAAU;mDAAC;AAGvB;IADC,iBAAM,EAAE;sCACc,6BAAkB;oDAAC;AAG1C;IADC,iBAAM,EAAE;sCACe,8BAAmB;qDAAC;AAG5C;IADC,iBAAM,EAAE;sCACc,6BAAkB;oDAAC;AAG1C;IADC,iBAAM,EAAE;sCACuB,+BAAoB;6DAAC;AAGrD;IADC,iBAAM,CAAC,MAAM,CAAC;;;;6CA8Bd;AA9CU,eAAe;IAD3B,eAAU,EAAE;GACA,eAAe,CA6D3B;AA7DY,0CAAe","sourcesContent":["import {InitCmdContext} from \"@tsed/cli\";\nimport {CliDockerComposeYaml, Inject, OnExec, ProjectPackageJson, RootRendererService, SrcRendererService} from \"@tsed/cli-core\";\nimport {Injectable} from \"@tsed/di\";\nimport {CliTypeORM} from \"../services/CliTypeORM\";\n\nfunction getDatabase(ctx: InitCmdContext) {\n return ctx.features.find(({type}) => type.includes(\"typeorm:\"))?.type.split(\":\")[1] || \"\";\n}\n\n@Injectable()\nexport class TypeORMInitHook {\n @Inject()\n cliTypeORM: CliTypeORM;\n\n @Inject()\n protected packageJson: ProjectPackageJson;\n\n @Inject()\n protected rootRenderer: RootRendererService;\n\n @Inject()\n protected srcRenderer: SrcRendererService;\n\n @Inject()\n protected cliDockerComposeYaml: CliDockerComposeYaml;\n\n @OnExec(\"init\")\n onExec(ctx: InitCmdContext) {\n this.addScripts();\n this.addDependencies(ctx);\n this.addDevDependencies(ctx);\n\n const database = getDatabase(ctx);\n\n if (!database) {\n return [];\n }\n\n return [\n {\n title: `Generate TypeORM connection file`,\n task: async () =>\n this.cliTypeORM.generateConnection(\"default\", {\n symbolPath: \"DefaultConnection\",\n symbolName: \"DefaultConnection\"\n })\n },\n {\n title: \"Generate TypeORM configuration\",\n task: async () => this.cliTypeORM.writeConfig(\"default\", database)\n },\n {\n title: \"Generate docker-compose configuration\",\n task: async () => this.cliDockerComposeYaml.addDatabaseService(database, database)\n }\n ];\n }\n\n addScripts() {\n this.packageJson.addScripts({\n typeorm: \"tsed typeorm\"\n });\n }\n\n addDependencies(ctx: InitCmdContext) {\n this.packageJson.addDependencies({}, ctx);\n }\n\n addDevDependencies(ctx: InitCmdContext) {\n this.packageJson.addDevDependencies({}, ctx);\n }\n}\n"]}
1
+ {"version":3,"file":"TypeORMInitHook.js","sourceRoot":"","sources":["../../src/hooks/TypeORMInitHook.ts"],"names":[],"mappings":";;;;AACA,6CAQwB;AACxB,iCAAoC;AACpC,6CAAuC;AAEvC,SAAS,WAAW,CAAC,GAAmB;;IACtC,OAAO,CAAA,MAAA,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAC,IAAI,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,0CAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,KAAI,EAAE,CAAC;AAC5F,CAAC;AAGD,IAAa,eAAe,GAA5B,MAAa,eAAe;IAiB1B,MAAM,CAAC,GAAmB;QACxB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAE7B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,EAAE,CAAC;SACX;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,EAAE;YAC1C,GAAG,GAAG;YACN,IAAI,EAAE,oBAAoB;YAC1B,IAAI,EAAE,wBAAU,CAAC,QAAQ,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,UAAU;QACR,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC;YAC1B,OAAO,EAAE,0BAA0B;SACpC,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,GAAmB;QACjC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC;IAED,kBAAkB,CAAC,GAAmB;QACpC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;CACF,CAAA;AA9CC;IADC,iBAAM,EAAE;sCACa,qBAAU;mDAAC;AAGjC;IADC,iBAAM,EAAE;sCACc,6BAAkB;oDAAC;AAG1C;IADC,iBAAM,EAAE;sCACe,8BAAmB;qDAAC;AAG5C;IADC,iBAAM,EAAE;sCACc,6BAAkB;oDAAC;AAG1C;IADC,iBAAM,EAAE;sCACuB,+BAAoB;6DAAC;AAGrD;IADC,iBAAM,CAAC,MAAM,CAAC;;;;6CAiBd;AAjCU,eAAe;IAD3B,eAAU,EAAE;GACA,eAAe,CAgD3B;AAhDY,0CAAe","sourcesContent":["import {InitCmdContext} from \"@tsed/cli\";\nimport {\n CliDockerComposeYaml,\n CliService,\n Inject,\n OnExec,\n ProjectPackageJson,\n RootRendererService,\n SrcRendererService\n} from \"@tsed/cli-core\";\nimport {Injectable} from \"@tsed/di\";\nimport {pascalCase} from \"change-case\";\n\nfunction getDatabase(ctx: InitCmdContext) {\n return ctx.features.find(({type}) => type.includes(\"typeorm:\"))?.type.split(\":\")[1] || \"\";\n}\n\n@Injectable()\nexport class TypeORMInitHook {\n @Inject()\n protected cliService: CliService;\n\n @Inject()\n protected packageJson: ProjectPackageJson;\n\n @Inject()\n protected rootRenderer: RootRendererService;\n\n @Inject()\n protected srcRenderer: SrcRendererService;\n\n @Inject()\n protected cliDockerComposeYaml: CliDockerComposeYaml;\n\n @OnExec(\"init\")\n onExec(ctx: InitCmdContext) {\n this.addScripts();\n this.addDependencies(ctx);\n this.addDevDependencies(ctx);\n\n const database = getDatabase(ctx);\n\n if (!database) {\n return [];\n }\n\n return this.cliService.getTasks(\"generate\", {\n ...ctx,\n type: \"typeorm:dataSource\",\n name: pascalCase(database)\n });\n }\n\n addScripts() {\n this.packageJson.addScripts({\n typeorm: \"typeorm-ts-node-commonjs\"\n });\n }\n\n addDependencies(ctx: InitCmdContext) {\n this.packageJson.addDependencies({}, ctx);\n }\n\n addDevDependencies(ctx: InitCmdContext) {\n this.packageJson.addDevDependencies({}, ctx);\n }\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { CliPluginTypeORMModule } from "./CliPluginTypeORMModule";
2
2
  export * from "./hooks/TypeORMInitHook";
3
3
  export * from "./hooks/TypeORMGenerateHook";
4
- export * from "./services/CliTypeORM";
5
4
  export default CliPluginTypeORMModule;
package/lib/index.js CHANGED
@@ -4,6 +4,5 @@ const tslib_1 = require("tslib");
4
4
  const CliPluginTypeORMModule_1 = require("./CliPluginTypeORMModule");
5
5
  tslib_1.__exportStar(require("./hooks/TypeORMInitHook"), exports);
6
6
  tslib_1.__exportStar(require("./hooks/TypeORMGenerateHook"), exports);
7
- tslib_1.__exportStar(require("./services/CliTypeORM"), exports);
8
7
  exports.default = CliPluginTypeORMModule_1.CliPluginTypeORMModule;
9
8
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAgE;AAEhE,kEAAwC;AACxC,sEAA4C;AAC5C,gEAAsC;AAEtC,kBAAe,+CAAsB,CAAC","sourcesContent":["import {CliPluginTypeORMModule} from \"./CliPluginTypeORMModule\";\n\nexport * from \"./hooks/TypeORMInitHook\";\nexport * from \"./hooks/TypeORMGenerateHook\";\nexport * from \"./services/CliTypeORM\";\n\nexport default CliPluginTypeORMModule;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAgE;AAEhE,kEAAwC;AACxC,sEAA4C;AAE5C,kBAAe,+CAAsB,CAAC","sourcesContent":["import {CliPluginTypeORMModule} from \"./CliPluginTypeORMModule\";\n\nexport * from \"./hooks/TypeORMInitHook\";\nexport * from \"./hooks/TypeORMGenerateHook\";\n\nexport default CliPluginTypeORMModule;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/cli-plugin-typeorm",
3
- "version": "3.19.5",
3
+ "version": "3.20.1",
4
4
  "main": "./lib/index.js",
5
5
  "typings": "./lib/index.d.ts",
6
6
  "description": "Ts.ED CLI plugin. Add TypeORM support",
@@ -9,8 +9,8 @@
9
9
  "tslib": "2.3.1"
10
10
  },
11
11
  "devDependencies": {
12
- "@tsed/cli": "3.19.5",
13
- "@tsed/cli-core": "3.19.5"
12
+ "@tsed/cli": "3.20.1",
13
+ "@tsed/cli-core": "3.20.1"
14
14
  },
15
15
  "scripts": {
16
16
  "build": "tsc --build tsconfig.compile.json",
@@ -0,0 +1,78 @@
1
+ import {Configuration, registerProvider} from "@tsed/di";
2
+ import {createConnection} from "@tsed/typeorm";
3
+ import {DataSource} from "typeorm";
4
+ import {Logger} from "@tsed/logger";
5
+
6
+ export const {{symbolName}} = new DataSource({
7
+ type: "{{database}}",
8
+ {{#switch database}}
9
+ {{#case 'mysql'}}
10
+ host: "localhost",
11
+ port: 3306,
12
+ username: "test",
13
+ password: "test",
14
+ database: "test"
15
+ {{/case}}
16
+ {{#case 'mariadb'}}
17
+ host: "localhost",
18
+ port: 3306,
19
+ username: "test",
20
+ password: "test",
21
+ database: "test"
22
+ {{/case}}
23
+ {{#case 'sqlite'}}
24
+ database: "database.sqlite"
25
+ {{/case}}
26
+ {{#case 'better-sqlite3'}}
27
+ database: "database.sqlite"
28
+ {{/case}}
29
+ {{#case 'postgres'}}
30
+ host: "localhost",
31
+ port: 5432,
32
+ username: "test",
33
+ password: "test",
34
+ database: "test"
35
+ {{/case}}
36
+ {{#case 'cockroachdb'}}
37
+ host: "localhost",
38
+ port: 26257,
39
+ username: "root",
40
+ password: "",
41
+ database: "defaultdb"
42
+ {{/case}}
43
+ {{#case 'mssql'}}
44
+ host: "localhost",
45
+ username: "sa",
46
+ password: "Admin12345",
47
+ database: "tempdb"
48
+ {{/case}}
49
+ {{#case 'oracle'}}
50
+ host: "localhost",
51
+ username: "system",
52
+ password: "oracle",
53
+ port: 1521,
54
+ sid: "xe.oracle.docker"
55
+ {{/case}}
56
+ {{#case 'mongodb'}}
57
+ database: "test"
58
+ {{/case}}
59
+ {{/switch}}
60
+ });
61
+
62
+ registerProvider<DataSource>({
63
+ provide: {{symbolName}},
64
+ type: "typeorm:datasource",
65
+ deps: [Logger],
66
+ async useAsyncFactory(logger: Logger) {
67
+ await {{symbolName}}.initialize();
68
+
69
+ logger.info('Connected with typeorm to database: {{name}}');
70
+
71
+ return {{symbolName}};
72
+ },
73
+ hooks: {
74
+ $onDestroy(dataSource) {
75
+ return dataSource.isInitialized && dataSource.close();
76
+ }
77
+ }
78
+ });
@@ -1,12 +0,0 @@
1
- import { CliDefaultOptions, CommandProvider } from "@tsed/cli-core";
2
- import { CliTypeORM } from "../services/CliTypeORM";
3
- export interface TypeORMContext extends CliDefaultOptions {
4
- command: string;
5
- }
6
- export declare class TypeORMCmd implements CommandProvider {
7
- cliTypeORM: CliTypeORM;
8
- $exec(ctx: TypeORMContext): Promise<{
9
- title: string;
10
- task: () => any;
11
- }[]>;
12
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeORMCmd = void 0;
4
- const tslib_1 = require("tslib");
5
- const cli_core_1 = require("@tsed/cli-core");
6
- const CliTypeORM_1 = require("../services/CliTypeORM");
7
- let TypeORMCmd = class TypeORMCmd {
8
- async $exec(ctx) {
9
- return [
10
- {
11
- title: `Run TypeORM CLI ${ctx.command}`,
12
- task: () => this.cliTypeORM.run(ctx.command, ctx.rawArgs)
13
- }
14
- ];
15
- }
16
- };
17
- tslib_1.__decorate([
18
- cli_core_1.Inject(),
19
- tslib_1.__metadata("design:type", CliTypeORM_1.CliTypeORM)
20
- ], TypeORMCmd.prototype, "cliTypeORM", void 0);
21
- TypeORMCmd = tslib_1.__decorate([
22
- cli_core_1.Command({
23
- name: "typeorm",
24
- description: "Run a typeorm command",
25
- args: {
26
- command: {
27
- description: "The typeorm command",
28
- type: String,
29
- required: true
30
- }
31
- },
32
- options: {},
33
- allowUnknownOption: true
34
- })
35
- ], TypeORMCmd);
36
- exports.TypeORMCmd = TypeORMCmd;
37
- //# sourceMappingURL=TypeORMCmd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypeORMCmd.js","sourceRoot":"","sources":["../../src/commands/TypeORMCmd.ts"],"names":[],"mappings":";;;;AAAA,6CAAmF;AACnF,uDAAkD;AAmBlD,IAAa,UAAU,GAAvB,MAAa,UAAU;IAIrB,KAAK,CAAC,KAAK,CAAC,GAAmB;QAC7B,OAAO;YACL;gBACE,KAAK,EAAE,mBAAmB,GAAG,CAAC,OAAO,EAAE;gBACvC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC;aAC1D;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAVC;IADC,iBAAM,EAAE;sCACG,uBAAU;8CAAC;AAFZ,UAAU;IAbtB,kBAAO,CAAC;QACP,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,uBAAuB;QACpC,IAAI,EAAE;YACJ,OAAO,EAAE;gBACP,WAAW,EAAE,qBAAqB;gBAClC,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,IAAI;aACf;SACF;QACD,OAAO,EAAE,EAAE;QACX,kBAAkB,EAAE,IAAI;KACzB,CAAC;GACW,UAAU,CAYtB;AAZY,gCAAU","sourcesContent":["import {Command, CliDefaultOptions, CommandProvider, Inject} from \"@tsed/cli-core\";\nimport {CliTypeORM} from \"../services/CliTypeORM\";\n\nexport interface TypeORMContext extends CliDefaultOptions {\n command: string;\n}\n\n@Command({\n name: \"typeorm\",\n description: \"Run a typeorm command\",\n args: {\n command: {\n description: \"The typeorm command\",\n type: String,\n required: true\n }\n },\n options: {},\n allowUnknownOption: true\n})\nexport class TypeORMCmd implements CommandProvider {\n @Inject()\n cliTypeORM: CliTypeORM;\n\n async $exec(ctx: TypeORMContext) {\n return [\n {\n title: `Run TypeORM CLI ${ctx.command}`,\n task: () => this.cliTypeORM.run(ctx.command, ctx.rawArgs)\n }\n ];\n }\n}\n"]}
@@ -1,10 +0,0 @@
1
- import { CliExeca, ProjectPackageJson, SrcRendererService } from "@tsed/cli-core";
2
- export declare class CliTypeORM {
3
- cliExeca: CliExeca;
4
- projectPackageJson: ProjectPackageJson;
5
- protected srcRenderer: SrcRendererService;
6
- run(command: string, args: string[], options?: any): any;
7
- generateConnection(name: string, options?: any): Promise<void>;
8
- writeConfig(name: string, database: string): Promise<void>;
9
- regenerateIndexConfig(): Promise<void>;
10
- }
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CliTypeORM = void 0;
4
- const tslib_1 = require("tslib");
5
- const cli_core_1 = require("@tsed/cli-core");
6
- const di_1 = require("@tsed/di");
7
- const change_case_1 = require("change-case");
8
- const path_1 = require("path");
9
- const templateDir_1 = require("../utils/templateDir");
10
- let CliTypeORM = class CliTypeORM {
11
- run(command, args, options = {}) {
12
- return this.cliExeca.run("npx", ["typeorm", command, ...args], {
13
- ...options,
14
- cwd: this.projectPackageJson.dir
15
- });
16
- }
17
- async generateConnection(name, options = {}) {
18
- return this.srcRenderer.render("connection.hbs", {
19
- ...options,
20
- symbolName: change_case_1.constantCase(options.symbolName),
21
- connectionName: name
22
- }, {
23
- templateDir: templateDir_1.TEMPLATE_DIR,
24
- output: `${options.symbolPath}.ts`,
25
- rootDir: path_1.join(this.srcRenderer.rootDir, "services", "connections")
26
- });
27
- }
28
- async writeConfig(name, database) {
29
- var _a, _b, _c;
30
- const { InitCommand } = await this.projectPackageJson.importModule("typeorm/commands/InitCommand.js");
31
- const content = {
32
- name,
33
- ...JSON.parse(await InitCommand.getOrmConfigTemplate(database))
34
- };
35
- function replace(path) {
36
- return path && path.replace("src/", "${rootDir}/").replace(/\.ts/, ".{js,ts}");
37
- }
38
- content.entities = (_a = content.entities) === null || _a === void 0 ? void 0 : _a.map(replace);
39
- content.migrations = (_b = content.migrations) === null || _b === void 0 ? void 0 : _b.map(replace);
40
- content.subscribers = (_c = content.subscribers) === null || _c === void 0 ? void 0 : _c.map(replace);
41
- if (content.cli) {
42
- content.cli.entitiesDir = replace(content.cli.entitiesDir);
43
- content.cli.migrationsDir = replace(content.cli.migrationsDir);
44
- content.cli.subscribersDir = replace(content.cli.subscribersDir);
45
- }
46
- await this.srcRenderer.write(JSON.stringify(content, null, 2), { output: `config/typeorm/${name}.config.json` });
47
- return this.regenerateIndexConfig();
48
- }
49
- async regenerateIndexConfig() {
50
- const list = await this.srcRenderer.scan(["config/typeorm/*.config.json"]);
51
- const configs = list.map((file) => {
52
- const name = path_1.basename(file).replace(/\.config\.json/gi, "");
53
- return {
54
- name,
55
- symbolName: change_case_1.camelCase(name)
56
- };
57
- });
58
- return this.srcRenderer.render("index.hbs", {
59
- configs
60
- }, {
61
- templateDir: templateDir_1.TEMPLATE_DIR,
62
- output: "index.ts",
63
- rootDir: path_1.join(this.srcRenderer.rootDir, "config", "typeorm")
64
- });
65
- }
66
- };
67
- tslib_1.__decorate([
68
- cli_core_1.Inject(),
69
- tslib_1.__metadata("design:type", cli_core_1.CliExeca)
70
- ], CliTypeORM.prototype, "cliExeca", void 0);
71
- tslib_1.__decorate([
72
- cli_core_1.Inject(),
73
- tslib_1.__metadata("design:type", cli_core_1.ProjectPackageJson)
74
- ], CliTypeORM.prototype, "projectPackageJson", void 0);
75
- tslib_1.__decorate([
76
- cli_core_1.Inject(),
77
- tslib_1.__metadata("design:type", cli_core_1.SrcRendererService)
78
- ], CliTypeORM.prototype, "srcRenderer", void 0);
79
- CliTypeORM = tslib_1.__decorate([
80
- di_1.Injectable()
81
- ], CliTypeORM);
82
- exports.CliTypeORM = CliTypeORM;
83
- //# sourceMappingURL=CliTypeORM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CliTypeORM.js","sourceRoot":"","sources":["../../src/services/CliTypeORM.ts"],"names":[],"mappings":";;;;AAAA,6CAAwF;AACxF,iCAAoC;AACpC,6CAAoD;AACpD,+BAAoC;AACpC,sDAAkD;AAGlD,IAAa,UAAU,GAAvB,MAAa,UAAU;IAUrB,GAAG,CAAC,OAAe,EAAE,IAAc,EAAE,UAAe,EAAE;QACpD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,EAAE;YAC7D,GAAG,OAAO;YACV,GAAG,EAAE,IAAI,CAAC,kBAAkB,CAAC,GAAG;SACjC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,IAAY,EAAE,UAAe,EAAE;QACtD,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAC5B,gBAAgB,EAChB;YACE,GAAG,OAAO;YACV,UAAU,EAA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endererService} from \"@tsed/cli-core\";\nimport {Injectable} from \"@tsed/di\";\nimport {camelCase, constantCase} from \"change-case\";\nimport {basename, join} from \"path\";\nimport {TEMPLATE_DIR} from \"../utils/templateDir\";\n\n@Injectable()\nexport class CliTypeORM {\n @Inject()\n cliExeca: CliExeca;\n\n @Inject()\n projectPackageJson: ProjectPackageJson;\n\n @Inject()\n protected srcRenderer: SrcRendererService;\n\n run(command: string, args: string[], options: any = {}) {\n return this.cliExeca.run(\"npx\", [\"typeorm\", command, ...args], {\n ...options,\n cwd: this.projectPackageJson.dir\n });\n }\n\n async generateConnection(name: string, options: any = {}) {\n return this.srcRenderer.render(\n \"connection.hbs\",\n {\n ...options,\n symbolName: constantCase(options.symbolName),\n connectionName: name\n },\n {\n templateDir: TEMPLATE_DIR,\n output: `${options.symbolPath}.ts`,\n rootDir: join(this.srcRenderer.rootDir, \"services\", \"connections\")\n }\n );\n }\n\n async writeConfig(name: string, database: string) {\n const {InitCommand} = await this.projectPackageJson.importModule(\"typeorm/commands/InitCommand.js\");\n\n const content = {\n name,\n ...JSON.parse(await InitCommand.getOrmConfigTemplate(database))\n };\n\n function replace(path: string | undefined) {\n return path && path.replace(\"src/\", \"${rootDir}/\").replace(/\\.ts/, \".{js,ts}\");\n }\n\n content.entities = content.entities?.map(replace);\n content.migrations = content.migrations?.map(replace);\n content.subscribers = content.subscribers?.map(replace);\n\n if (content.cli) {\n content.cli.entitiesDir = replace(content.cli.entitiesDir);\n content.cli.migrationsDir = replace(content.cli.migrationsDir);\n content.cli.subscribersDir = replace(content.cli.subscribersDir);\n }\n\n await this.srcRenderer.write(JSON.stringify(content, null, 2), {output: `config/typeorm/${name}.config.json`});\n\n return this.regenerateIndexConfig();\n }\n\n async regenerateIndexConfig() {\n const list = await this.srcRenderer.scan([\"config/typeorm/*.config.json\"]);\n\n const configs = list.map((file: string) => {\n const name = basename(file).replace(/\\.config\\.json/gi, \"\");\n\n return {\n name,\n symbolName: camelCase(name)\n };\n });\n\n return this.srcRenderer.render(\n \"index.hbs\",\n {\n configs\n },\n {\n templateDir: TEMPLATE_DIR,\n output: \"index.ts\",\n rootDir: join(this.srcRenderer.rootDir, \"config\", \"typeorm\")\n }\n );\n }\n}\n"]}
@@ -1,17 +0,0 @@
1
- import {Configuration, registerProvider} from "@tsed/di";
2
- import {createConnection} from "@tsed/typeorm";
3
- import {Connection, ConnectionOptions} from "typeorm";
4
-
5
- export const {{symbolName}} = Symbol.for("{{symbolName}}");
6
- export type {{symbolName}} = Connection;
7
-
8
- registerProvider({
9
- provide: {{symbolName}},
10
- deps: [Configuration],
11
- async useAsyncFactory(configuration: Configuration) {
12
- const settings = configuration.get<ConnectionOptions[]>("typeorm")!;
13
- const connectionOptions = settings.find(o => o.name === "{{connectionName}}");
14
-
15
- return createConnection(connectionOptions!);
16
- }
17
- });
@@ -1,10 +0,0 @@
1
- // @tsed/cli do not edit
2
- {{#forEach configs}}
3
- import * as {{symbolName}}Config from "./{{name}}.config.json";
4
- {{/forEach}}
5
-
6
- export default [
7
- {{#forEach configs}}
8
- {{symbolName}}Config as any{{#unless isLast}}, {{/unless}}
9
- {{/forEach}}
10
- ];