@tsed/cli-plugin-typeorm 6.6.3 → 7.0.0-alpha.10
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/lib/esm/CliPluginTypeORMModule.js +12 -20
- package/lib/esm/hooks/TypeORMGenerateHook.js +23 -96
- package/lib/esm/hooks/TypeORMInitHook.js +36 -39
- package/lib/esm/index.js +1 -1
- package/lib/esm/templates/datasource.template.js +111 -0
- package/lib/esm/utils/getTypeORMDatabases.js +7 -0
- package/lib/types/CliPluginTypeORMModule.d.ts +3 -2
- package/lib/types/hooks/TypeORMGenerateHook.d.ts +4 -26
- package/lib/types/hooks/TypeORMInitHook.d.ts +6 -8
- package/lib/types/index.d.ts +1 -1
- package/lib/types/templates/datasource.template.d.ts +25 -0
- package/lib/types/utils/getTypeORMDatabases.d.ts +4 -0
- package/package.json +8 -5
- package/lib/esm/utils/templateDir.js +0 -2
- package/lib/types/utils/templateDir.d.ts +0 -1
- package/templates/datasource.hbs +0 -81
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { inject, ProjectPackageJson } from "@tsed/cli-core";
|
|
2
|
+
import { injectable } from "@tsed/di";
|
|
3
3
|
import { TypeORMGenerateHook } from "./hooks/TypeORMGenerateHook.js";
|
|
4
4
|
import { TypeORMInitHook } from "./hooks/TypeORMInitHook.js";
|
|
5
|
-
|
|
5
|
+
export class CliPluginTypeORMModule {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.packageJson = inject(ProjectPackageJson);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
$alterPackageJson(packageJson, data) {
|
|
10
|
+
if (data.typeorm) {
|
|
11
|
+
packageJson.addDependencies({
|
|
12
|
+
typeorm: "latest"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return packageJson;
|
|
13
16
|
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
OnAdd("@tsed/cli-plugin-typeorm"),
|
|
17
|
-
__metadata("design:type", Function),
|
|
18
|
-
__metadata("design:paramtypes", []),
|
|
19
|
-
__metadata("design:returntype", void 0)
|
|
20
|
-
], CliPluginTypeORMModule.prototype, "install", null);
|
|
21
|
-
CliPluginTypeORMModule = __decorate([
|
|
22
|
-
Module({
|
|
23
|
-
imports: [TypeORMInitHook, TypeORMGenerateHook]
|
|
24
|
-
})
|
|
25
|
-
], CliPluginTypeORMModule);
|
|
26
|
-
export { CliPluginTypeORMModule };
|
|
17
|
+
}
|
|
18
|
+
injectable(CliPluginTypeORMModule).imports([TypeORMInitHook, TypeORMGenerateHook]);
|
|
@@ -1,107 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { TEMPLATE_DIR } from "../utils/templateDir.js";
|
|
8
|
-
let TypeORMGenerateHook = TypeORMGenerateHook_1 = class TypeORMGenerateHook {
|
|
9
|
-
constructor(providersInfoService) {
|
|
10
|
-
this.providersInfoService = providersInfoService;
|
|
1
|
+
import {} from "@tsed/cli";
|
|
2
|
+
import { CliDockerComposeYaml, ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
+
import { inject, injectable } from "@tsed/di";
|
|
4
|
+
import { getDatabase, getTypeORMDatabases } from "../utils/getTypeORMDatabases.js";
|
|
5
|
+
export class TypeORMGenerateHook {
|
|
6
|
+
constructor() {
|
|
11
7
|
this.projectPackageJson = inject(ProjectPackageJson);
|
|
12
|
-
this.srcRenderService = inject(SrcRendererService);
|
|
13
8
|
this.cliDockerComposeYaml = inject(CliDockerComposeYaml);
|
|
14
|
-
providersInfoService.add({
|
|
15
|
-
name: "TypeORM Datasource",
|
|
16
|
-
value: "typeorm:datasource",
|
|
17
|
-
model: "{{symbolName}}.datasource"
|
|
18
|
-
}, TypeORMGenerateHook_1);
|
|
19
9
|
}
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
value
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
type: "autocomplete",
|
|
30
|
-
name: "typeormDataSource",
|
|
31
|
-
message: "Which database type?",
|
|
32
|
-
when(state) {
|
|
33
|
-
return state.type === "typeorm:datasource";
|
|
34
|
-
},
|
|
35
|
-
source: (state, keyword) => {
|
|
36
|
-
if (keyword) {
|
|
37
|
-
return list.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
|
|
38
|
-
}
|
|
39
|
-
return list;
|
|
10
|
+
$alterGenerateTasks(tasks, data) {
|
|
11
|
+
const { typeormDataSource, name } = data;
|
|
12
|
+
if (typeormDataSource) {
|
|
13
|
+
getTypeORMDatabases()
|
|
14
|
+
.filter(([value]) => value === typeormDataSource)
|
|
15
|
+
.forEach(([, feature]) => {
|
|
16
|
+
if (feature.dependencies) {
|
|
17
|
+
this.projectPackageJson.addDependencies(feature.dependencies);
|
|
40
18
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (this.providersInfoService.isMyProvider(ctx.type, TypeORMGenerateHook_1)) {
|
|
46
|
-
return this.generateDataSourceTasks(ctx);
|
|
47
|
-
}
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
getTypeORMTypes() {
|
|
51
|
-
return Object.entries(FeaturesMap).filter(([value]) => value.startsWith("typeorm:"));
|
|
52
|
-
}
|
|
53
|
-
generateDataSourceTasks(ctx) {
|
|
54
|
-
const { typeormDataSource, symbolPath, name } = ctx;
|
|
55
|
-
if (!typeormDataSource) {
|
|
56
|
-
return [];
|
|
19
|
+
if (feature.devDependencies) {
|
|
20
|
+
this.projectPackageJson.addDependencies(feature.devDependencies);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
57
23
|
}
|
|
58
|
-
this.getTypeORMTypes()
|
|
59
|
-
.filter(([value]) => value === typeormDataSource)
|
|
60
|
-
.forEach(([, feature]) => {
|
|
61
|
-
if (feature.dependencies) {
|
|
62
|
-
this.projectPackageJson.addDependencies(feature.dependencies);
|
|
63
|
-
}
|
|
64
|
-
if (feature.devDependencies) {
|
|
65
|
-
this.projectPackageJson.addDependencies(feature.devDependencies);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
const database = typeormDataSource.split(":").at(-1);
|
|
69
|
-
const symbolName = ctx.symbolName;
|
|
70
24
|
return [
|
|
71
|
-
|
|
72
|
-
title: `Generate TypeORM datasource file to '${symbolPath}.ts'`,
|
|
73
|
-
task: () => this.srcRenderService.render("datasource.hbs", {
|
|
74
|
-
name,
|
|
75
|
-
database,
|
|
76
|
-
symbolName,
|
|
77
|
-
instanceName: camelCase(symbolName)
|
|
78
|
-
}, {
|
|
79
|
-
templateDir: TEMPLATE_DIR,
|
|
80
|
-
output: `${ctx.symbolPath}.ts`,
|
|
81
|
-
rootDir: this.srcRenderService.rootDir
|
|
82
|
-
})
|
|
83
|
-
},
|
|
25
|
+
...tasks,
|
|
84
26
|
{
|
|
85
27
|
title: "Generate docker-compose configuration",
|
|
86
|
-
|
|
28
|
+
enabled: () => !!typeormDataSource,
|
|
29
|
+
task: () => this.cliDockerComposeYaml.addDatabaseService(name, getDatabase(data))
|
|
87
30
|
}
|
|
88
31
|
];
|
|
89
32
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
OnPrompt("generate"),
|
|
93
|
-
__metadata("design:type", Function),
|
|
94
|
-
__metadata("design:paramtypes", []),
|
|
95
|
-
__metadata("design:returntype", void 0)
|
|
96
|
-
], TypeORMGenerateHook.prototype, "onGeneratePrompt", null);
|
|
97
|
-
__decorate([
|
|
98
|
-
OnExec("generate"),
|
|
99
|
-
__metadata("design:type", Function),
|
|
100
|
-
__metadata("design:paramtypes", [Object]),
|
|
101
|
-
__metadata("design:returntype", Array)
|
|
102
|
-
], TypeORMGenerateHook.prototype, "onGenerateExec", null);
|
|
103
|
-
TypeORMGenerateHook = TypeORMGenerateHook_1 = __decorate([
|
|
104
|
-
Injectable(),
|
|
105
|
-
__metadata("design:paramtypes", [ProvidersInfoService])
|
|
106
|
-
], TypeORMGenerateHook);
|
|
107
|
-
export { TypeORMGenerateHook };
|
|
33
|
+
}
|
|
34
|
+
injectable(TypeORMGenerateHook);
|
|
@@ -1,49 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CliService, inject,
|
|
3
|
-
import {
|
|
1
|
+
import { ProjectClient } from "@tsed/cli";
|
|
2
|
+
import { CliService, inject, ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
+
import { injectable } from "@tsed/di";
|
|
4
4
|
import { pascalCase } from "change-case";
|
|
5
5
|
function getDatabase(ctx) {
|
|
6
|
-
return ctx.features
|
|
6
|
+
return ctx.features?.find((type) => type.includes("typeorm:"))?.split(":")[1];
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
export class TypeORMInitHook {
|
|
9
9
|
constructor() {
|
|
10
10
|
this.cliService = inject(CliService);
|
|
11
|
-
this.packageJson = inject(ProjectPackageJson);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (!database) {
|
|
19
|
-
return [];
|
|
12
|
+
$alterPackageJson(packageJson, data) {
|
|
13
|
+
if (data.typeorm) {
|
|
14
|
+
packageJson.addScripts({
|
|
15
|
+
typeorm: "typeorm-ts-node-commonjs"
|
|
16
|
+
});
|
|
20
17
|
}
|
|
21
|
-
return
|
|
22
|
-
...ctx,
|
|
23
|
-
type: "typeorm:dataSource",
|
|
24
|
-
name: pascalCase(database),
|
|
25
|
-
typeormDataSource: ctx.features.find((value) => value.startsWith("typeorm:"))
|
|
26
|
-
});
|
|
18
|
+
return packageJson;
|
|
27
19
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
$alterProjectFiles(project, data) {
|
|
21
|
+
if (data.typeorm) {
|
|
22
|
+
//set that in config.ts
|
|
23
|
+
project.serverSourceFile?.addImportDeclaration({
|
|
24
|
+
moduleSpecifier: "@tsed/typeorm"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return project;
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
async $alterInitSubTasks(tasks, data) {
|
|
30
|
+
const database = getDatabase(data);
|
|
31
|
+
if (!database || !data.typeorm) {
|
|
32
|
+
return tasks;
|
|
33
|
+
}
|
|
34
|
+
const typeormDataSource = data.features?.find((value) => value.startsWith("typeorm:"));
|
|
35
|
+
return [
|
|
36
|
+
...tasks,
|
|
37
|
+
...(await this.cliService.getTasks("generate", {
|
|
38
|
+
...data,
|
|
39
|
+
type: "typeorm:dataSource",
|
|
40
|
+
name: pascalCase(database),
|
|
41
|
+
typeormDataSource
|
|
42
|
+
}))
|
|
43
|
+
];
|
|
38
44
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
OnExec("init"),
|
|
42
|
-
__metadata("design:type", Function),
|
|
43
|
-
__metadata("design:paramtypes", [Object]),
|
|
44
|
-
__metadata("design:returntype", void 0)
|
|
45
|
-
], TypeORMInitHook.prototype, "onExec", null);
|
|
46
|
-
TypeORMInitHook = __decorate([
|
|
47
|
-
Injectable()
|
|
48
|
-
], TypeORMInitHook);
|
|
49
|
-
export { TypeORMInitHook };
|
|
45
|
+
}
|
|
46
|
+
injectable(TypeORMInitHook);
|
package/lib/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import "./templates/datasource.template.js";
|
|
1
2
|
import { CliPluginTypeORMModule } from "./CliPluginTypeORMModule.js";
|
|
2
3
|
export * from "./hooks/TypeORMGenerateHook.js";
|
|
3
4
|
export * from "./hooks/TypeORMInitHook.js";
|
|
4
|
-
export * from "./utils/templateDir.js";
|
|
5
5
|
export default CliPluginTypeORMModule;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { getDatabase, getTypeORMDatabases } from "../utils/getTypeORMDatabases.js";
|
|
3
|
+
import { camelCase } from "change-case";
|
|
4
|
+
function datasourceConfig(database) {
|
|
5
|
+
switch (database) {
|
|
6
|
+
case "mysql":
|
|
7
|
+
case "mariadb":
|
|
8
|
+
return `
|
|
9
|
+
host: "localhost",
|
|
10
|
+
port: 3306,
|
|
11
|
+
username: "test",
|
|
12
|
+
password: "test",
|
|
13
|
+
database: "test"`;
|
|
14
|
+
case "sqlite":
|
|
15
|
+
case "better-sqlite3":
|
|
16
|
+
return `
|
|
17
|
+
database: "database.sqlite"`;
|
|
18
|
+
case "postgres":
|
|
19
|
+
return `
|
|
20
|
+
host: "localhost",
|
|
21
|
+
port: 5432,
|
|
22
|
+
username: "test",
|
|
23
|
+
password: "test",
|
|
24
|
+
database: "test"`;
|
|
25
|
+
case "cockroachdb":
|
|
26
|
+
return `
|
|
27
|
+
host: "localhost",
|
|
28
|
+
port: 26257,
|
|
29
|
+
username: "root",
|
|
30
|
+
password: "",
|
|
31
|
+
database: "defaultdb"`;
|
|
32
|
+
case "mssql":
|
|
33
|
+
return `
|
|
34
|
+
host: "localhost",
|
|
35
|
+
username: "sa",
|
|
36
|
+
password: "Admin12345",
|
|
37
|
+
database: "tempdb"`;
|
|
38
|
+
case "oracle":
|
|
39
|
+
return `
|
|
40
|
+
host: "localhost",
|
|
41
|
+
username: "system",
|
|
42
|
+
password: "oracle",
|
|
43
|
+
port: 1521,
|
|
44
|
+
sid: "xe.oracle.docker"`;
|
|
45
|
+
case "mongodb":
|
|
46
|
+
return `
|
|
47
|
+
database: "test"`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export default defineTemplate({
|
|
51
|
+
id: "typeorm:datasource",
|
|
52
|
+
label: "TypeORM DataSource",
|
|
53
|
+
fileName: "{{symbolName}}.datasource",
|
|
54
|
+
outputDir: "{{srcDir}}/datasources",
|
|
55
|
+
prompts: () => {
|
|
56
|
+
const list = getTypeORMDatabases().map(([value, { name }]) => {
|
|
57
|
+
return {
|
|
58
|
+
name: name,
|
|
59
|
+
value: value
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
type: "autocomplete",
|
|
65
|
+
name: "typeormDataSource",
|
|
66
|
+
message: "Which database type?",
|
|
67
|
+
when(state) {
|
|
68
|
+
return state.type === "typeorm:datasource";
|
|
69
|
+
},
|
|
70
|
+
source: (state, keyword) => {
|
|
71
|
+
if (keyword) {
|
|
72
|
+
return list.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
|
|
73
|
+
}
|
|
74
|
+
return list;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
},
|
|
79
|
+
render(symbolName, data) {
|
|
80
|
+
const database = getDatabase(data);
|
|
81
|
+
const instanceName = camelCase(symbolName);
|
|
82
|
+
return `import {injectable, logger} from "@tsed/di";
|
|
83
|
+
import {DataSource} from "typeorm";
|
|
84
|
+
import {Logger} from "@tsed/logger";
|
|
85
|
+
|
|
86
|
+
export const ${instanceName} = new DataSource({
|
|
87
|
+
type: "${database}",
|
|
88
|
+
entities: [],
|
|
89
|
+
${datasourceConfig(database)?.trim()}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const ${symbolName} = injectable(Symbol.for("${symbolName}"))
|
|
93
|
+
.type("typeorm:datasource")
|
|
94
|
+
.asyncFactory(async () => {
|
|
95
|
+
await ${instanceName}.initialize();
|
|
96
|
+
|
|
97
|
+
logger().info("Connected with typeorm to database: ${data.name}");
|
|
98
|
+
|
|
99
|
+
return ${instanceName};
|
|
100
|
+
})
|
|
101
|
+
.hooks({
|
|
102
|
+
$onDestroy(dataSource) {
|
|
103
|
+
return dataSource.isInitialized && dataSource.close();
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
.token();
|
|
107
|
+
|
|
108
|
+
export type ${symbolName} = DataSource;
|
|
109
|
+
`;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FeaturesMap } from "@tsed/cli";
|
|
2
|
+
export function getTypeORMDatabases() {
|
|
3
|
+
return Object.entries(FeaturesMap).filter(([value]) => value.startsWith("typeorm:"));
|
|
4
|
+
}
|
|
5
|
+
export function getDatabase(data) {
|
|
6
|
+
return data.typeormDataSource?.split(":").at(-1);
|
|
7
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { AlterPackageJson, RenderDataContext } from "@tsed/cli";
|
|
1
2
|
import { ProjectPackageJson } from "@tsed/cli-core";
|
|
2
|
-
export declare class CliPluginTypeORMModule {
|
|
3
|
+
export declare class CliPluginTypeORMModule implements AlterPackageJson {
|
|
3
4
|
protected packageJson: ProjectPackageJson;
|
|
4
|
-
|
|
5
|
+
$alterPackageJson(packageJson: ProjectPackageJson, data: RenderDataContext): ProjectPackageJson;
|
|
5
6
|
}
|
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { CliDockerComposeYaml, ProjectPackageJson, type
|
|
3
|
-
export
|
|
4
|
-
typeormDataSource: string;
|
|
5
|
-
datasourceName: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class TypeORMGenerateHook {
|
|
8
|
-
private providersInfoService;
|
|
1
|
+
import { type AlterGenerateTasks, type GenerateCmdContext } from "@tsed/cli";
|
|
2
|
+
import { CliDockerComposeYaml, ProjectPackageJson, type Task } from "@tsed/cli-core";
|
|
3
|
+
export declare class TypeORMGenerateHook implements AlterGenerateTasks {
|
|
9
4
|
protected projectPackageJson: ProjectPackageJson;
|
|
10
|
-
protected srcRenderService: SrcRendererService;
|
|
11
5
|
protected cliDockerComposeYaml: CliDockerComposeYaml;
|
|
12
|
-
|
|
13
|
-
onGeneratePrompt(): {
|
|
14
|
-
type: string;
|
|
15
|
-
name: string;
|
|
16
|
-
message: string;
|
|
17
|
-
when(state: any): boolean;
|
|
18
|
-
source: (state: any, keyword: string) => {
|
|
19
|
-
name: string;
|
|
20
|
-
value: string;
|
|
21
|
-
}[];
|
|
22
|
-
}[];
|
|
23
|
-
onGenerateExec(ctx: TypeORMGenerateOptions): Tasks;
|
|
24
|
-
getTypeORMTypes(): [string, import("@tsed/cli").Feature][];
|
|
25
|
-
generateDataSourceTasks(ctx: TypeORMGenerateOptions): {
|
|
26
|
-
title: string;
|
|
27
|
-
task: () => Promise<void>;
|
|
28
|
-
}[];
|
|
6
|
+
$alterGenerateTasks(tasks: Task[], data: GenerateCmdContext): Task[] | Promise<Task[]>;
|
|
29
7
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { CliService, ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
-
export declare class TypeORMInitHook {
|
|
1
|
+
import { type CliCommandHooks, ProjectClient, type RenderDataContext } from "@tsed/cli";
|
|
2
|
+
import { CliService, ProjectPackageJson, type Task } from "@tsed/cli-core";
|
|
3
|
+
export declare class TypeORMInitHook implements CliCommandHooks {
|
|
4
4
|
protected cliService: CliService;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
addDependencies(ctx: InitCmdContext): void;
|
|
9
|
-
addDevDependencies(ctx: InitCmdContext): void;
|
|
5
|
+
$alterPackageJson(packageJson: ProjectPackageJson, data: RenderDataContext): ProjectPackageJson;
|
|
6
|
+
$alterProjectFiles(project: ProjectClient, data: RenderDataContext): ProjectClient;
|
|
7
|
+
$alterInitSubTasks(tasks: Task[], data: RenderDataContext): Promise<Task[]>;
|
|
10
8
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import "./templates/datasource.template.js";
|
|
1
2
|
import { CliPluginTypeORMModule } from "./CliPluginTypeORMModule.js";
|
|
2
3
|
export * from "./hooks/TypeORMGenerateHook.js";
|
|
3
4
|
export * from "./hooks/TypeORMInitHook.js";
|
|
4
|
-
export * from "./utils/templateDir.js";
|
|
5
5
|
export default CliPluginTypeORMModule;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type GenerateCmdContext } from "@tsed/cli";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace TsED {
|
|
4
|
+
interface GenerateOptions {
|
|
5
|
+
typeormDataSource?: string;
|
|
6
|
+
datasourceName?: string;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare const _default: import("@tsed/cli-core").FactoryTokenProvider<{
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
outputDir: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
fileName?: string;
|
|
17
|
+
ext: string | null;
|
|
18
|
+
hidden?: boolean;
|
|
19
|
+
preserveCase?: boolean;
|
|
20
|
+
preserveDirectory?: boolean;
|
|
21
|
+
render(symbolName: string, data: GenerateCmdContext): Promise<string | undefined | import("@tsed/cli").TemplateRenderReturnType> | string | undefined | import("@tsed/cli").TemplateRenderReturnType;
|
|
22
|
+
prompts?(data: GenerateCmdContext): import("@tsed/cli-core").QuestionOptions<GenerateCmdContext>[] | Promise<import("@tsed/cli-core").QuestionOptions<GenerateCmdContext>[]>;
|
|
23
|
+
hooks?: import("@tsed/cli-core").ProviderOpts["hooks"];
|
|
24
|
+
}>;
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type GenerateCmdContext } from "@tsed/cli";
|
|
2
|
+
import type { CliDatabases } from "@tsed/cli-core";
|
|
3
|
+
export declare function getTypeORMDatabases(): [string, import("@tsed/cli").Feature][];
|
|
4
|
+
export declare function getDatabase(data: GenerateCmdContext): CliDatabases | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-plugin-typeorm",
|
|
3
3
|
"description": "Ts.ED CLI plugin. Add TypeORM support",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-alpha.10",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/esm/index.js",
|
|
7
7
|
"source": "./src/index.ts",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"tslib": "2.7.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@tsed/cli": "
|
|
30
|
-
"@tsed/cli-core": "
|
|
31
|
-
"@tsed/typescript": "
|
|
29
|
+
"@tsed/cli": "7.0.0-alpha.10",
|
|
30
|
+
"@tsed/cli-core": "7.0.0-alpha.10",
|
|
31
|
+
"@tsed/typescript": "7.0.0-alpha.10",
|
|
32
32
|
"cross-env": "7.0.3",
|
|
33
33
|
"typescript": "5.6.2",
|
|
34
34
|
"vitest": "3.2.4"
|
|
@@ -40,5 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/tsedio/tsed-cli/tree/master/packages/cli-plugin-typeorm",
|
|
42
42
|
"author": "Romain Lenzotti",
|
|
43
|
-
"license": "MIT"
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"tag": "alpha"
|
|
46
|
+
}
|
|
44
47
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const TEMPLATE_DIR: string;
|
package/templates/datasource.hbs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {registerProvider} from "@tsed/di";
|
|
2
|
-
import {DataSource} from "typeorm";
|
|
3
|
-
import {Logger} from "@tsed/logger";
|
|
4
|
-
|
|
5
|
-
export const {{symbolName}} = Symbol.for("{{symbolName}}");
|
|
6
|
-
export type {{symbolName}} = DataSource;
|
|
7
|
-
export const {{instanceName}} = new DataSource({
|
|
8
|
-
type: "{{database}}",
|
|
9
|
-
entities: [],
|
|
10
|
-
{{#switch database}}
|
|
11
|
-
{{#case 'mysql'}}
|
|
12
|
-
host: "localhost",
|
|
13
|
-
port: 3306,
|
|
14
|
-
username: "test",
|
|
15
|
-
password: "test",
|
|
16
|
-
database: "test"
|
|
17
|
-
{{/case}}
|
|
18
|
-
{{#case 'mariadb'}}
|
|
19
|
-
host: "localhost",
|
|
20
|
-
port: 3306,
|
|
21
|
-
username: "test",
|
|
22
|
-
password: "test",
|
|
23
|
-
database: "test"
|
|
24
|
-
{{/case}}
|
|
25
|
-
{{#case 'sqlite'}}
|
|
26
|
-
database: "database.sqlite"
|
|
27
|
-
{{/case}}
|
|
28
|
-
{{#case 'better-sqlite3'}}
|
|
29
|
-
database: "database.sqlite"
|
|
30
|
-
{{/case}}
|
|
31
|
-
{{#case 'postgres'}}
|
|
32
|
-
host: "localhost",
|
|
33
|
-
port: 5432,
|
|
34
|
-
username: "test",
|
|
35
|
-
password: "test",
|
|
36
|
-
database: "test"
|
|
37
|
-
{{/case}}
|
|
38
|
-
{{#case 'cockroachdb'}}
|
|
39
|
-
host: "localhost",
|
|
40
|
-
port: 26257,
|
|
41
|
-
username: "root",
|
|
42
|
-
password: "",
|
|
43
|
-
database: "defaultdb"
|
|
44
|
-
{{/case}}
|
|
45
|
-
{{#case 'mssql'}}
|
|
46
|
-
host: "localhost",
|
|
47
|
-
username: "sa",
|
|
48
|
-
password: "Admin12345",
|
|
49
|
-
database: "tempdb"
|
|
50
|
-
{{/case}}
|
|
51
|
-
{{#case 'oracle'}}
|
|
52
|
-
host: "localhost",
|
|
53
|
-
username: "system",
|
|
54
|
-
password: "oracle",
|
|
55
|
-
port: 1521,
|
|
56
|
-
sid: "xe.oracle.docker"
|
|
57
|
-
{{/case}}
|
|
58
|
-
{{#case 'mongodb'}}
|
|
59
|
-
database: "test"
|
|
60
|
-
{{/case}}
|
|
61
|
-
{{/switch}}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
registerProvider<DataSource>({
|
|
66
|
-
provide: {{symbolName}},
|
|
67
|
-
type: "typeorm:datasource",
|
|
68
|
-
deps: [Logger],
|
|
69
|
-
async useAsyncFactory(logger: Logger) {
|
|
70
|
-
await {{instanceName}}.initialize();
|
|
71
|
-
|
|
72
|
-
logger.info("Connected with typeorm to database: {{name}}");
|
|
73
|
-
|
|
74
|
-
return {{instanceName}};
|
|
75
|
-
},
|
|
76
|
-
hooks: {
|
|
77
|
-
$onDestroy(dataSource) {
|
|
78
|
-
return dataSource.isInitialized && dataSource.close();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|