@anarchitects/nx-typeorm 0.0.3 → 0.1.0

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.
Files changed (97) hide show
  1. package/README.md +155 -49
  2. package/dist/executors/cache-clear/executor.d.ts +6 -0
  3. package/dist/executors/cache-clear/executor.d.ts.map +1 -0
  4. package/dist/executors/cache-clear/executor.js +5 -0
  5. package/dist/executors/cache-clear/schema.json +28 -0
  6. package/dist/executors/ensure-schema/executor.d.ts +1 -5
  7. package/dist/executors/ensure-schema/executor.d.ts.map +1 -1
  8. package/dist/executors/ensure-schema/executor.js +1 -1
  9. package/dist/executors/entity-create/executor.d.ts +6 -0
  10. package/dist/executors/entity-create/executor.d.ts.map +1 -0
  11. package/dist/executors/entity-create/executor.js +15 -0
  12. package/dist/executors/entity-create/schema.json +23 -0
  13. package/dist/executors/generate/executor.d.ts +1 -7
  14. package/dist/executors/generate/executor.d.ts.map +1 -1
  15. package/dist/executors/generate/executor.js +12 -24
  16. package/dist/executors/generate/schema.json +11 -1
  17. package/dist/executors/init/executor.d.ts +6 -0
  18. package/dist/executors/init/executor.d.ts.map +1 -0
  19. package/dist/executors/init/executor.js +24 -0
  20. package/dist/executors/init/schema.json +40 -0
  21. package/dist/executors/migration-create/executor.d.ts +6 -0
  22. package/dist/executors/migration-create/executor.d.ts.map +1 -0
  23. package/dist/executors/migration-create/executor.js +19 -0
  24. package/dist/executors/migration-create/schema.json +31 -0
  25. package/dist/executors/migration-show/executor.d.ts +6 -0
  26. package/dist/executors/migration-show/executor.d.ts.map +1 -0
  27. package/dist/executors/migration-show/executor.js +5 -0
  28. package/dist/executors/migration-show/schema.json +28 -0
  29. package/dist/executors/query/executor.d.ts +6 -0
  30. package/dist/executors/query/executor.d.ts.map +1 -0
  31. package/dist/executors/query/executor.js +9 -0
  32. package/dist/executors/query/schema.json +33 -0
  33. package/dist/executors/revert/executor.d.ts +1 -5
  34. package/dist/executors/revert/executor.d.ts.map +1 -1
  35. package/dist/executors/revert/executor.js +8 -19
  36. package/dist/executors/revert/schema.json +7 -1
  37. package/dist/executors/run/executor.d.ts +1 -6
  38. package/dist/executors/run/executor.d.ts.map +1 -1
  39. package/dist/executors/run/executor.js +7 -18
  40. package/dist/executors/run/schema.json +6 -0
  41. package/dist/executors/schema-drop/executor.d.ts +6 -0
  42. package/dist/executors/schema-drop/executor.d.ts.map +1 -0
  43. package/dist/executors/schema-drop/executor.js +5 -0
  44. package/dist/executors/schema-drop/schema.json +28 -0
  45. package/dist/executors/schema-log/executor.d.ts +6 -0
  46. package/dist/executors/schema-log/executor.d.ts.map +1 -0
  47. package/dist/executors/schema-log/executor.js +5 -0
  48. package/dist/executors/schema-log/schema.json +28 -0
  49. package/dist/executors/schema-sync/executor.d.ts +6 -0
  50. package/dist/executors/schema-sync/executor.d.ts.map +1 -0
  51. package/dist/executors/schema-sync/executor.js +5 -0
  52. package/dist/executors/schema-sync/schema.json +28 -0
  53. package/dist/executors/seed/executor.d.ts +1 -7
  54. package/dist/executors/seed/executor.d.ts.map +1 -1
  55. package/dist/executors/seed/executor.js +1 -1
  56. package/dist/executors/subscriber-create/executor.d.ts +6 -0
  57. package/dist/executors/subscriber-create/executor.d.ts.map +1 -0
  58. package/dist/executors/subscriber-create/executor.js +13 -0
  59. package/dist/executors/subscriber-create/schema.json +23 -0
  60. package/dist/executors/version/executor.d.ts +6 -0
  61. package/dist/executors/version/executor.d.ts.map +1 -0
  62. package/dist/executors/version/executor.js +5 -0
  63. package/dist/executors/version/schema.json +14 -0
  64. package/dist/generators/bootstrap/files/app/env.example__tmpl__ +55 -1
  65. package/dist/generators/bootstrap/files/app/src/data-source.ts__tmpl__ +6 -0
  66. package/dist/generators/bootstrap/files/app/src/typeorm.datasource.ts__tmpl__ +1 -15
  67. package/dist/generators/bootstrap/files/app/tools/typeorm/connection-options.ts__tmpl__ +292 -0
  68. package/dist/generators/bootstrap/files/app/tools/typeorm/datasource.migrations.ts__tmpl__ +2 -7
  69. package/dist/generators/bootstrap/files/lib/project.json.partial__tmpl__ +3 -1
  70. package/dist/generators/bootstrap/generator.d.ts +5 -1
  71. package/dist/generators/bootstrap/generator.d.ts.map +1 -1
  72. package/dist/generators/bootstrap/generator.js +179 -31
  73. package/dist/generators/bootstrap/schema.json +18 -1
  74. package/dist/generators/init/generator.d.ts +4 -0
  75. package/dist/generators/init/generator.d.ts.map +1 -0
  76. package/dist/generators/init/generator.js +31 -0
  77. package/dist/generators/init/schema.json +18 -0
  78. package/dist/index.d.ts +13 -0
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +13 -0
  81. package/dist/index.json +48 -0
  82. package/dist/plugin/index.d.ts +9 -0
  83. package/dist/plugin/index.d.ts.map +1 -0
  84. package/dist/plugin/index.js +241 -0
  85. package/dist/plugins/typeorm.d.ts +1 -6
  86. package/dist/plugins/typeorm.d.ts.map +1 -1
  87. package/dist/plugins/typeorm.js +1 -161
  88. package/dist/utils/cli.d.ts +17 -0
  89. package/dist/utils/cli.d.ts.map +1 -0
  90. package/dist/utils/cli.js +55 -0
  91. package/dist/{executors → utils}/shared.d.ts +12 -9
  92. package/dist/utils/shared.d.ts.map +1 -0
  93. package/dist/utils/shared.js +260 -0
  94. package/package.json +6 -7
  95. package/dist/executors/shared.d.ts.map +0 -1
  96. package/dist/executors/shared.js +0 -71
  97. package/dist/generators/bootstrap/files/app/tools/typeorm/datasource.runtime.ts__tmpl__ +0 -9
