angular-typed-router 0.1.1-0 → 0.1.1-2
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 +5 -5
- package/index.d.ts +5 -3
- package/package.json +12 -3
- package/schematics/collection.json +15 -0
- package/schematics/index.d.ts +1 -0
- package/schematics/index.js +5 -0
- package/schematics/index.js.map +1 -0
- package/schematics/migrate/index.d.ts +3 -0
- package/schematics/migrate/index.js +10 -0
- package/schematics/migrate/index.js.map +1 -0
- package/schematics/migrate/schema.d.ts +16 -0
- package/schematics/migrate/schema.js +4 -0
- package/schematics/migrate/schema.js.map +1 -0
- package/schematics/migrate/schema.json +26 -0
- package/schematics/migrate/steps/replace-usages.d.ts +3 -0
- package/schematics/migrate/steps/replace-usages.js +208 -0
- package/schematics/migrate/steps/replace-usages.js.map +1 -0
- package/schematics/ng-add/index.d.ts +3 -0
- package/schematics/ng-add/index.js +22 -0
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/ng-add/schema.d.ts +18 -0
- package/schematics/ng-add/schema.js +5 -0
- package/schematics/ng-add/schema.js.map +1 -0
- package/schematics/ng-add/schema.json +26 -0
- package/schematics/ng-add/steps/add-declaration-file.d.ts +3 -0
- package/schematics/ng-add/steps/add-declaration-file.js +64 -0
- package/schematics/ng-add/steps/add-declaration-file.js.map +1 -0
- package/schematics/ng-add/steps/inform-user.d.ts +2 -0
- package/schematics/ng-add/steps/inform-user.js +14 -0
- package/schematics/ng-add/steps/inform-user.js.map +1 -0
- package/schematics/ng-add/steps/run-migrate.d.ts +3 -0
- package/schematics/ng-add/steps/run-migrate.js +16 -0
- package/schematics/ng-add/steps/run-migrate.js.map +1 -0
- package/schematics/ng-add/steps/update-route-declarations.d.ts +3 -0
- package/schematics/ng-add/steps/update-route-declarations.js +79 -0
- package/schematics/ng-add/steps/update-route-declarations.js.map +1 -0
- package/schematics/utils/handle-uncommitted-changes.d.ts +3 -0
- package/schematics/utils/handle-uncommitted-changes.js +41 -0
- package/schematics/utils/handle-uncommitted-changes.js.map +1 -0
package/README.md
CHANGED
|
@@ -49,6 +49,11 @@ declare module 'angular-typed-router' {
|
|
|
49
49
|
interface UserTypedRoutes {
|
|
50
50
|
routes: typeof appRoutes;
|
|
51
51
|
}
|
|
52
|
+
// Customize route param types here
|
|
53
|
+
interface AllowedRouteParamValues {
|
|
54
|
+
ids: `${number}`;
|
|
55
|
+
// other params...
|
|
56
|
+
}
|
|
52
57
|
}
|
|
53
58
|
```
|
|
54
59
|
|
|
@@ -177,8 +182,6 @@ Keep the augmentation in a `.d.ts` that is included by `tsconfig.app.json` (`inc
|
|
|
177
182
|
|
|
178
183
|
| Concern | Status / Rationale |
|
|
179
184
|
|---------|---------------------------------------------------------------------------------------|
|
|
180
|
-
| Restrict param values (non-empty) | Not enforced; doing so significantly worsens DX (would reject plain `string` vars). |
|
|
181
|
-
| Trailing slashes | Not generated unless authored; currently no auto-normalization. |
|
|
182
185
|
| `relativeTo` (relative navigation) | Not supported – all inferred `Path` / `Commands` are absolute. Use absolute commands. |
|
|
183
186
|
|
|
184
187
|
|
|
@@ -186,15 +189,12 @@ Keep the augmentation in a `.d.ts` that is included by `tsconfig.app.json` (`inc
|
|
|
186
189
|
|
|
187
190
|
You can use `angular-typed-router-eslint` plugin to forbid untyped navigation calls.
|
|
188
191
|
|
|
189
|
-
```bash
|
|
190
|
-
|
|
191
192
|
## Troubleshooting
|
|
192
193
|
|
|
193
194
|
| Symptom | Fix |
|
|
194
195
|
|---------|-----|
|
|
195
196
|
| `Path` is `never` | Check augmentation file is included in tsconfig. |
|
|
196
197
|
| Lazy children missing | Ensure promise resolves to `Route[]` or `{ routes: Route[] }`. |
|
|
197
|
-
| Template error: unknown routerLink type | Ensure `TypedRouterLink` directive is imported (standalone). |
|
|
198
198
|
|
|
199
199
|
## Contributing
|
|
200
200
|
|
package/index.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ declare const __rootCatchAll: unique symbol;
|
|
|
16
16
|
type RootCatchAll = string & {
|
|
17
17
|
readonly [__rootCatchAll]: true;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
interface AllowedRouteParamValues {
|
|
20
|
+
}
|
|
21
|
+
type AllowedRouteParamValue = AllowedRouteParamValues[keyof AllowedRouteParamValues];
|
|
22
|
+
type _ReplaceParams<S extends string> = S extends `${infer Start}:${string}/${infer Rest}` ? `${Start}${AllowedRouteParamValue}/${_ReplaceParams<Rest>}` : S extends `${infer Start}:${string}` ? `${Start}${AllowedRouteParamValue}` : S extends `${infer Start}**/${infer Rest}` ? `${Start}${string}/${_ReplaceParams<Rest>}` : S extends `${infer Start}**` ? Start extends '' ? RootCatchAll : `${Start}${string}` : S;
|
|
21
23
|
type ReplaceParams<S extends string> = _ReplaceParams<S>;
|
|
22
24
|
|
|
23
25
|
type PathOrEmptyString<R extends Route> = R['path'] extends string ? R['path'] : '';
|
|
@@ -63,4 +65,4 @@ declare class TypedRouterLink extends RouterLink {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export { TypedRouter, TypedRouterLink };
|
|
66
|
-
export type { Commands, ExtractPathsFromRoutes, Path, UserTypedRoutes };
|
|
68
|
+
export type { AllowedRouteParamValues, Commands, ExtractPathsFromRoutes, Path, UserTypedRoutes };
|
package/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "angular-typed-router",
|
|
3
|
-
"version": "0.1.1-
|
|
3
|
+
"version": "0.1.1-2",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@angular/common": "^20.
|
|
6
|
-
"@angular/core": "^20.
|
|
5
|
+
"@angular/common": "^20.0.0",
|
|
6
|
+
"@angular/core": "^20.0.0"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/dominicbachmann/angular-typed-router.git",
|
|
11
|
+
"directory": "libs/typed-router"
|
|
7
12
|
},
|
|
8
13
|
"sideEffects": false,
|
|
14
|
+
"schematics": "./schematics/collection.json",
|
|
15
|
+
"ng-add": {
|
|
16
|
+
"save": "dependencies"
|
|
17
|
+
},
|
|
9
18
|
"module": "fesm2022/angular-typed-router.mjs",
|
|
10
19
|
"typings": "index.d.ts",
|
|
11
20
|
"exports": {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
|
+
"schematics": {
|
|
4
|
+
"ng-add": {
|
|
5
|
+
"description": "Add angular-typed-router to the project.",
|
|
6
|
+
"factory": "./ng-add/index#ngAdd",
|
|
7
|
+
"schema": "./ng-add/schema.json"
|
|
8
|
+
},
|
|
9
|
+
"migrate": {
|
|
10
|
+
"description": "Migrate from @angular/router to angular-typed-router",
|
|
11
|
+
"factory": "./migrate/index#migrate",
|
|
12
|
+
"schema": "./migrate/schema.json"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './collection.json';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/typed-router/schematics/index.ts"],"names":[],"mappings":";;AAAA,wEAAwE;AACxE,6BAA2B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrate = migrate;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const handle_uncommitted_changes_1 = require("../utils/handle-uncommitted-changes");
|
|
6
|
+
const replace_usages_1 = require("./steps/replace-usages");
|
|
7
|
+
function migrate(options) {
|
|
8
|
+
return (0, schematics_1.chain)([(0, handle_uncommitted_changes_1.handleUncommittedChanges)(options), (0, replace_usages_1.replaceUsages)(options)]);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/typed-router/schematics/migrate/index.ts"],"names":[],"mappings":";;AAKA,0BAEC;AAPD,2DAAyD;AAEzD,oFAA+E;AAC/E,2DAAuD;AAEvD,SAAgB,OAAO,CAAC,OAAe;IACrC,OAAO,IAAA,kBAAK,EAAC,CAAC,IAAA,qDAAwB,EAAC,OAAO,CAAC,EAAE,IAAA,8BAAa,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import './schema.json';
|
|
2
|
+
export interface Schema {
|
|
3
|
+
/**
|
|
4
|
+
* The name of the project to migrate.
|
|
5
|
+
*/
|
|
6
|
+
project: string;
|
|
7
|
+
/**
|
|
8
|
+
* Path to the project source files.
|
|
9
|
+
* If not specified, the project source root will be used.
|
|
10
|
+
*/
|
|
11
|
+
path?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to allow the migration to run even if there are uncommitted Git changes.
|
|
14
|
+
*/
|
|
15
|
+
allowDirty?: boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../libs/typed-router/schematics/migrate/schema.ts"],"names":[],"mappings":";;AAAA,yBAAuB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "migrate-to-angular-typed-router",
|
|
4
|
+
"title": "Angular Typed Router Migration",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"project": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The name of the project to migrate.",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "projectName"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"path": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Path to the project source files. If not specified, the project source root will be used.",
|
|
17
|
+
"format": "path"
|
|
18
|
+
},
|
|
19
|
+
"allowDirty": {
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"description": "Whether to allow the migration to run even if there are uncommitted Git changes.",
|
|
22
|
+
"default": false
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"required": ["project"]
|
|
26
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Schema } from '../schema';
|
|
2
|
+
import { SchematicContext, Tree } from '@angular-devkit/schematics';
|
|
3
|
+
export declare const replaceUsages: (options: Schema) => (tree: Tree, context: SchematicContext) => Promise<import("@angular-devkit/schematics/src/tree/interface").Tree>;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.replaceUsages = void 0;
|
|
13
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
14
|
+
const utility_1 = require("@schematics/angular/utility");
|
|
15
|
+
const ts = require("typescript");
|
|
16
|
+
const replaceUsages = (options) => (tree, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const workspace = yield (0, utility_1.readWorkspace)(tree);
|
|
18
|
+
const project = workspace.projects.get(options.project);
|
|
19
|
+
if (!project) {
|
|
20
|
+
throw new schematics_1.SchematicsException(`Project "${options.project}" not found.`);
|
|
21
|
+
}
|
|
22
|
+
const sourceRoot = options.path || project.sourceRoot;
|
|
23
|
+
if (!sourceRoot) {
|
|
24
|
+
throw new schematics_1.SchematicsException(`Could not determine source root for project "${options.project}".`);
|
|
25
|
+
}
|
|
26
|
+
context.logger.info(`Migrating Angular Router imports in ${sourceRoot}...`);
|
|
27
|
+
const importMappings = [
|
|
28
|
+
{
|
|
29
|
+
oldImport: 'Router',
|
|
30
|
+
newImport: 'TypedRouter',
|
|
31
|
+
fromModule: '@angular/router',
|
|
32
|
+
toModule: 'angular-typed-router',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
oldImport: 'RouterLink',
|
|
36
|
+
newImport: 'TypedRouterLink',
|
|
37
|
+
fromModule: '@angular/router',
|
|
38
|
+
toModule: 'angular-typed-router',
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
const tsFiles = getTypeScriptFiles(tree, sourceRoot);
|
|
42
|
+
for (const filePath of tsFiles) {
|
|
43
|
+
migrateFile(tree, filePath, importMappings);
|
|
44
|
+
}
|
|
45
|
+
context.logger.info('Migration complete!');
|
|
46
|
+
return tree;
|
|
47
|
+
});
|
|
48
|
+
exports.replaceUsages = replaceUsages;
|
|
49
|
+
function getTypeScriptFiles(tree, rootPath) {
|
|
50
|
+
const files = [];
|
|
51
|
+
function getFilesRecursively(path) {
|
|
52
|
+
const dir = tree.getDir(path);
|
|
53
|
+
const entries = dir.subfiles;
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
if (entry.endsWith('.ts') &&
|
|
56
|
+
!entry.endsWith('.d.ts') &&
|
|
57
|
+
!entry.endsWith('.spec.ts')) {
|
|
58
|
+
files.push(`${path}/${entry}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const directories = dir.subdirs;
|
|
62
|
+
for (const directory of directories) {
|
|
63
|
+
getFilesRecursively(`${path}/${directory}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
getFilesRecursively(rootPath);
|
|
67
|
+
return files;
|
|
68
|
+
}
|
|
69
|
+
function migrateFile(tree, filePath, mappings) {
|
|
70
|
+
const content = tree.read(filePath);
|
|
71
|
+
if (!content) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const sourceText = content.toString('utf-8');
|
|
75
|
+
const sourceFile = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
76
|
+
let updatedSourceText = sourceText;
|
|
77
|
+
let hasChanged = false;
|
|
78
|
+
const importsToAdd = new Map();
|
|
79
|
+
const importsToRemove = new Set();
|
|
80
|
+
const componentImportsToReplace = new Map();
|
|
81
|
+
sourceFile.forEachChild((node) => {
|
|
82
|
+
if (ts.isImportDeclaration(node)) {
|
|
83
|
+
const moduleSpecifier = node.moduleSpecifier;
|
|
84
|
+
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
85
|
+
const moduleName = moduleSpecifier.text;
|
|
86
|
+
if (moduleName === '@angular/router') {
|
|
87
|
+
if (node.importClause && node.importClause.namedBindings) {
|
|
88
|
+
const namedBindings = node.importClause.namedBindings;
|
|
89
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
90
|
+
const importSpecifiers = namedBindings.elements;
|
|
91
|
+
for (const specifier of importSpecifiers) {
|
|
92
|
+
const importName = specifier.name.text;
|
|
93
|
+
const mapping = mappings.find((m) => m.oldImport === importName);
|
|
94
|
+
if (mapping) {
|
|
95
|
+
if (!importsToAdd.has(mapping.toModule)) {
|
|
96
|
+
importsToAdd.set(mapping.toModule, new Set());
|
|
97
|
+
}
|
|
98
|
+
importsToAdd.get(mapping.toModule).add(mapping.newImport);
|
|
99
|
+
importsToRemove.add(importName);
|
|
100
|
+
hasChanged = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
if (hasChanged || componentImportsToReplace.size > 0) {
|
|
110
|
+
updatedSourceText = processImports(sourceFile, updatedSourceText, importsToRemove);
|
|
111
|
+
updatedSourceText = addNewImports(updatedSourceText, importsToAdd);
|
|
112
|
+
const updatedSourceFile = ts.createSourceFile(filePath, updatedSourceText, ts.ScriptTarget.Latest, true);
|
|
113
|
+
updatedSourceText = replaceAllClassReferences(updatedSourceFile, updatedSourceText, mappings);
|
|
114
|
+
tree.overwrite(filePath, updatedSourceText);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function processImports(sourceFile, sourceText, importsToRemove) {
|
|
118
|
+
let updatedText = sourceText;
|
|
119
|
+
sourceFile.forEachChild((node) => {
|
|
120
|
+
if (ts.isImportDeclaration(node)) {
|
|
121
|
+
const moduleSpecifier = node.moduleSpecifier;
|
|
122
|
+
if (ts.isStringLiteral(moduleSpecifier) &&
|
|
123
|
+
moduleSpecifier.text === '@angular/router') {
|
|
124
|
+
if (node.importClause && node.importClause.namedBindings) {
|
|
125
|
+
const namedBindings = node.importClause.namedBindings;
|
|
126
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
127
|
+
const importSpecifiers = namedBindings.elements;
|
|
128
|
+
const remainingImports = importSpecifiers.filter((specifier) => !importsToRemove.has(specifier.name.text));
|
|
129
|
+
if (remainingImports.length !== importSpecifiers.length) {
|
|
130
|
+
if (remainingImports.length === 0) {
|
|
131
|
+
updatedText =
|
|
132
|
+
updatedText.substring(0, node.getStart()) +
|
|
133
|
+
updatedText.substring(node.getEnd());
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const namedBindingsStart = namedBindings.getStart();
|
|
137
|
+
const namedBindingsEnd = namedBindings.getEnd();
|
|
138
|
+
const newNamedBindings = '{ ' +
|
|
139
|
+
remainingImports
|
|
140
|
+
.map((specifier) => specifier.getText())
|
|
141
|
+
.join(', ') +
|
|
142
|
+
' }';
|
|
143
|
+
updatedText =
|
|
144
|
+
updatedText.substring(0, namedBindingsStart) +
|
|
145
|
+
newNamedBindings +
|
|
146
|
+
updatedText.substring(namedBindingsEnd);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return updatedText;
|
|
155
|
+
}
|
|
156
|
+
function addNewImports(sourceText, importsToAdd) {
|
|
157
|
+
let updatedText = sourceText;
|
|
158
|
+
for (const [moduleName, importNames] of Array.from(importsToAdd.entries())) {
|
|
159
|
+
const importStatement = `import { ${Array.from(importNames).join(', ')} } from '${moduleName}';\n`;
|
|
160
|
+
let insertPosition = 0;
|
|
161
|
+
const importRegex = /^import .* from .*;$/gm;
|
|
162
|
+
let match;
|
|
163
|
+
while ((match = importRegex.exec(updatedText)) !== null) {
|
|
164
|
+
insertPosition = match.index + match[0].length;
|
|
165
|
+
}
|
|
166
|
+
updatedText =
|
|
167
|
+
updatedText.substring(0, insertPosition) +
|
|
168
|
+
'\n' +
|
|
169
|
+
importStatement +
|
|
170
|
+
updatedText.substring(insertPosition);
|
|
171
|
+
}
|
|
172
|
+
return updatedText;
|
|
173
|
+
}
|
|
174
|
+
function replaceAllClassReferences(sourceFile, sourceText, mappings) {
|
|
175
|
+
const replacementMap = new Map(mappings.map((m) => [m.oldImport, m.newImport]));
|
|
176
|
+
const replacements = [];
|
|
177
|
+
function visitNode(node) {
|
|
178
|
+
if (ts.isIdentifier(node)) {
|
|
179
|
+
const replacement = replacementMap.get(node.text);
|
|
180
|
+
if (replacement) {
|
|
181
|
+
let parent = node.parent;
|
|
182
|
+
let isPartOfImport = false;
|
|
183
|
+
while (parent) {
|
|
184
|
+
if (ts.isImportDeclaration(parent) || ts.isImportSpecifier(parent)) {
|
|
185
|
+
isPartOfImport = true;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
parent = parent.parent;
|
|
189
|
+
}
|
|
190
|
+
if (!isPartOfImport) {
|
|
191
|
+
replacements.push({
|
|
192
|
+
start: node.getStart(sourceFile),
|
|
193
|
+
end: node.getEnd(),
|
|
194
|
+
newText: replacement,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
ts.forEachChild(node, visitNode);
|
|
200
|
+
}
|
|
201
|
+
visitNode(sourceFile);
|
|
202
|
+
let result = sourceText;
|
|
203
|
+
for (const { start, end, newText } of replacements.sort((a, b) => b.start - a.start)) {
|
|
204
|
+
result = result.substring(0, start) + newText + result.substring(end);
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=replace-usages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-usages.js","sourceRoot":"","sources":["../../../../../../libs/typed-router/schematics/migrate/steps/replace-usages.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2DAIoC;AACpC,yDAA4D;AAC5D,iCAAiC;AAS1B,MAAM,aAAa,GACxB,CAAC,OAAe,EAAE,EAAE,CAAC,CAAO,IAAU,EAAE,OAAyB,EAAE,EAAE;IACnE,MAAM,SAAS,GAAG,MAAM,IAAA,uBAAa,EAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAExD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,gCAAmB,CAAC,YAAY,OAAO,CAAC,OAAO,cAAc,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;IAEtD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,gCAAmB,CAC3B,gDAAgD,OAAO,CAAC,OAAO,IAAI,CACpE,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,uCAAuC,UAAU,KAAK,CAAC,CAAC;IAE5E,MAAM,cAAc,GAAG;QACrB;YACE,SAAS,EAAE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,UAAU,CAAC,CAAC;IAEtB,IAAI,MAAM,GAAG,UAAU,CAAC;IACxB,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,YAAY,CAAC,IAAI,CACrD,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAC5B,EAAE,CAAC;QACF,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ngAdd = ngAdd;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const update_route_declarations_1 = require("./steps/update-route-declarations");
|
|
6
|
+
const run_migrate_1 = require("./steps/run-migrate");
|
|
7
|
+
const add_declaration_file_1 = require("./steps/add-declaration-file");
|
|
8
|
+
const handle_uncommitted_changes_1 = require("../utils/handle-uncommitted-changes");
|
|
9
|
+
const inform_user_1 = require("./steps/inform-user");
|
|
10
|
+
function ngAdd(options) {
|
|
11
|
+
if (!options.project) {
|
|
12
|
+
throw new Error('Project name is required.');
|
|
13
|
+
}
|
|
14
|
+
return (0, schematics_1.chain)([
|
|
15
|
+
(0, handle_uncommitted_changes_1.handleUncommittedChanges)(options),
|
|
16
|
+
(0, add_declaration_file_1.addDeclarationFile)(options),
|
|
17
|
+
(0, update_route_declarations_1.updateRouteDeclarations)(options),
|
|
18
|
+
(0, run_migrate_1.runMigrate)(options),
|
|
19
|
+
(0, inform_user_1.informUser)(),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/typed-router/schematics/ng-add/index.ts"],"names":[],"mappings":";;AAQA,sBAYC;AApBD,2DAAyD;AAEzD,iFAA4E;AAC5E,qDAAiD;AACjD,uEAAkE;AAClE,oFAA+E;AAC/E,qDAAiD;AAEjD,SAAgB,KAAK,CAAC,OAAe;IACnC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,qDAAwB,EAAC,OAAO,CAAC;QACjC,IAAA,yCAAkB,EAAC,OAAO,CAAC;QAC3B,IAAA,mDAAuB,EAAC,OAAO,CAAC;QAChC,IAAA,wBAAU,EAAC,OAAO,CAAC;QACnB,IAAA,wBAAU,GAAE;KACb,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import './schema.json';
|
|
2
|
+
/**
|
|
3
|
+
* Options available to the ng-add schematic.
|
|
4
|
+
*/
|
|
5
|
+
export interface Schema {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the project to add angular-typed-router to.
|
|
8
|
+
*/
|
|
9
|
+
project?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to allow the migration to run even if there are uncommitted Git changes.
|
|
12
|
+
*/
|
|
13
|
+
allowDirty?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to run the migration to update existing imports from @angular/router to angular-typed-router.
|
|
16
|
+
*/
|
|
17
|
+
migrate?: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../libs/typed-router/schematics/ng-add/schema.ts"],"names":[],"mappings":";;AAAA,oEAAoE;AACpE,yBAAuB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "add-angular-typed-router",
|
|
4
|
+
"title": "Add angular-typed-router to an existing workspace",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"project": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The name of the project to add angular-typed-router to.",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "projectName"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"allowDirty": {
|
|
15
|
+
"type": "boolean",
|
|
16
|
+
"description": "Whether to allow to run even if there are uncommitted Git changes.",
|
|
17
|
+
"default": false
|
|
18
|
+
},
|
|
19
|
+
"migrate": {
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"description": "Run migration to replace usages of RouterLink and Router with TypedRouterLink and TypedRouter.",
|
|
22
|
+
"default": false,
|
|
23
|
+
"x-prompt": "Would you like to replace usages of RouterLink and Router with TypedRouterLink and TypedRouter?"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addDeclarationFile = void 0;
|
|
13
|
+
const utility_1 = require("@schematics/angular/utility");
|
|
14
|
+
const workspace_models_1 = require("@schematics/angular/utility/workspace-models");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const json_file_1 = require("@schematics/angular/utility/json-file");
|
|
17
|
+
const addDeclarationFile = (options) => (host, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b, _c, _d;
|
|
19
|
+
const workspace = yield (0, utility_1.readWorkspace)(host);
|
|
20
|
+
const project = workspace.projects.get(options.project);
|
|
21
|
+
if (project &&
|
|
22
|
+
project.extensions['projectType'] === workspace_models_1.ProjectType.Application) {
|
|
23
|
+
const projectRoot = project.root;
|
|
24
|
+
const augmentationFileName = 'angular-typed-router.d.ts';
|
|
25
|
+
const declarationFilePath = (0, path_1.join)(projectRoot, augmentationFileName);
|
|
26
|
+
// TODO: Check if app.routes.ts exists and if it has the correct export
|
|
27
|
+
const augmentationFileContent = `import type { routes } from './src/app/app.routes';
|
|
28
|
+
|
|
29
|
+
declare module 'angular-typed-router' {
|
|
30
|
+
interface UserTypedRoutes {
|
|
31
|
+
routes: typeof routes;
|
|
32
|
+
}
|
|
33
|
+
interface AllowedRouteParamValues {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
host.create(declarationFilePath, augmentationFileContent);
|
|
39
|
+
const buildTsConfig = (_b = (_a = project === null || project === void 0 ? void 0 : project.targets.get('build')) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.tsConfig;
|
|
40
|
+
const testTsConfig = (_d = (_c = project === null || project === void 0 ? void 0 : project.targets.get('test')) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.tsConfig;
|
|
41
|
+
if (buildTsConfig && typeof buildTsConfig === 'string') {
|
|
42
|
+
addDeclarationFileToTsConfig(host, buildTsConfig, declarationFilePath);
|
|
43
|
+
}
|
|
44
|
+
if (testTsConfig && typeof testTsConfig === 'string') {
|
|
45
|
+
addDeclarationFileToTsConfig(host, testTsConfig, declarationFilePath);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
context.logger.warn(`Project "${options.project}" not found or is not an application.`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
exports.addDeclarationFile = addDeclarationFile;
|
|
53
|
+
function addDeclarationFileToTsConfig(host, tsConfigPath, declarationFilePath) {
|
|
54
|
+
if (host.exists(tsConfigPath)) {
|
|
55
|
+
const json = new json_file_1.JSONFile(host, tsConfigPath);
|
|
56
|
+
const includeArray = json.get(['include']) || [];
|
|
57
|
+
const relativePath = (0, path_1.relative)((0, path_1.dirname)(tsConfigPath), declarationFilePath);
|
|
58
|
+
if (!includeArray.includes(relativePath)) {
|
|
59
|
+
includeArray.push(relativePath);
|
|
60
|
+
json.modify(['include'], includeArray);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=add-declaration-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-declaration-file.js","sourceRoot":"","sources":["../../../../../../libs/typed-router/schematics/ng-add/steps/add-declaration-file.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yDAA4D;AAC5D,mFAA2E;AAC3E,+BAA+C;AAC/C,qEAAiE;AAE1D,MAAM,kBAAkB,GAC7B,CAAC,OAAe,EAAE,EAAE,CAAC,CAAO,IAAU,EAAE,OAAyB,EAAE,EAAE;;IACnE,MAAM,SAAS,GAAG,MAAM,IAAA,uBAAa,EAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAQ,CAAC,CAAC;IACzD,IACE,OAAO;QACP,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,8BAAW,CAAC,WAAW,EAC7D,CAAC;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;QACjC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;QACzD,MAAM,mBAAmB,GAAG,IAAA,WAAI,EAAC,WAA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A,cAAO,EAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC,CAAC;QAE1E,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YACzC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.informUser = void 0;
|
|
4
|
+
const informUser = () => (host, context) => {
|
|
5
|
+
context.logger.info('\n⚠️ IMPORTANT: Route Declaration Change Required ⚠️');
|
|
6
|
+
context.logger.info('We attempted to automatically update your route declarations.');
|
|
7
|
+
context.logger.info('Please verify that all route files now use the correct format:');
|
|
8
|
+
context.logger.info('FROM: export const routes: Routes = [];');
|
|
9
|
+
context.logger.info('TO: export const routes = [] as const satisfies Routes;');
|
|
10
|
+
context.logger.info('\nThis change is necessary for proper type inference of your routes.\n');
|
|
11
|
+
return host;
|
|
12
|
+
};
|
|
13
|
+
exports.informUser = informUser;
|
|
14
|
+
//# sourceMappingURL=inform-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inform-user.js","sourceRoot":"","sources":["../../../../../../libs/typed-router/schematics/ng-add/steps/inform-user.ts"],"names":[],"mappings":";;;AAEO,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;IACxE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;IAC5E,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,+DAA+D,CAChE,CAAC;IACF,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,gEAAgE,CACjE,CAAC;IACF,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;IAC/D,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,2DAA2D,CAC5D,CAAC;IACF,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,wEAAwE,CACzE,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAhBW,QAAA,UAAU,cAgBrB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SchematicContext, Tree } from '@angular-devkit/schematics';
|
|
2
|
+
import { Schema } from '../schema';
|
|
3
|
+
export declare const runMigrate: (options: Schema) => (host: Tree, context: SchematicContext) => import("@angular-devkit/schematics/src/tree/interface").Tree | import("@angular-devkit/schematics").Rule;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runMigrate = void 0;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const runMigrate = (options) => (host, context) => {
|
|
6
|
+
if (options.migrate) {
|
|
7
|
+
context.logger.info('Running migration to angular-typed-router...');
|
|
8
|
+
return (0, schematics_1.schematic)('migrate', {
|
|
9
|
+
project: options.project,
|
|
10
|
+
allowDirty: options.allowDirty,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return host;
|
|
14
|
+
};
|
|
15
|
+
exports.runMigrate = runMigrate;
|
|
16
|
+
//# sourceMappingURL=run-migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-migrate.js","sourceRoot":"","sources":["../../../../../../libs/typed-router/schematics/ng-add/steps/run-migrate.ts"],"names":[],"mappings":";;;AAAA,2DAA+E;AAGxE,MAAM,UAAU,GACrB,CAAC,OAAe,EAAE,EAAE,CAAC,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;IAC7D,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;QACpE,OAAO,IAAA,sBAAS,EAAC,SAAS,EAAE;YAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAVS,QAAA,UAAU,cAUnB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.updateRouteDeclarations = void 0;
|
|
13
|
+
const ts = require("typescript");
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const utility_1 = require("@schematics/angular/utility");
|
|
16
|
+
const updateRouteDeclarations = (options) => (tree, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
var _a;
|
|
18
|
+
const workspace = yield (0, utility_1.readWorkspace)(tree);
|
|
19
|
+
const project = workspace.projects.get(options.project);
|
|
20
|
+
if (!project)
|
|
21
|
+
return tree;
|
|
22
|
+
const routeFiles = findRouteFiles(tree, project.sourceRoot || (0, path_1.join)(project.root, 'src'));
|
|
23
|
+
for (const filePath of routeFiles) {
|
|
24
|
+
if (!tree.exists(filePath))
|
|
25
|
+
continue;
|
|
26
|
+
const sourceText = (_a = tree.read(filePath)) === null || _a === void 0 ? void 0 : _a.toString();
|
|
27
|
+
if (!sourceText)
|
|
28
|
+
continue;
|
|
29
|
+
const sourceFile = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
30
|
+
const result = transformRouteDeclarations(sourceFile, sourceText);
|
|
31
|
+
if (result.changed) {
|
|
32
|
+
context.logger.info(`Updated route declaration in ${filePath}`);
|
|
33
|
+
tree.overwrite(filePath, result.content);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return tree;
|
|
37
|
+
});
|
|
38
|
+
exports.updateRouteDeclarations = updateRouteDeclarations;
|
|
39
|
+
function findRouteFiles(tree, sourceRoot) {
|
|
40
|
+
const result = [];
|
|
41
|
+
// Look for common route file patterns
|
|
42
|
+
tree.getDir(sourceRoot).visit((filePath) => {
|
|
43
|
+
if (filePath.endsWith('.routes.ts') ||
|
|
44
|
+
(filePath.includes('routes') && filePath.endsWith('.ts'))) {
|
|
45
|
+
result.push(filePath);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function transformRouteDeclarations(sourceFile, sourceText) {
|
|
51
|
+
let changed = false;
|
|
52
|
+
const replacements = [];
|
|
53
|
+
function visit(node) {
|
|
54
|
+
// Look for variable declarations like "routes: Routes = [...]"
|
|
55
|
+
if (ts.isVariableDeclaration(node) &&
|
|
56
|
+
node.type &&
|
|
57
|
+
ts.isTypeReferenceNode(node.type) &&
|
|
58
|
+
node.type.typeName.getText() === 'Routes' &&
|
|
59
|
+
node.initializer &&
|
|
60
|
+
ts.isArrayLiteralExpression(node.initializer)) {
|
|
61
|
+
const variableName = node.name.getText();
|
|
62
|
+
const arrayText = node.initializer.getText();
|
|
63
|
+
replacements.push({
|
|
64
|
+
start: node.getStart(),
|
|
65
|
+
end: node.getEnd(),
|
|
66
|
+
newText: `${variableName} = ${arrayText} as const satisfies Routes`,
|
|
67
|
+
});
|
|
68
|
+
changed = true;
|
|
69
|
+
}
|
|
70
|
+
ts.forEachChild(node, visit);
|
|
71
|
+
}
|
|
72
|
+
visit(sourceFile);
|
|
73
|
+
let result = sourceText;
|
|
74
|
+
for (const { start, end, newText } of replacements.sort((a, b) => b.start - a.start)) {
|
|
75
|
+
result = result.substring(0, start) + newText + result.substring(end);
|
|
76
|
+
}
|
|
77
|
+
return { changed, content: result };
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=update-route-declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-route-declarations.js","sourceRoot":"","sources":["../../../../../../libs/typed-router/schematics/ng-add/steps/update-route-declarations.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AACjC,+BAA4B;AAG5B,yDAA4D;AAErD,MAAM,uBAAuB,GAClC,CAAC,OAAe,EAAQ,EAAE,CAC1B,CAAO,IAAU,EAAE,OAAyB,EAAE,EAAE;;IAC9C,MAAM,SAAS,GAAG,MAAM,IAAA,uBAAa,EAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAQ,CAAC,CAAC;IACzD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE1B,MAAM,UAAU,GAAG,cAAc,CAC/B,IAAI,EACJ,OAAO,CAAC,UAAU,IAAI,IAAA,WAAI,EAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAChD,CAAC;IAEF,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YAAE,SAAS;QAErC,MAAM,UAAU,GAAG,MAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,QAAQ,EAAE,CAAC;QACnD,IAAI,CAAC,UAAU;YAAE,SAAS;QAE1B,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,QAAQ,EACR,UAAU,EACV,EAAE,CA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Q;YACzC,IAAI,CAAC,WAAW;YAChB,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,EAC7C,CAAC;YACD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YAE7C,YAAY,CAAC,IAAI,CAAC;gBAChB,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE;gBACtB,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;gBAClB,OAAO,EAAE,GAAG,YAAY,MAAM,SAAS,4BAA4B;aACpE,CAAC,CAAC;YAEH,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;QAED,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,CAAC;IAElB,IAAI,MAAM,GAAG,UAAU,CAAC;IACxB,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,YAAY,CAAC,IAAI,CACrD,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAC5B,EAAE,CAAC;QACF,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleUncommittedChanges = void 0;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const hasUncommittedChanges = () => {
|
|
7
|
+
try {
|
|
8
|
+
const gitVersionResult = (0, child_process_1.spawnSync)('git', ['--version']);
|
|
9
|
+
if (gitVersionResult.status !== 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const gitRevParseResult = (0, child_process_1.spawnSync)('git', [
|
|
13
|
+
'rev-parse',
|
|
14
|
+
'--is-inside-work-tree',
|
|
15
|
+
]);
|
|
16
|
+
if (gitRevParseResult.status !== 0) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const result = (0, child_process_1.spawnSync)('git', ['status', '--porcelain']);
|
|
20
|
+
if (result.status !== 0) {
|
|
21
|
+
throw new schematics_1.SchematicsException(`Failed to execute git status: ${result.stderr.toString()}`);
|
|
22
|
+
}
|
|
23
|
+
// If output is not empty, there are uncommitted changes
|
|
24
|
+
return result.stdout.toString().trim() !== '';
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw new schematics_1.SchematicsException('Error checking Git status: ' + error.message);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const handleUncommittedChanges = (options) => {
|
|
31
|
+
return () => {
|
|
32
|
+
if (hasUncommittedChanges()) {
|
|
33
|
+
if (!options.allowDirty) {
|
|
34
|
+
throw new schematics_1.SchematicsException('Operation aborted due to uncommitted changes. ' +
|
|
35
|
+
'Use --allow-dirty flag to bypass this check.');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.handleUncommittedChanges = handleUncommittedChanges;
|
|
41
|
+
//# sourceMappingURL=handle-uncommitted-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-uncommitted-changes.js","sourceRoot":"","sources":["../../../../../libs/typed-router/schematics/utils/handle-uncommitted-changes.ts"],"names":[],"mappings":";;;AAAA,2DAAiE;AACjE,iDAA0C;AAE1C,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACjC,IAAI,CAAC;QACH,MAAM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