@anarchitects/nx-typeorm 0.0.3 → 0.2.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.
- package/README.md +203 -43
- package/dist/executors/cache-clear/executor.d.ts +6 -0
- package/dist/executors/cache-clear/executor.d.ts.map +1 -0
- package/dist/executors/cache-clear/executor.js +5 -0
- package/dist/executors/cache-clear/schema.json +28 -0
- package/dist/executors/ensure-schema/executor.d.ts +1 -5
- package/dist/executors/ensure-schema/executor.d.ts.map +1 -1
- package/dist/executors/ensure-schema/executor.js +1 -1
- package/dist/executors/entity-create/executor.d.ts +6 -0
- package/dist/executors/entity-create/executor.d.ts.map +1 -0
- package/dist/executors/entity-create/executor.js +15 -0
- package/dist/executors/entity-create/schema.json +23 -0
- package/dist/executors/generate/executor.d.ts +1 -7
- package/dist/executors/generate/executor.d.ts.map +1 -1
- package/dist/executors/generate/executor.js +12 -24
- package/dist/executors/generate/schema.json +11 -1
- package/dist/executors/init/executor.d.ts +6 -0
- package/dist/executors/init/executor.d.ts.map +1 -0
- package/dist/executors/init/executor.js +24 -0
- package/dist/executors/init/schema.json +40 -0
- package/dist/executors/migration-create/executor.d.ts +6 -0
- package/dist/executors/migration-create/executor.d.ts.map +1 -0
- package/dist/executors/migration-create/executor.js +19 -0
- package/dist/executors/migration-create/schema.json +31 -0
- package/dist/executors/migration-show/executor.d.ts +6 -0
- package/dist/executors/migration-show/executor.d.ts.map +1 -0
- package/dist/executors/migration-show/executor.js +5 -0
- package/dist/executors/migration-show/schema.json +28 -0
- package/dist/executors/query/executor.d.ts +6 -0
- package/dist/executors/query/executor.d.ts.map +1 -0
- package/dist/executors/query/executor.js +9 -0
- package/dist/executors/query/schema.json +33 -0
- package/dist/executors/revert/executor.d.ts +1 -5
- package/dist/executors/revert/executor.d.ts.map +1 -1
- package/dist/executors/revert/executor.js +8 -19
- package/dist/executors/revert/schema.json +7 -1
- package/dist/executors/run/executor.d.ts +1 -6
- package/dist/executors/run/executor.d.ts.map +1 -1
- package/dist/executors/run/executor.js +7 -18
- package/dist/executors/run/schema.json +6 -0
- package/dist/executors/schema-drop/executor.d.ts +6 -0
- package/dist/executors/schema-drop/executor.d.ts.map +1 -0
- package/dist/executors/schema-drop/executor.js +5 -0
- package/dist/executors/schema-drop/schema.json +28 -0
- package/dist/executors/schema-log/executor.d.ts +6 -0
- package/dist/executors/schema-log/executor.d.ts.map +1 -0
- package/dist/executors/schema-log/executor.js +5 -0
- package/dist/executors/schema-log/schema.json +28 -0
- package/dist/executors/schema-sync/executor.d.ts +6 -0
- package/dist/executors/schema-sync/executor.d.ts.map +1 -0
- package/dist/executors/schema-sync/executor.js +5 -0
- package/dist/executors/schema-sync/schema.json +28 -0
- package/dist/executors/seed/executor.d.ts +1 -7
- package/dist/executors/seed/executor.d.ts.map +1 -1
- package/dist/executors/seed/executor.js +1 -1
- package/dist/executors/subscriber-create/executor.d.ts +6 -0
- package/dist/executors/subscriber-create/executor.d.ts.map +1 -0
- package/dist/executors/subscriber-create/executor.js +13 -0
- package/dist/executors/subscriber-create/schema.json +23 -0
- package/dist/executors/version/executor.d.ts +6 -0
- package/dist/executors/version/executor.d.ts.map +1 -0
- package/dist/executors/version/executor.js +5 -0
- package/dist/executors/version/schema.json +14 -0
- package/dist/generators/bootstrap/files/app/env.example__tmpl__ +55 -1
- package/dist/generators/bootstrap/files/app/src/data-source.ts__tmpl__ +6 -0
- package/dist/generators/bootstrap/files/app/src/typeorm.datasource.ts__tmpl__ +1 -15
- package/dist/generators/bootstrap/files/app/tools/typeorm/connection-options.ts__tmpl__ +292 -0
- package/dist/generators/bootstrap/files/app/tools/typeorm/datasource.migrations.ts__tmpl__ +2 -7
- package/dist/generators/bootstrap/files/lib/project.json.partial__tmpl__ +3 -1
- package/dist/generators/bootstrap/generator.d.ts +5 -1
- package/dist/generators/bootstrap/generator.d.ts.map +1 -1
- package/dist/generators/bootstrap/generator.js +179 -31
- package/dist/generators/bootstrap/schema.json +18 -1
- package/dist/generators/entity-create/generator.d.ts +4 -0
- package/dist/generators/entity-create/generator.d.ts.map +1 -0
- package/dist/generators/entity-create/generator.js +70 -0
- package/dist/generators/entity-create/schema.json +28 -0
- package/dist/generators/init/generator.d.ts +4 -0
- package/dist/generators/init/generator.d.ts.map +1 -0
- package/dist/generators/init/generator.js +31 -0
- package/dist/generators/init/schema.json +18 -0
- package/dist/generators/migration-create/generator.d.ts +4 -0
- package/dist/generators/migration-create/generator.d.ts.map +1 -0
- package/dist/generators/migration-create/generator.js +72 -0
- package/dist/generators/migration-create/schema.json +40 -0
- package/dist/generators/subscriber-create/generator.d.ts +4 -0
- package/dist/generators/subscriber-create/generator.d.ts.map +1 -0
- package/dist/generators/subscriber-create/generator.js +70 -0
- package/dist/generators/subscriber-create/schema.json +28 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.json +72 -0
- package/dist/plugin/index.d.ts +9 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +241 -0
- package/dist/plugins/typeorm.d.ts +1 -6
- package/dist/plugins/typeorm.d.ts.map +1 -1
- package/dist/plugins/typeorm.js +1 -161
- package/dist/utils/cli.d.ts +17 -0
- package/dist/utils/cli.d.ts.map +1 -0
- package/dist/utils/cli.js +55 -0
- package/dist/{executors → utils}/shared.d.ts +12 -9
- package/dist/utils/shared.d.ts.map +1 -0
- package/dist/utils/shared.js +260 -0
- package/package.json +6 -7
- package/dist/executors/shared.d.ts.map +0 -1
- package/dist/executors/shared.js +0 -71
- package/dist/generators/bootstrap/files/app/tools/typeorm/datasource.runtime.ts__tmpl__ +0 -9
package/README.md
CHANGED
|
@@ -1,84 +1,244 @@
|
|
|
1
1
|
# @anarchitects/nx-typeorm
|
|
2
2
|
|
|
3
|
-
Nx plugin
|
|
4
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
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
|
+
- name-first scaffold generators for TypeORM file creation workflows.
|
|
10
|
+
- inferred database targets via `createNodesV2`.
|
|
11
|
+
- thin executors that wrap TypeORM CLI workflows.
|
|
15
12
|
|
|
16
13
|
## Installation
|
|
17
14
|
|
|
15
|
+
Use `nx add` so the plugin installs and runs `init` automatically:
|
|
16
|
+
|
|
18
17
|
```bash
|
|
19
|
-
|
|
18
|
+
nx add @anarchitects/nx-typeorm
|
|
20
19
|
```
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
This registers the plugin in `nx.json` and installs minimal dependencies:
|
|
22
|
+
`typeorm` and `reflect-metadata`.
|
|
23
|
+
|
|
24
|
+
You can re-run initialization later:
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
|
-
|
|
27
|
+
nx g @anarchitects/nx-typeorm:init
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
##
|
|
30
|
+
## Generators
|
|
29
31
|
|
|
30
|
-
###
|
|
32
|
+
### `init`
|
|
31
33
|
|
|
32
34
|
```bash
|
|
33
|
-
nx g @anarchitects/nx-typeorm:
|
|
35
|
+
nx g @anarchitects/nx-typeorm:init
|
|
34
36
|
```
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
`
|
|
38
|
+
- Registers `@anarchitects/nx-typeorm` in `nx.json > plugins`.
|
|
39
|
+
- Adds `typeorm` and `reflect-metadata`.
|
|
38
40
|
|
|
39
|
-
###
|
|
41
|
+
### `bootstrap`
|
|
40
42
|
|
|
41
43
|
```bash
|
|
42
|
-
nx
|
|
44
|
+
nx g @anarchitects/nx-typeorm:bootstrap --project=api
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
For applications:
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
- generates runtime datasource in `src/data-source.ts`.
|
|
50
|
+
- generates compatibility re-export `src/typeorm.datasource.ts`.
|
|
51
|
+
- generates shared connection helper `tools/typeorm/connection-options.ts`.
|
|
52
|
+
- generates TypeORM CLI migration datasource
|
|
53
|
+
`tools/typeorm/datasource.migrations.ts` and seeds under `tools/typeorm`.
|
|
54
|
+
- preserves an existing `tools/typeorm/datasource.migrations.ts` file.
|
|
55
|
+
- generates a DB-specific `env.example` with URL/discrete modes.
|
|
56
|
+
- patches `app.module.ts` only when the app has a Nest module file.
|
|
57
|
+
|
|
58
|
+
For libraries:
|
|
59
|
+
|
|
60
|
+
- generates `schema.ts` and `1700000000000_init_schema.ts` under
|
|
61
|
+
`src/infrastructure-persistence` by default.
|
|
62
|
+
- supports overrides with:
|
|
63
|
+
- `--schemaPath=<relative-path>`
|
|
64
|
+
- `--migrationsDir=<relative-dir>`
|
|
65
|
+
- patches project metadata (`metadata.typeorm`) with schema/domain and paths.
|
|
66
|
+
|
|
67
|
+
Additional bootstrap dependencies are installed during bootstrap:
|
|
68
|
+
`ts-node`, `typeorm-ts-node-commonjs`, `typeorm-ts-node-esm`,
|
|
69
|
+
DB driver package for selected `--db`, and `@nestjs/typeorm` only for Nest
|
|
70
|
+
applications.
|
|
71
|
+
|
|
72
|
+
Supported `--db` values: `postgres`, `postgresql` (normalized to `postgres`),
|
|
73
|
+
`mysql`, `mariadb`, `sqlite`, `better-sqlite3`, `mssql`.
|
|
74
|
+
|
|
75
|
+
Generated app datasources support two connection modes:
|
|
76
|
+
|
|
77
|
+
- `DATABASE_URL`
|
|
78
|
+
- discrete `TYPEORM_*` variables
|
|
79
|
+
|
|
80
|
+
The generated helper rejects mixed mode (setting `DATABASE_URL` together with
|
|
81
|
+
`TYPEORM_*` connection variables) and throws clear validation errors when
|
|
82
|
+
required variables are missing.
|
|
50
83
|
|
|
51
|
-
###
|
|
84
|
+
### Scaffolding generators
|
|
85
|
+
|
|
86
|
+
These are convenience wrappers around existing executors. They are invoked
|
|
87
|
+
manually via `nx g` and are not inferred targets.
|
|
88
|
+
|
|
89
|
+
`migration-create` (alias: `migration`)
|
|
52
90
|
|
|
53
91
|
```bash
|
|
54
|
-
nx
|
|
92
|
+
nx g @anarchitects/nx-typeorm:migration-create --project=api --name="add users"
|
|
93
|
+
nx g @anarchitects/nx-typeorm:migration --project=api --name="add users"
|
|
55
94
|
```
|
|
56
95
|
|
|
57
|
-
|
|
96
|
+
- required: `--project`, `--name`
|
|
97
|
+
- optional: `--directory` (relative to project root), `--outputJs`, `--esm`,
|
|
98
|
+
`--timestamp`, `--args`
|
|
99
|
+
- default output directory:
|
|
100
|
+
- app: `tools/typeorm/migrations`
|
|
101
|
+
- lib: `src/infrastructure-persistence/migrations`
|
|
102
|
+
|
|
103
|
+
`entity-create` (alias: `entity`)
|
|
58
104
|
|
|
59
105
|
```bash
|
|
60
|
-
|
|
106
|
+
nx g @anarchitects/nx-typeorm:entity-create --project=api --name="user profile"
|
|
107
|
+
nx g @anarchitects/nx-typeorm:entity --project=api --name="user profile"
|
|
61
108
|
```
|
|
62
109
|
|
|
63
|
-
|
|
110
|
+
- required: `--project`, `--name`
|
|
111
|
+
- optional: `--directory` (relative to project root), `--args`
|
|
112
|
+
- default output directory:
|
|
113
|
+
- app: `src/entities`
|
|
114
|
+
- lib: `src/infrastructure-persistence/entities`
|
|
115
|
+
|
|
116
|
+
`subscriber-create` (alias: `subscriber`)
|
|
64
117
|
|
|
65
118
|
```bash
|
|
66
|
-
nx
|
|
119
|
+
nx g @anarchitects/nx-typeorm:subscriber-create --project=api --name="user subscriber"
|
|
120
|
+
nx g @anarchitects/nx-typeorm:subscriber --project=api --name="user subscriber"
|
|
67
121
|
```
|
|
68
122
|
|
|
69
|
-
|
|
70
|
-
|
|
123
|
+
- required: `--project`, `--name`
|
|
124
|
+
- optional: `--directory` (relative to project root), `--args`
|
|
125
|
+
- default output directory:
|
|
126
|
+
- app: `src/subscribers`
|
|
127
|
+
- lib: `src/infrastructure-persistence/subscribers`
|
|
128
|
+
|
|
129
|
+
## Inferred Targets
|
|
130
|
+
|
|
131
|
+
When TypeORM files are detected, the plugin infers:
|
|
71
132
|
|
|
72
|
-
|
|
133
|
+
- `db:migrate:generate`
|
|
134
|
+
- `db:migrate:run`
|
|
135
|
+
- `db:migrate:revert`
|
|
136
|
+
- `db:migrate:show`
|
|
137
|
+
- `db:schema:sync`
|
|
138
|
+
- `db:schema:log`
|
|
139
|
+
- `db:cache:clear`
|
|
140
|
+
- `db:ensure-schema`
|
|
141
|
+
- `db:seed` (applications)
|
|
73
142
|
|
|
74
|
-
|
|
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.
|
|
143
|
+
Compatibility aliases are also inferred:
|
|
80
144
|
|
|
81
|
-
|
|
145
|
+
- `typeorm:generate`
|
|
146
|
+
- `typeorm:run`
|
|
147
|
+
- `typeorm:revert`
|
|
148
|
+
- `typeorm:show`
|
|
149
|
+
- `typeorm:schema:sync`
|
|
150
|
+
- `typeorm:schema:log`
|
|
151
|
+
- `typeorm:cache:clear`
|
|
152
|
+
- `typeorm:ensure-schema`
|
|
153
|
+
- `typeorm:seed` (applications)
|
|
82
154
|
|
|
83
|
-
|
|
84
|
-
|
|
155
|
+
## Executor Usage
|
|
156
|
+
|
|
157
|
+
Run inferred targets:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
nx run api:db:migrate:run --transaction=each
|
|
161
|
+
nx run api:db:migrate:generate --name AddUsers
|
|
162
|
+
nx run api:db:migrate:revert --count=2
|
|
163
|
+
nx run api:db:migrate:show
|
|
164
|
+
nx run api:db:schema:sync
|
|
165
|
+
nx run api:db:schema:log
|
|
166
|
+
nx run api:db:cache:clear
|
|
167
|
+
nx run data-access:db:ensure-schema
|
|
168
|
+
nx run api:db:seed --file tools/typeorm/seeds/index.ts
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`generate` supports `--check` and compatibility alias `--driftCheck` (mapped to
|
|
172
|
+
TypeORM check mode).
|
|
173
|
+
|
|
174
|
+
Datasource-backed CLI executors (`generate`, `run`, `revert`,
|
|
175
|
+
`migration-show`, `schema-sync`, `schema-log`, `schema-drop`, `query`,
|
|
176
|
+
`cache-clear`) select the TypeORM runner at runtime:
|
|
177
|
+
|
|
178
|
+
- `moduleSystem=auto` (default): detect by nearest `package.json` `type`,
|
|
179
|
+
then project tsconfig module mode, then fall back to CommonJS.
|
|
180
|
+
- `moduleSystem=commonjs`: force `typeorm-ts-node-commonjs`.
|
|
181
|
+
- `moduleSystem=esm`: force `typeorm-ts-node-esm`.
|
|
182
|
+
|
|
183
|
+
When `dataSource` is omitted, datasource-backed executors (`generate`, `run`,
|
|
184
|
+
`revert`, `migration-show`, `schema-sync`, `schema-log`, `schema-drop`,
|
|
185
|
+
`query`, `cache-clear`) and `ensure-schema` infer it from the project with
|
|
186
|
+
this priority:
|
|
187
|
+
|
|
188
|
+
1. `tools/typeorm/datasource.migrations.ts`
|
|
189
|
+
2. `tools/typeorm/datasource.migrations.js`
|
|
190
|
+
3. `src/data-source.ts`
|
|
191
|
+
4. `src/data-source.js`
|
|
192
|
+
5. `src/typeorm.datasource.ts`
|
|
193
|
+
6. `src/typeorm.datasource.js`
|
|
194
|
+
|
|
195
|
+
Override inference at any time with `--dataSource=<relative-or-absolute-path>`.
|
|
196
|
+
|
|
197
|
+
## TypeORM CLI Coverage
|
|
198
|
+
|
|
199
|
+
Inference is intentionally limited to convention-safe operational commands.
|
|
200
|
+
Scaffolding/meta commands (`migration:create`, `entity:create`,
|
|
201
|
+
`subscriber:create`, `version`, `init`) are executor-only and not inferred.
|
|
202
|
+
|
|
203
|
+
| TypeORM CLI command | nx-typeorm executor | Inferred target |
|
|
204
|
+
| -------------------- | ------------------- | --------------- |
|
|
205
|
+
| `migration:create` | `migration-create` | no |
|
|
206
|
+
| `migration:generate` | `generate` | yes |
|
|
207
|
+
| `migration:run` | `run` | yes |
|
|
208
|
+
| `migration:revert` | `revert` | yes |
|
|
209
|
+
| `migration:show` | `migration-show` | yes |
|
|
210
|
+
| `schema:sync` | `schema-sync` | yes |
|
|
211
|
+
| `schema:log` | `schema-log` | yes |
|
|
212
|
+
| `schema:drop` | `schema-drop` | no |
|
|
213
|
+
| `query` | `query` | no |
|
|
214
|
+
| `cache:clear` | `cache-clear` | yes |
|
|
215
|
+
| `entity:create` | `entity-create` | no |
|
|
216
|
+
| `subscriber:create` | `subscriber-create` | no |
|
|
217
|
+
| `version` | `version` | no |
|
|
218
|
+
| `init` | `init` | no |
|
|
219
|
+
|
|
220
|
+
Manual-only executors are available for explicit wiring in `project.json`.
|
|
221
|
+
This includes risky commands (`query`, `schema:drop`) and non-inferred
|
|
222
|
+
scaffolding/meta commands from the table above.
|
|
223
|
+
|
|
224
|
+
Example manual targets:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"targets": {
|
|
229
|
+
"db:query": {
|
|
230
|
+
"executor": "@anarchitects/nx-typeorm:query",
|
|
231
|
+
"options": {
|
|
232
|
+
"projectRoot": "apps/api",
|
|
233
|
+
"query": "SELECT 1"
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
"db:schema:drop": {
|
|
237
|
+
"executor": "@anarchitects/nx-typeorm:schema-drop",
|
|
238
|
+
"options": {
|
|
239
|
+
"projectRoot": "apps/api"
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
@@ -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,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 {
|
|
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;
|
|
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 '
|
|
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 {
|
|
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;
|
|
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 {
|
|
4
|
-
import {
|
|
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
|
|
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
|
|
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
|
-
|
|
17
|
+
afterDataSourceArgs.push('--pretty');
|
|
32
18
|
}
|
|
33
|
-
if (options.driftCheck) {
|
|
34
|
-
|
|
19
|
+
if (options.driftCheck || options.check) {
|
|
20
|
+
afterDataSourceArgs.push('--check');
|
|
35
21
|
}
|
|
36
|
-
|
|
37
|
-
|
|
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": "
|
|
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
|
+
}
|