package/README.md CHANGED
@@ -1,84 +1,190 @@
1
1
  # @anarchitects/nx-typeorm
2
2
 
3
- Nx plugin that gives Rails-like ergonomics for TypeORM projects. It wires common
4
- TypeORM workflows into the Nx task system so you can run migrations, seeds, and
5
- bootstrap new projects without leaving `nx`.
3
+ Nx plugin for TypeORM integration in Nx backend applications and libraries.
4
+ It provides:
6
5
 
7
- ## Purpose
8
-
9
- - Detect TypeORM-enabled projects and infer common Nx targets (run, revert,
10
- seed, ensure-schema).
11
- - Provide thin executors that proxy TypeORM CLI commands through the active
12
- package manager.
13
- - Scaffold applications or libraries with ready-to-use TypeORM wiring, seeds,
14
- and migration directories via `nx g @anarchitects/nx-typeorm:bootstrap`.
6
+ - `nx add` / `init` setup for minimal TypeORM dependencies.
7
+ - `bootstrap` scaffolding for app runtime datasource wiring and library
8
+ infrastructure-persistence templates.
9
+ - inferred database targets via `createNodesV2`.
10
+ - thin executors that wrap TypeORM CLI workflows.
15
11
 
16
12
  ## Installation
17
13
 
14
+ Use `nx add` so the plugin installs and runs `init` automatically:
15
+
18
16
  ```bash
19
- yarn add -D @anarchitects/nx-typeorm
17
+ nx add @anarchitects/nx-typeorm
20
18
  ```
21
19
 
22
- If you rely on TypeScript seeds or migrations, also add:
20
+ This registers the plugin in `nx.json` and installs minimal dependencies:
21
+ `typeorm` and `reflect-metadata`.
22
+
23
+ You can re-run initialization later:
23
24
 
24
25
  ```bash
25
- yarn add -D ts-node typeorm-ts-node-commonjs
26
+ nx g @anarchitects/nx-typeorm:init
26
27
  ```
27
28
 
28
- ## Usage
29
+ ## Generators
29
30
 
