@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
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
|
+
const MIGRATION_DATASOURCE_CANDIDATES = [
|
|
5
|
+
'tools/typeorm/datasource.migrations.ts',
|
|
6
|
+
'tools/typeorm/datasource.migrations.js',
|
|
7
|
+
];
|
|
8
|
+
const LEGACY_RUNTIME_DATASOURCE_CANDIDATES = [
|
|
9
|
+
'src/data-source.ts',
|
|
10
|
+
'src/data-source.js',
|
|
11
|
+
'src/typeorm.datasource.ts',
|
|
12
|
+
'src/typeorm.datasource.js',
|
|
13
|
+
];
|
|
14
|
+
const CANDIDATE_DATASOURCES = [
|
|
15
|
+
...MIGRATION_DATASOURCE_CANDIDATES,
|
|
16
|
+
...LEGACY_RUNTIME_DATASOURCE_CANDIDATES,
|
|
17
|
+
];
|
|
18
|
+
const DEFAULT_TS_CONFIG_NAMES = [
|
|
19
|
+
'tsconfig.app.json',
|
|
20
|
+
'tsconfig.lib.json',
|
|
21
|
+
'tsconfig.build.json',
|
|
22
|
+
'tsconfig.json',
|
|
23
|
+
];
|
|
24
|
+
const ESM_RUNNER = 'typeorm-ts-node-esm';
|
|
25
|
+
const CJS_RUNNER = 'typeorm-ts-node-commonjs';
|
|
26
|
+
const requireFromExecutor = createRequire(import.meta.url);
|
|
27
|
+
export function ensureProjectRoot(options, context) {
|
|
28
|
+
const { projectRoot, absoluteProjectRoot } = resolveProjectRoot(options.projectRoot, context);
|
|
29
|
+
const dataSource = resolveDataSource(options.dataSource, absoluteProjectRoot);
|
|
30
|
+
return { projectRoot, absoluteProjectRoot, dataSource };
|
|
31
|
+
}
|
|
32
|
+
export function resolveTypeormCliRunner(options, context, absoluteProjectRoot) {
|
|
33
|
+
const moduleSystem = detectModuleSystem(options, context, absoluteProjectRoot);
|
|
34
|
+
const runner = moduleSystem === 'esm' ? ESM_RUNNER : CJS_RUNNER;
|
|
35
|
+
assertRunnerInstalled(runner, context.root);
|
|
36
|
+
return runner;
|
|
37
|
+
}
|
|
38
|
+
export function resolveProjectRoot(configuredRoot, context) {
|
|
39
|
+
const projectConfig = context.projectsConfigurations?.projects?.[context.projectName ?? ''];
|
|
40
|
+
const projectRoot = configuredRoot ?? projectConfig?.root;
|
|
41
|
+
if (!projectRoot) {
|
|
42
|
+
throw new Error('Unable to determine project root. Provide projectRoot.');
|
|
43
|
+
}
|
|
44
|
+
const absoluteProjectRoot = isAbsolute(projectRoot)
|
|
45
|
+
? projectRoot
|
|
46
|
+
: resolve(context.root, projectRoot);
|
|
47
|
+
return { projectRoot, absoluteProjectRoot };
|
|
48
|
+
}
|
|
49
|
+
function detectModuleSystem(options, context, absoluteProjectRoot) {
|
|
50
|
+
if (options.moduleSystem === 'commonjs' || options.moduleSystem === 'esm') {
|
|
51
|
+
return options.moduleSystem;
|
|
52
|
+
}
|
|
53
|
+
const packageModuleSystem = moduleSystemFromNearestPackageJson(context.root, absoluteProjectRoot);
|
|
54
|
+
if (packageModuleSystem) {
|
|
55
|
+
return packageModuleSystem;
|
|
56
|
+
}
|
|
57
|
+
if (moduleSystemFromProjectTsConfig(context, absoluteProjectRoot) === 'esm') {
|
|
58
|
+
return 'esm';
|
|
59
|
+
}
|
|
60
|
+
return 'commonjs';
|
|
61
|
+
}
|
|
62
|
+
function moduleSystemFromNearestPackageJson(workspaceRoot, absoluteProjectRoot) {
|
|
63
|
+
const resolvedWorkspaceRoot = resolve(workspaceRoot);
|
|
64
|
+
let currentDir = absoluteProjectRoot;
|
|
65
|
+
while (isWithinOrEqual(currentDir, resolvedWorkspaceRoot)) {
|
|
66
|
+
const packageJsonPath = join(currentDir, 'package.json');
|
|
67
|
+
if (existsSync(packageJsonPath)) {
|
|
68
|
+
try {
|
|
69
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
70
|
+
if (packageJson.type === 'module') {
|
|
71
|
+
return 'esm';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// best effort: ignore malformed package.json files
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (currentDir === resolvedWorkspaceRoot) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const parentDir = dirname(currentDir);
|
|
82
|
+
if (parentDir === currentDir) {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
currentDir = parentDir;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
function moduleSystemFromProjectTsConfig(context, absoluteProjectRoot) {
|
|
90
|
+
const candidates = tsConfigCandidates(context, absoluteProjectRoot);
|
|
91
|
+
for (const tsConfigPath of candidates) {
|
|
92
|
+
if (isEsmTsConfig(tsConfigPath, new Set())) {
|
|
93
|
+
return 'esm';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
function tsConfigCandidates(context, absoluteProjectRoot) {
|
|
99
|
+
const candidates = new Set();
|
|
100
|
+
for (const name of DEFAULT_TS_CONFIG_NAMES) {
|
|
101
|
+
candidates.add(resolve(absoluteProjectRoot, name));
|
|
102
|
+
}
|
|
103
|
+
const projectConfig = getProjectConfiguration(context);
|
|
104
|
+
const targets = projectConfig?.targets;
|
|
105
|
+
if (targets) {
|
|
106
|
+
for (const target of Object.values(targets)) {
|
|
107
|
+
collectTsConfigPathsFromObject(target.options, context, absoluteProjectRoot, candidates);
|
|
108
|
+
const configurations = target.configurations;
|
|
109
|
+
if (!configurations) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
for (const configuration of Object.values(configurations)) {
|
|
113
|
+
collectTsConfigPathsFromObject(configuration, context, absoluteProjectRoot, candidates);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return [...candidates].filter((pathValue) => existsSync(pathValue));
|
|
118
|
+
}
|
|
119
|
+
function collectTsConfigPathsFromObject(value, context, absoluteProjectRoot, candidates) {
|
|
120
|
+
if (!value) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const tsConfigValue = value.tsConfig;
|
|
124
|
+
if (typeof tsConfigValue !== 'string' || tsConfigValue.trim().length === 0) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const normalized = tsConfigValue.trim();
|
|
128
|
+
if (isAbsolute(normalized)) {
|
|
129
|
+
candidates.add(normalized);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const workspaceRelative = resolve(context.root, normalized);
|
|
133
|
+
if (existsSync(workspaceRelative)) {
|
|
134
|
+
candidates.add(workspaceRelative);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
candidates.add(resolve(absoluteProjectRoot, normalized));
|
|
138
|
+
}
|
|
139
|
+
function isEsmTsConfig(tsConfigPath, seen) {
|
|
140
|
+
const resolvedPath = resolve(tsConfigPath);
|
|
141
|
+
if (seen.has(resolvedPath) || !existsSync(resolvedPath)) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
seen.add(resolvedPath);
|
|
145
|
+
let contents = '';
|
|
146
|
+
try {
|
|
147
|
+
contents = readFileSync(resolvedPath, 'utf-8');
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const moduleValue = extractCompilerModule(contents);
|
|
153
|
+
if (moduleValue && isEsmModule(moduleValue)) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
const extendsValue = extractExtends(contents);
|
|
157
|
+
if (!extendsValue) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const extendedTsConfigPath = resolveExtendedTsConfigPath(extendsValue, dirname(resolvedPath));
|
|
161
|
+
if (!extendedTsConfigPath) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return isEsmTsConfig(extendedTsConfigPath, seen);
|
|
165
|
+
}
|
|
166
|
+
function extractCompilerModule(contents) {
|
|
167
|
+
const moduleMatch = contents.match(/"module"\s*:\s*"([^"]+)"/i);
|
|
168
|
+
return moduleMatch?.[1]?.trim();
|
|
169
|
+
}
|
|
170
|
+
function extractExtends(contents) {
|
|
171
|
+
const extendsMatch = contents.match(/"extends"\s*:\s*"([^"]+)"/i);
|
|
172
|
+
return extendsMatch?.[1]?.trim();
|
|
173
|
+
}
|
|
174
|
+
function resolveExtendedTsConfigPath(extendsValue, currentDirectory) {
|
|
175
|
+
if (!extendsValue.startsWith('.') && !extendsValue.startsWith('/')) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
const basePath = extendsValue.startsWith('/')
|
|
179
|
+
? extendsValue
|
|
180
|
+
: resolve(currentDirectory, extendsValue);
|
|
181
|
+
const candidates = [
|
|
182
|
+
basePath,
|
|
183
|
+
`${basePath}.json`,
|
|
184
|
+
join(basePath, 'tsconfig.json'),
|
|
185
|
+
];
|
|
186
|
+
for (const candidate of candidates) {
|
|
187
|
+
if (existsSync(candidate)) {
|
|
188
|
+
return candidate;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
function isEsmModule(moduleValue) {
|
|
194
|
+
const normalized = moduleValue.toLowerCase();
|
|
195
|
+
if (normalized === 'esnext' ||
|
|
196
|
+
normalized === 'node16' ||
|
|
197
|
+
normalized === 'node18' ||
|
|
198
|
+
normalized === 'node20' ||
|
|
199
|
+
normalized === 'nodenext') {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (!normalized.startsWith('es20')) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const year = Number(normalized.slice(2));
|
|
206
|
+
return Number.isFinite(year) && year >= 2020;
|
|
207
|
+
}
|
|
208
|
+
function assertRunnerInstalled(runner, workspaceRoot) {
|
|
209
|
+
try {
|
|
210
|
+
requireFromExecutor.resolve(`${runner}/package.json`, {
|
|
211
|
+
paths: [workspaceRoot],
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
throw new Error(`TypeORM CLI runner "${runner}" is not installed. Install "${runner}" (or run @anarchitects/nx-typeorm:bootstrap) or set moduleSystem to a compatible value.`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function isWithinOrEqual(pathValue, rootPath) {
|
|
219
|
+
const rel = relative(rootPath, pathValue);
|
|
220
|
+
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
|
|
221
|
+
}
|
|
222
|
+
function getProjectConfiguration(context) {
|
|
223
|
+
return context.projectsConfigurations?.projects?.[context.projectName ?? ''];
|
|
224
|
+
}
|
|
225
|
+
function resolveDataSource(explicit, absoluteProjectRoot) {
|
|
226
|
+
if (explicit) {
|
|
227
|
+
return absoluteFrom(explicit, absoluteProjectRoot);
|
|
228
|
+
}
|
|
229
|
+
for (const candidate of CANDIDATE_DATASOURCES) {
|
|
230
|
+
const absoluteCandidate = join(absoluteProjectRoot, candidate);
|
|
231
|
+
if (existsSync(absoluteCandidate)) {
|
|
232
|
+
return absoluteCandidate;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
throw new Error('Unable to locate a TypeORM data source. Add one or pass the dataSource option.');
|
|
236
|
+
}
|
|
237
|
+
function absoluteFrom(pathValue, absoluteProjectRoot) {
|
|
238
|
+
return isAbsolute(pathValue)
|
|
239
|
+
? pathValue
|
|
240
|
+
: resolve(absoluteProjectRoot, pathValue);
|
|
241
|
+
}
|
|
242
|
+
export function defaultMigrationsDirectory(projectRoot, projectType) {
|
|
243
|
+
if (projectType === 'application') {
|
|
244
|
+
return join(projectRoot, 'tools/typeorm/migrations');
|
|
245
|
+
}
|
|
246
|
+
return join(projectRoot, 'src/infrastructure-persistence/migrations');
|
|
247
|
+
}
|
|
248
|
+
export function projectTypeFor(context) {
|
|
249
|
+
return getProjectConfiguration(context)?.projectType;
|
|
250
|
+
}
|
|
251
|
+
export function schemaFilePath(projectRoot) {
|
|
252
|
+
return join(projectRoot, 'src/infrastructure-persistence/schema.ts');
|
|
253
|
+
}
|
|
254
|
+
export function schemaNameFrom(contents) {
|
|
255
|
+
const match = contents.match(/SCHEMA\s*=\s*['"]([^'"\s]+)['"]/);
|
|
256
|
+
return match?.[1];
|
|
257
|
+
}
|
|
258
|
+
export function normalizeName(name) {
|
|
259
|
+
return name.replace(/\s+/g, '-');
|
|
260
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anarchitects/nx-typeorm",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Nx plugin providing TypeORM executors, generators, and schema management utilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"name": "nx-typeorm",
|
|
26
26
|
"plugins": [
|
|
27
27
|
{
|
|
28
|
-
"plugin": "dist/
|
|
28
|
+
"plugin": "dist/plugin/index.js"
|
|
29
29
|
}
|
|
30
30
|
],
|
|
31
31
|
"targets": {
|
|
@@ -62,14 +62,13 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@nx/devkit": "^22.
|
|
66
|
-
"nx": "22.0.1",
|
|
65
|
+
"@nx/devkit": "^22.5.3",
|
|
67
66
|
"ts-morph": "^22.0.0",
|
|
68
|
-
"ts-node": "10.9.1",
|
|
69
|
-
"typeorm": "^0.3.
|
|
67
|
+
"ts-node": "^10.9.1",
|
|
68
|
+
"typeorm": "^0.3.27"
|
|
70
69
|
},
|
|
71
70
|
"dependencies": {
|
|
72
|
-
"tslib": "^2.
|
|
71
|
+
"tslib": "^2.8.1"
|
|
73
72
|
},
|
|
74
73
|
"devDependencies": {
|
|
75
74
|
"ts-morph": "^22.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/executors/shared.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB;AASD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,eAAe,GACvB,cAAc,CAShB;AAED,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,OAAO,EAAE,eAAe,GACvB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,CActD;AA4BD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAGhE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,aAAa,GAAG,SAAS,GAAG,SAAS,GACjD,MAAM,CAMR;AAED,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEvD;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,GACvB,aAAa,GAAG,SAAS,GAAG,SAAS,CAGvC;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGnE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
package/dist/executors/shared.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
const CANDIDATE_DATASOURCES = [
|
|
4
|
-
'tools/typeorm/datasource.migrations.ts',
|
|
5
|
-
'tools/typeorm/datasource.migrations.js',
|
|
6
|
-
'src/typeorm.datasource.ts',
|
|
7
|
-
'src/typeorm.datasource.js',
|
|
8
|
-
];
|
|
9
|
-
export function ensureProjectRoot(options, context) {
|
|
10
|
-
const { projectRoot, absoluteProjectRoot } = resolveProjectRoot(options.projectRoot, context);
|
|
11
|
-
const dataSource = resolveDataSource(options.dataSource, absoluteProjectRoot);
|
|
12
|
-
return { projectRoot, absoluteProjectRoot, dataSource };
|
|
13
|
-
}
|
|
14
|
-
export function resolveProjectRoot(configuredRoot, context) {
|
|
15
|
-
const projectConfig = context.projectsConfigurations?.projects?.[context.projectName ?? ''];
|
|
16
|
-
const projectRoot = configuredRoot ?? projectConfig?.root;
|
|
17
|
-
if (!projectRoot) {
|
|
18
|
-
throw new Error('Unable to determine project root. Provide projectRoot.');
|
|
19
|
-
}
|
|
20
|
-
const absoluteProjectRoot = isAbsolute(projectRoot)
|
|
21
|
-
? projectRoot
|
|
22
|
-
: resolve(context.root, projectRoot);
|
|
23
|
-
return { projectRoot, absoluteProjectRoot };
|
|
24
|
-
}
|
|
25
|
-
function resolveDataSource(explicit, absoluteProjectRoot) {
|
|
26
|
-
if (explicit) {
|
|
27
|
-
return absoluteFrom(explicit, absoluteProjectRoot);
|
|
28
|
-
}
|
|
29
|
-
for (const candidate of CANDIDATE_DATASOURCES) {
|
|
30
|
-
const absoluteCandidate = join(absoluteProjectRoot, candidate);
|
|
31
|
-
if (existsSync(absoluteCandidate)) {
|
|
32
|
-
return absoluteCandidate;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
throw new Error('Unable to locate a TypeORM data source. Add one or pass the dataSource option.');
|
|
36
|
-
}
|
|
37
|
-
function absoluteFrom(pathValue, absoluteProjectRoot) {
|
|
38
|
-
return isAbsolute(pathValue)
|
|
39
|
-
? pathValue
|
|
40
|
-
: resolve(absoluteProjectRoot, pathValue);
|
|
41
|
-
}
|
|
42
|
-
export function splitCommand(command) {
|
|
43
|
-
const [cmd, ...rest] = command.split(' ');
|
|
44
|
-
return [cmd, rest];
|
|
45
|
-
}
|
|
46
|
-
export function relativeToWorkspace(root, filePath) {
|
|
47
|
-
return relative(root, filePath) || '.';
|
|
48
|
-
}
|
|
49
|
-
export function defaultMigrationsDirectory(projectRoot, projectType) {
|
|
50
|
-
if (projectType === 'application') {
|
|
51
|
-
return join(projectRoot, 'tools/typeorm/migrations');
|
|
52
|
-
}
|
|
53
|
-
return join(projectRoot, 'src/infrastructure-persistence/migrations');
|
|
54
|
-
}
|
|
55
|
-
export function ensureArgs(options) {
|
|
56
|
-
return options?.filter((arg) => arg.trim().length > 0) ?? [];
|
|
57
|
-
}
|
|
58
|
-
export function projectTypeFor(context) {
|
|
59
|
-
return context.projectsConfigurations?.projects?.[context.projectName ?? '']
|
|
60
|
-
?.projectType;
|
|
61
|
-
}
|
|
62
|
-
export function schemaFilePath(projectRoot) {
|
|
63
|
-
return join(projectRoot, 'src/infrastructure-persistence/schema.ts');
|
|
64
|
-
}
|
|
65
|
-
export function schemaNameFrom(contents) {
|
|
66
|
-
const match = contents.match(/SCHEMA\s*=\s*['"]([^'"\s]+)['"]/);
|
|
67
|
-
return match?.[1];
|
|
68
|
-
}
|
|
69
|
-
export function normalizeName(name) {
|
|
70
|
-
return name.replace(/\s+/g, '-');
|
|
71
|
-
}
|