30
- ### Bootstrap a project
31
+ ### `init`
31
32
 
32
33
  ```bash
33
- nx g @anarchitects/nx-typeorm:bootstrap api --withCompose
34
+ nx g @anarchitects/nx-typeorm:init
34
35
  ```
35
36
 
36
- Creates TypeORM configuration files, seed/migration directories, and patches
37
- `app.module.ts` (for Nest apps) to use `TypeOrmModule.forRootAsync`.
37
+ - Registers `@anarchitects/nx-typeorm` in `nx.json > plugins`.
38
+ - Adds `typeorm` and `reflect-metadata`.
38
39
 
39
- ### Run migrations
40
+ ### `bootstrap`
40
41
 
41
42
  ```bash
42
- nx run api:run --transaction=each
43
+ nx g @anarchitects/nx-typeorm:bootstrap --project=api
43
44
  ```
44
45
 
45
- ### Generate a migration
46
+ For applications:
46
47
 
47
- ```bash
48
- nx run api:generate --name AddUsers --driftCheck
49
- ```
48
+ - generates runtime datasource in `src/data-source.ts`.
49
+ - generates compatibility re-export `src/typeorm.datasource.ts`.
50
+ - generates shared connection helper `tools/typeorm/connection-options.ts`.
51
+ - generates TypeORM CLI migration datasource
52
+ `tools/typeorm/datasource.migrations.ts` and seeds under `tools/typeorm`.
53
+ - preserves an existing `tools/typeorm/datasource.migrations.ts` file.
54
+ - generates a DB-specific `env.example` with URL/discrete modes.
55
+ - patches `app.module.ts` only when the app has a Nest module file.
50
56
 
51
- ### Revert migrations
57
+ For libraries:
52
58
 
53
- ```bash
54
- nx run api:revert --count=1
55
- ```
59
+ - generates `schema.ts` and `1700000000000_init_schema.ts` under
60
+ `src/infrastructure-persistence` by default.
61
+ - supports overrides with:
62
+ - `--schemaPath=<relative-path>`
63
+ - `--migrationsDir=<relative-dir>`
64
+ - patches project metadata (`metadata.typeorm`) with schema/domain and paths.
56
65
 
57
- ### Ensure schema
66
+ Additional bootstrap dependencies are installed during bootstrap:
67
+ `ts-node`, `typeorm-ts-node-commonjs`, `typeorm-ts-node-esm`,
68
+ DB driver package for selected `--db`, and `@nestjs/typeorm` only for Nest
69
+ applications.
58
70
 
59
- ```bash
60
- DATABASE_URL=postgres://... nx run data-access:ensure-schema
61
- ```
71
+ Supported `--db` values: `postgres`, `postgresql` (normalized to `postgres`),
72
+ `mysql`, `mariadb`, `sqlite`, `better-sqlite3`, `mssql`.
62
73
 
63
- ### Seed data
74
+ Generated app datasources support two connection modes:
64
75
 
65
- ```bash
66
- nx run api:seed --file tools/typeorm/seeds/index.ts --export runSeed
67
- ```
76
+ - `DATABASE_URL`
77
+ - discrete `TYPEORM_*` variables
78
+
79
+ The generated helper rejects mixed mode (setting `DATABASE_URL` together with
80
+ `TYPEORM_*` connection variables) and throws clear validation errors when
81
+ required variables are missing.
82
+
83
+ ## Inferred Targets
84
+
85
+ When TypeORM files are detected, the plugin infers:
86
+
87
+ - `db:migrate:generate`
88
+ - `db:migrate:run`
89
+ - `db:migrate:revert`
90
+ - `db:migrate:show`
91
+ - `db:schema:sync`
92
+ - `db:schema:log`
93
+ - `db:cache:clear`
94
+ - `db:ensure-schema`
95
+ - `db:seed` (applications)
68
96
 
69
- Each executor forwards any extra CLI arguments to the underlying TypeORM tool,
70
- making it easy to customize behavior.
97
+ Compatibility aliases are also inferred:
71
98
 
72
- ## Functionality Overview
99
+ - `typeorm:generate`
100
+ - `typeorm:run`
101
+ - `typeorm:revert`
102
+ - `typeorm:show`
103
+ - `typeorm:schema:sync`
104
+ - `typeorm:schema:log`
105
+ - `typeorm:cache:clear`
106
+ - `typeorm:ensure-schema`
107
+ - `typeorm:seed` (applications)
73
108
 
74
- - **Executors**: `generate`, `run`, `revert`, `ensure-schema`, and `seed` wrap
75
- TypeORM commands with Nx-friendly ergonomics.
76
- - **Generator**: `bootstrap` lays down TypeORM config, seeds, migrations, and
77
- Nest integration boilerplate.
78
- - **Inference**: Detects TypeORM projects and auto adds sensible default targets
79
- when you run `nx graph` or `nx run` commands.
109
+ ## Executor Usage
80
110
 
81
- ## Tasks
111
+ Run inferred targets:
82
112
 
83
- - `nx build nx-typeorm` – build the plugin.
84
- - `nx test nx-typeorm` – run Jest unit tests.
113
+ ```bash
114
+ nx run api:db:migrate:run --transaction=each
115
+ nx run api:db:migrate:generate --name AddUsers
116
+ nx run api:db:migrate:revert --count=2
117
+ nx run api:db:migrate:show
118
+ nx run api:db:schema:sync
119
+ nx run api:db:schema:log
120
+ nx run api:db:cache:clear
121
+ nx run data-access:db:ensure-schema
122
+ nx run api:db:seed --file tools/typeorm/seeds/index.ts
123
+ ```
124
+
125
+ `generate` supports `--check` and compatibility alias `--driftCheck` (mapped to
126
+ TypeORM check mode).
127
+
128
+ CLI executors (`generate`, `run`, `revert`) select the TypeORM runner at
129
+ runtime:
130
+
131
+ - `moduleSystem=auto` (default): detect by nearest `package.json` `type`,
132
+ then project tsconfig module mode, then fall back to CommonJS.
133
+ - `moduleSystem=commonjs`: force `typeorm-ts-node-commonjs`.
134
+ - `moduleSystem=esm`: force `typeorm-ts-node-esm`.
135
+
136
+ When `dataSource` is omitted, migration-oriented executors (`generate`, `run`,
137
+ `revert`) and `ensure-schema` infer it from the project with this priority:
138
+
139
+ 1. `tools/typeorm/datasource.migrations.ts`
140
+ 2. `tools/typeorm/datasource.migrations.js`
141
+ 3. `src/data-source.ts`
142
+ 4. `src/data-source.js`
143
+ 5. `src/typeorm.datasource.ts`
144
+ 6. `src/typeorm.datasource.js`
145
+
146
+ Override inference at any time with `--dataSource=<relative-or-absolute-path>`.
147
+
148
+ ## TypeORM CLI Coverage
149
+
150
+ | TypeORM CLI command | nx-typeorm executor | Inferred target |
151
+ | -------------------- | ------------------- | --------------- |
152
+ | `migration:create` | `migration-create` | no |
153
+ | `migration:generate` | `generate` | yes |
154
+ | `migration:run` | `run` | yes |
155
+ | `migration:revert` | `revert` | yes |
156
+ | `migration:show` | `migration-show` | yes |
157
+ | `schema:sync` | `schema-sync` | yes |
158
+ | `schema:log` | `schema-log` | yes |
159
+ | `schema:drop` | `schema-drop` | no |
160
+ | `query` | `query` | no |
161
+ | `cache:clear` | `cache-clear` | yes |
162
+ | `entity:create` | `entity-create` | no |
163
+ | `subscriber:create` | `subscriber-create` | no |
164
+ | `version` | `version` | no |
165
+ | `init` | `init` | no |
166
+
167
+ Manual-only executors are available for explicit wiring in `project.json`.
168
+ This includes risky commands like `query` and `schema:drop`.
169
+
170
+ Example manual targets:
171
+
172
+ ```json
173
+ {
174
+ "targets": {
175
+ "db:query": {
176
+ "executor": "@anarchitects/nx-typeorm:query",
177
+ "options": {
178
+ "projectRoot": "apps/api",
179
+ "query": "SELECT 1"
180
+ }
181
+ },
182
+ "db:schema:drop": {
183
+ "executor": "@anarchitects/nx-typeorm:schema-drop",
184
+ "options": {
185
+ "projectRoot": "apps/api"
186
+ }
187
+ }
188
+ }
189
+ }
190
+ ```
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { CacheClearExecutorOptions } from './schema.js';
3
+ export default function clearCache(options: CacheClearExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/cache-clear/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAA8B,UAAU,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,eAAe;;GASzB"}
@@ -0,0 +1,5 @@
1
+ import { runDataSourceTypeormCommand } from '../../utils/cli.js';
2
+ export default async function clearCache(options, context) {
3
+ const exitCode = await runDataSourceTypeormCommand('cache:clear', options, context);
4
+ return { success: exitCode === 0 };
5
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Cache Clear Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "projectRoot": {
7
+ "type": "string",
8
+ "description": "Project root when it cannot be inferred from the Nx project configuration."
9
+ },
10
+ "dataSource": {
11
+ "type": "string",
12
+ "description": "Path to the TypeORM data source file used for cache clearing."
13
+ },
14
+ "moduleSystem": {
15
+ "type": "string",
16
+ "enum": ["auto", "commonjs", "esm"],
17
+ "default": "auto",
18
+ "description": "Override module-system detection used to select the TypeORM CLI runner."
19
+ },
20
+ "args": {
21
+ "type": "array",
22
+ "items": {
23
+ "type": "string"
24
+ },
25
+ "description": "Additional CLI arguments passed through to the TypeORM command."
26
+ }
27
+ }
28
+ }
@@ -1,9 +1,5 @@
1
1
  import type { ExecutorContext } from '@nx/devkit';
2
- import { type BaseExecutorOptions } from '../shared.js';
3
- export interface EnsureSchemaExecutorOptions extends Pick<BaseExecutorOptions, 'projectRoot' | 'dataSource'> {
4
- schema?: string;
5
- tsconfig?: string;
6
- }
2
+ import type { EnsureSchemaExecutorOptions } from './schema.js';
7
3
  export default function ensureSchema(options: EnsureSchemaExecutorOptions, context: ExecutorContext): Promise<{
8
4
  success: boolean;
9
5
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/ensure-schema/executor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,2BACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,YAAY,CAAC;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAA8B,YAAY,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe;;GAyEzB"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/ensure-schema/executor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQlD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/D,wBAA8B,YAAY,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe;;GAyEzB"}
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { logger } from '@nx/devkit';
5
- import { ensureProjectRoot, schemaFilePath, schemaNameFrom, } from '../shared.js';
5
+ import { ensureProjectRoot, schemaFilePath, schemaNameFrom, } from '../../utils/shared.js';
6
6
  export default async function ensureSchema(options, context) {
7
7
  const { absoluteProjectRoot, dataSource: dataSourcePath } = ensureProjectRoot({ projectRoot: options.projectRoot, dataSource: options.dataSource }, context);
8
8
  let schemaName = options.schema?.trim();
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { EntityCreateExecutorOptions } from './schema.js';
3
+ export default function createEntity(options: EntityCreateExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/entity-create/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/D,wBAA8B,YAAY,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe;;GAczB"}
@@ -0,0 +1,15 @@
1
+ import { isAbsolute, join } from 'node:path';
2
+ import { runTypeormCommand } from '../../utils/cli.js';
3
+ import { resolveProjectRoot } from '../../utils/shared.js';
4
+ export default async function createEntity(options, context) {
5
+ const path = options.path?.trim();
6
+ if (!path) {
7
+ throw new Error('Provide an entity path via the path option.');
8
+ }
9
+ const { projectRoot } = resolveProjectRoot(options.projectRoot, context);
10
+ const targetPath = isAbsolute(path) ? path : join(projectRoot, path);
11
+ const exitCode = await runTypeormCommand('entity:create', options, context, [
12
+ targetPath,
13
+ ]);
14
+ return { success: exitCode === 0 };
15
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Entity Create Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "path": {
7
+ "type": "string",
8
+ "description": "Path of the entity file."
9
+ },
10
+ "projectRoot": {
11
+ "type": "string",
12
+ "description": "Project root when it cannot be inferred from the Nx project configuration."
13
+ },
14
+ "args": {
15
+ "type": "array",
16
+ "items": {
17
+ "type": "string"
18
+ },
19
+ "description": "Additional CLI arguments passed through to the TypeORM command."
20
+ }
21
+ },
22
+ "required": ["path"]
23
+ }
@@ -1,11 +1,5 @@
1
1
  import type { ExecutorContext } from '@nx/devkit';
2
- import { type BaseExecutorOptions } from '../shared.js';
3
- export interface GenerateExecutorOptions extends BaseExecutorOptions {
4
- name: string;
5
- outputPath?: string;
6
- pretty?: boolean;
7
- driftCheck?: boolean;
8
- }
2
+ import type { GenerateExecutorOptions } from './schema.js';
9
3
  export default function runGenerate(options: GenerateExecutorOptions, context: ExecutorContext): Promise<{
10
4
  success: boolean;
11
5
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/generate/executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAQL,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAA8B,WAAW,CACvC,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,eAAe;;GAyCzB"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/generate/executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQlD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,wBAA8B,WAAW,CACvC,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,eAAe;;GAiCzB"}
@@ -1,39 +1,27 @@
1
1
  import { mkdirSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
- import { getPackageManagerCommand } from '@nx/devkit';
4
- import { defaultMigrationsDirectory, ensureArgs, ensureProjectRoot, normalizeName, projectTypeFor, relativeToWorkspace, splitCommand, } from '../shared.js';
5
- import { spawn } from '../../utils/spawn.js';
3
+ import { defaultMigrationsDirectory, normalizeName, projectTypeFor, resolveProjectRoot, } from '../../utils/shared.js';
4
+ import { runDataSourceTypeormCommand } from '../../utils/cli.js';
6
5
  export default async function runGenerate(options, context) {
7
6
  if (!options.name || options.name.trim().length === 0) {
8
7
  throw new Error('Provide a migration name via the name option.');
9
8
  }
10
9
  const normalizedName = normalizeName(options.name.trim());
11
- const paths = ensureProjectRoot(options, context);
10
+ const { projectRoot } = resolveProjectRoot(options.projectRoot, context);
12
11
  const projectType = projectTypeFor(context);
13
- const outputDirectory = options.outputPath ??
14
- defaultMigrationsDirectory(paths.projectRoot, projectType);
12
+ const outputDirectory = options.outputPath ?? defaultMigrationsDirectory(projectRoot, projectType);
15
13
  const targetPath = join(outputDirectory, normalizedName);
16
14
  mkdirSync(dirname(targetPath), { recursive: true });
17
- const pmc = getPackageManagerCommand();
18
- const execCommand = pmc.exec ?? pmc.dlx ?? 'npx';
19
- const [command, baseArgs] = splitCommand(execCommand);
20
- const args = [
21
- ...baseArgs,
22
- 'typeorm-ts-node-commonjs',
23
- 'migration:generate',
24
- targetPath,
25
- '-d',
26
- relativeToWorkspace(context.root, paths.dataSource),
27
- '-n',
28
- normalizedName,
29
- ];
15
+ const afterDataSourceArgs = [];
30
16
  if (options.pretty ?? true) {
31
- args.push('--pretty');
17
+ afterDataSourceArgs.push('--pretty');
32
18
  }
33
- if (options.driftCheck) {
34
- args.push('--drift-check');
19
+ if (options.driftCheck || options.check) {
20
+ afterDataSourceArgs.push('--check');
35
21
  }
36
- args.push(...ensureArgs(options.args));
37
- const exitCode = await spawn(command, args, { cwd: context.root });
22
+ const exitCode = await runDataSourceTypeormCommand('migration:generate', options, context, {
23
+ beforeDataSourceArgs: [targetPath],
24
+ afterDataSourceArgs,
25
+ });
38
26
  return { success: exitCode === 0 };
39
27
  }
@@ -15,6 +15,12 @@
15
15
  "type": "string",
16
16
  "description": "Path to the TypeORM data source file used for migrations."
17
17
  },
18
+ "moduleSystem": {
19
+ "type": "string",
20
+ "enum": ["auto", "commonjs", "esm"],
21
+ "default": "auto",
22
+ "description": "Override module-system detection used to select the TypeORM CLI runner."
23
+ },
18
24
  "outputPath": {
19
25
  "type": "string",
20
26
  "description": "Directory where generated migrations will be placed."
@@ -26,7 +32,11 @@
26
32
  },
27
33
  "driftCheck": {
28
34
  "type": "boolean",
29
- "description": "Enable drift check before generating migrations."
35
+ "description": "Compatibility alias for TypeORM check mode (`--check`)."
36
+ },
37
+ "check": {
38
+ "type": "boolean",
39
+ "description": "Run TypeORM in check mode (`--check`) and fail when schema drift is detected."
30
40
  },
31
41
  "args": {
32
42
  "type": "array",
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { InitExecutorOptions } from './schema.js';
3
+ export default function initTypeormProject(options: InitExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/init/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAA8B,kBAAkB,CAC9C,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,eAAe;;GA+BzB"}
@@ -0,0 +1,24 @@
1
+ import { runTypeormCommand } from '../../utils/cli.js';
2
+ export default async function initTypeormProject(options, context) {
3
+ const commandArgs = [];
4
+ if (options.name && options.name.trim().length > 0) {
5
+ commandArgs.push('--name', options.name.trim());
6
+ }
7
+ if (options.database && options.database.trim().length > 0) {
8
+ commandArgs.push('--database', options.database.trim());
9
+ }
10
+ if (options.express) {
11
+ commandArgs.push('--express');
12
+ }
13
+ if (options.docker) {
14
+ commandArgs.push('--docker');
15
+ }
16
+ if (options.manager) {
17
+ commandArgs.push('--manager', options.manager);
18
+ }
19
+ if (options.module) {
20
+ commandArgs.push('--module', options.module);
21
+ }
22
+ const exitCode = await runTypeormCommand('init', options, context, commandArgs);
23
+ return { success: exitCode === 0 };
24
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Init Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "name": {
7
+ "type": "string",
8
+ "description": "Name of the generated TypeORM project directory."
9
+ },
10
+ "database": {
11
+ "type": "string",
12
+ "description": "Database type passed to TypeORM init."
13
+ },
14
+ "express": {
15
+ "type": "boolean",
16
+ "description": "Generate an Express sample project."
17
+ },
18
+ "docker": {
19
+ "type": "boolean",
20
+ "description": "Generate docker-compose output."
21
+ },
22
+ "manager": {
23
+ "type": "string",
24
+ "enum": ["npm", "yarn"],
25
+ "description": "Package manager used by TypeORM init."
26
+ },
27
+ "module": {
28
+ "type": "string",
29
+ "enum": ["commonjs", "esm"],
30
+ "description": "Module system used by TypeORM init."
31
+ },
32
+ "args": {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "string"
36
+ },
37
+ "description": "Additional CLI arguments passed through to the TypeORM command."
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { MigrationCreateExecutorOptions } from './schema.js';
3
+ export default function createMigration(options: MigrationCreateExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/migration-create/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAElE,wBAA8B,eAAe,CAC3C,OAAO,EAAE,8BAA8B,EACvC,OAAO,EAAE,eAAe;;GA0BzB"}
@@ -0,0 +1,19 @@
1
+ import { runTypeormCommand } from '../../utils/cli.js';
2
+ export default async function createMigration(options, context) {
3
+ const path = options.path?.trim();
4
+ if (!path) {
5
+ throw new Error('Provide a migration path via the path option.');
6
+ }
7
+ const commandArgs = [path];
8
+ if (options.outputJs) {
9
+ commandArgs.push('--outputJs');
10
+ }
11
+ if (options.esm) {
12
+ commandArgs.push('--esm');
13
+ }
14
+ if (typeof options.timestamp === 'number') {
15
+ commandArgs.push('--timestamp', `${options.timestamp}`);
16
+ }
17
+ const exitCode = await runTypeormCommand('migration:create', options, context, commandArgs);
18
+ return { success: exitCode === 0 };
19
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Migration Create Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "path": {
7
+ "type": "string",
8
+ "description": "Path for the migration file."
9
+ },
10
+ "outputJs": {
11
+ "type": "boolean",
12
+ "description": "Generate JavaScript migration output."
13
+ },
14
+ "esm": {
15
+ "type": "boolean",
16
+ "description": "Generate ESM migration output."
17
+ },
18
+ "timestamp": {
19
+ "type": "number",
20
+ "description": "Custom migration timestamp."
21
+ },
22
+ "args": {
23
+ "type": "array",
24
+ "items": {
25
+ "type": "string"
26
+ },
27
+ "description": "Additional CLI arguments passed through to the TypeORM command."
28
+ }
29
+ },
30
+ "required": ["path"]
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { MigrationShowExecutorOptions } from './schema.js';
3
+ export default function showMigrations(options: MigrationShowExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/migration-show/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,cAAc,CAC1C,OAAO,EAAE,4BAA4B,EACrC,OAAO,EAAE,eAAe;;GASzB"}
@@ -0,0 +1,5 @@
1
+ import { runDataSourceTypeormCommand } from '../../utils/cli.js';
2
+ export default async function showMigrations(options, context) {
3
+ const exitCode = await runDataSourceTypeormCommand('migration:show', options, context);
4
+ return { success: exitCode === 0 };
5
+ }