@schematics/angular 15.0.2 → 15.1.0-next.1
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/guard/{files → implements-files}/__name@dasherize__.guard.spec.ts.template +0 -0
- package/guard/{files → implements-files}/__name@dasherize__.guard.ts.template +1 -1
- package/guard/index.js +27 -18
- package/guard/schema.d.ts +5 -1
- package/guard/schema.json +7 -2
- package/guard/type-files/__name@dasherize__.guard.spec.ts.template +17 -0
- package/guard/type-files/__name@dasherize__.guard.ts.template +9 -0
- package/interceptor/{files → class-files}/__name@dasherize@if-flat__/__name@dasherize__.interceptor.spec.ts.template +0 -0
- package/interceptor/{files → class-files}/__name@dasherize@if-flat__/__name@dasherize__.interceptor.ts.template +0 -0
- package/interceptor/functional-files/__name@dasherize@if-flat__/__name@dasherize__.interceptor.spec.ts.template +16 -0
- package/interceptor/functional-files/__name@dasherize@if-flat__/__name@dasherize__.interceptor.ts.template +5 -0
- package/interceptor/index.js +5 -2
- package/interceptor/schema.d.ts +4 -0
- package/interceptor/schema.json +5 -0
- package/library/files/package.json.template +3 -2
- package/package.json +3 -3
- package/resolver/{files → class-files}/__name@dasherize__.resolver.spec.ts.template +0 -0
- package/resolver/{files → class-files}/__name@dasherize__.resolver.ts.template +0 -0
- package/resolver/functional-files/__name@dasherize__.resolver.spec.ts.template +17 -0
- package/resolver/functional-files/__name@dasherize__.resolver.ts.template +5 -0
- package/resolver/index.js +3 -1
- package/resolver/schema.d.ts +4 -0
- package/resolver/schema.json +5 -0
- package/utility/generate-from-files.d.ts +1 -0
- package/utility/generate-from-files.js +3 -2
- package/utility/latest-versions/package.json +1 -1
- package/utility/latest-versions.js +1 -1
|
File without changes
|
package/guard/index.js
CHANGED
|
@@ -14,26 +14,35 @@ function default_1(options) {
|
|
|
14
14
|
if (!options.implements) {
|
|
15
15
|
throw new schematics_1.SchematicsException('Option "implements" is required.');
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
options.implements.includes(schema_1.Implement.CanMatch)) {
|
|
24
|
-
routerNamedImports.push('Route', 'UrlSegment');
|
|
25
|
-
if (options.implements.length > 1) {
|
|
26
|
-
routerNamedImports.push(...commonRouterNameImports);
|
|
27
|
-
}
|
|
17
|
+
if (options.implements.length > 1 && options.functional) {
|
|
18
|
+
throw new schematics_1.SchematicsException('Can only specify one value for implements when generating a functional guard.');
|
|
19
|
+
}
|
|
20
|
+
if (options.functional) {
|
|
21
|
+
const guardType = options.implements[0] + 'Fn';
|
|
22
|
+
return (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './type-files' }, { guardType });
|
|
28
23
|
}
|
|
29
24
|
else {
|
|
30
|
-
|
|
25
|
+
const implementations = options.implements
|
|
26
|
+
.map((implement) => (implement === 'CanDeactivate' ? 'CanDeactivate<unknown>' : implement))
|
|
27
|
+
.join(', ');
|
|
28
|
+
const commonRouterNameImports = ['ActivatedRouteSnapshot', 'RouterStateSnapshot'];
|
|
29
|
+
const routerNamedImports = [...options.implements, 'UrlTree'];
|
|
30
|
+
if (options.implements.includes(schema_1.Implement.CanLoad) ||
|
|
31
|
+
options.implements.includes(schema_1.Implement.CanMatch)) {
|
|
32
|
+
routerNamedImports.push('Route', 'UrlSegment');
|
|
33
|
+
if (options.implements.length > 1) {
|
|
34
|
+
routerNamedImports.push(...commonRouterNameImports);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
routerNamedImports.push(...commonRouterNameImports);
|
|
39
|
+
}
|
|
40
|
+
routerNamedImports.sort();
|
|
41
|
+
const routerImports = routerNamedImports.join(', ');
|
|
42
|
+
return (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './implements-files' }, {
|
|
43
|
+
implementations,
|
|
44
|
+
routerImports,
|
|
45
|
+
});
|
|
31
46
|
}
|
|
32
|
-
routerNamedImports.sort();
|
|
33
|
-
const implementationImports = routerNamedImports.join(', ');
|
|
34
|
-
return (0, generate_from_files_1.generateFromFiles)(options, {
|
|
35
|
-
implementations,
|
|
36
|
-
implementationImports,
|
|
37
|
-
});
|
|
38
47
|
}
|
|
39
48
|
exports.default = default_1;
|
package/guard/schema.d.ts
CHANGED
|
@@ -7,7 +7,11 @@ export interface Schema {
|
|
|
7
7
|
*/
|
|
8
8
|
flat?: boolean;
|
|
9
9
|
/**
|
|
10
|
-
* Specifies
|
|
10
|
+
* Specifies whether to generate a guard as a function.
|
|
11
|
+
*/
|
|
12
|
+
functional?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Specifies which type of guard to create.
|
|
11
15
|
*/
|
|
12
16
|
implements?: Implement[];
|
|
13
17
|
/**
|
package/guard/schema.json
CHANGED
|
@@ -41,9 +41,14 @@
|
|
|
41
41
|
"$source": "projectName"
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
+
"functional": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"description": "Specifies whether to generate a guard as a function.",
|
|
47
|
+
"default": false
|
|
48
|
+
},
|
|
44
49
|
"implements": {
|
|
45
50
|
"type": "array",
|
|
46
|
-
"description": "Specifies which
|
|
51
|
+
"description": "Specifies which type of guard to create.",
|
|
47
52
|
"uniqueItems": true,
|
|
48
53
|
"minItems": 1,
|
|
49
54
|
"items": {
|
|
@@ -51,7 +56,7 @@
|
|
|
51
56
|
"type": "string"
|
|
52
57
|
},
|
|
53
58
|
"default": ["CanActivate"],
|
|
54
|
-
"x-prompt": "Which
|
|
59
|
+
"x-prompt": "Which type of guard would you like to create?"
|
|
55
60
|
}
|
|
56
61
|
},
|
|
57
62
|
"required": ["name", "project"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { <%= guardType %> } from '@angular/router';
|
|
3
|
+
|
|
4
|
+
import { <%= camelize(name) %>Guard } from './<%= dasherize(name) %>.guard';
|
|
5
|
+
|
|
6
|
+
describe('<%= camelize(name) %>Guard', () => {
|
|
7
|
+
const executeGuard: <%= guardType %> = (...guardParameters) =>
|
|
8
|
+
TestBed.runInInjectionContext(() => <%= camelize(name) %>Guard(...guardParameters));
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
TestBed.configureTestingModule({});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should be created', () => {
|
|
15
|
+
expect(executeGuard).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { <%= guardType %> } from '@angular/router';
|
|
2
|
+
|
|
3
|
+
export const <%= camelize(name) %>Guard: <%= guardType %><% if (guardType === 'CanDeactivateFn') { %><unknown><% } %> = <%
|
|
4
|
+
if (guardType === 'CanMatchFn' || guardType === 'CanLoadFn') { %>(route, segments)<% }
|
|
5
|
+
%><% if (guardType === 'CanActivateFn') { %>(route, state)<% }
|
|
6
|
+
%><% if (guardType === 'CanActivateChildFn') { %>(childRoute, state)<% }
|
|
7
|
+
%><% if (guardType === 'CanDeactivateFn') { %>(component, currentRoute, currentState, nextState)<% } %> => {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { <%= camelize(name) %>Interceptor } from './<%= dasherize(name) %>.interceptor';
|
|
4
|
+
|
|
5
|
+
describe('<%= camelize(name) %>Interceptor', () => {
|
|
6
|
+
const interceptor: HttpInterceptorFn = (req, next) =>
|
|
7
|
+
TestBed.runInInjectionContext(() => <%= camelize(name) %>Interceptor(req, next));
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should be created', () => {
|
|
14
|
+
expect(interceptor).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
});
|
package/interceptor/index.js
CHANGED
|
@@ -12,8 +12,11 @@ function default_1(options) {
|
|
|
12
12
|
// This schematic uses an older method to implement the flat option
|
|
13
13
|
const flat = options.flat;
|
|
14
14
|
options.flat = true;
|
|
15
|
-
|
|
15
|
+
const extraTemplateValues = {
|
|
16
16
|
'if-flat': (s) => (flat ? '' : s),
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
|
+
return options.functional
|
|
19
|
+
? (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './functional-files' }, extraTemplateValues)
|
|
20
|
+
: (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './class-files' }, extraTemplateValues);
|
|
18
21
|
}
|
|
19
22
|
exports.default = default_1;
|
package/interceptor/schema.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export interface Schema {
|
|
|
6
6
|
* When true (the default), creates files at the top level of the project.
|
|
7
7
|
*/
|
|
8
8
|
flat?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Creates the interceptor as a `HttpInterceptorFn`.
|
|
11
|
+
*/
|
|
12
|
+
functional?: boolean;
|
|
9
13
|
/**
|
|
10
14
|
* The name of the interceptor.
|
|
11
15
|
*/
|
package/interceptor/schema.json
CHANGED
|
@@ -40,6 +40,11 @@
|
|
|
40
40
|
"type": "boolean",
|
|
41
41
|
"description": "Do not create \"spec.ts\" test files for the new interceptor.",
|
|
42
42
|
"default": false
|
|
43
|
+
},
|
|
44
|
+
"functional": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"description": "Creates the interceptor as a `HttpInterceptorFn`.",
|
|
47
|
+
"default": false
|
|
43
48
|
}
|
|
44
49
|
},
|
|
45
50
|
"required": ["name", "project"]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematics/angular",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.1.0-next.1",
|
|
4
4
|
"description": "Schematics specific to Angular",
|
|
5
5
|
"homepage": "https://github.com/angular/angular-cli",
|
|
6
6
|
"keywords": [
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"schematics": "./collection.json",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@angular-devkit/core": "15.0.
|
|
27
|
-
"@angular-devkit/schematics": "15.0.
|
|
26
|
+
"@angular-devkit/core": "15.1.0-next.1",
|
|
27
|
+
"@angular-devkit/schematics": "15.1.0-next.1",
|
|
28
28
|
"jsonc-parser": "3.2.0"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { ResolveFn } from '@angular/router';
|
|
3
|
+
|
|
4
|
+
import { <%= camelize(name) %>Resolver } from './<%= dasherize(name) %>.resolver';
|
|
5
|
+
|
|
6
|
+
describe('<%= camelize(name) %>Resolver', () => {
|
|
7
|
+
const executeResolver: ResolveFn<boolean> = (...resolverParameters) =>
|
|
8
|
+
TestBed.runInInjectionContext(() => <%= camelize(name) %>Resolver(...resolverParameters));
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
TestBed.configureTestingModule({});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should be created', () => {
|
|
15
|
+
expect(executeResolver).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
});
|
package/resolver/index.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const generate_from_files_1 = require("../utility/generate-from-files");
|
|
11
11
|
function default_1(options) {
|
|
12
|
-
return
|
|
12
|
+
return options.functional
|
|
13
|
+
? (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './functional-files' })
|
|
14
|
+
: (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './class-files' });
|
|
13
15
|
}
|
|
14
16
|
exports.default = default_1;
|
package/resolver/schema.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export interface Schema {
|
|
|
6
6
|
* When true (the default), creates the new files at the top level of the current project.
|
|
7
7
|
*/
|
|
8
8
|
flat?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Creates the resolver as a `ResolveFn`.
|
|
11
|
+
*/
|
|
12
|
+
functional?: boolean;
|
|
9
13
|
/**
|
|
10
14
|
* The name of the new resolver.
|
|
11
15
|
*/
|
package/resolver/schema.json
CHANGED
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"description": "When true (the default), creates the new files at the top level of the current project.",
|
|
26
26
|
"default": true
|
|
27
27
|
},
|
|
28
|
+
"functional": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"description": "Creates the resolver as a `ResolveFn`.",
|
|
31
|
+
"default": false
|
|
32
|
+
},
|
|
28
33
|
"path": {
|
|
29
34
|
"type": "string",
|
|
30
35
|
"format": "path",
|
|
@@ -13,5 +13,6 @@ export interface GenerateFromFilesOptions {
|
|
|
13
13
|
prefix?: string;
|
|
14
14
|
project: string;
|
|
15
15
|
skipTests?: boolean;
|
|
16
|
+
templateFilesDirectory?: string;
|
|
16
17
|
}
|
|
17
18
|
export declare function generateFromFiles(options: GenerateFromFilesOptions, extraTemplateValues?: Record<string, string | ((v: string) => string)>): Rule;
|
|
@@ -14,7 +14,7 @@ const validation_1 = require("./validation");
|
|
|
14
14
|
const workspace_1 = require("./workspace");
|
|
15
15
|
function generateFromFiles(options, extraTemplateValues = {}) {
|
|
16
16
|
return async (host) => {
|
|
17
|
-
var _a, _b, _c;
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
18
|
(_a = options.path) !== null && _a !== void 0 ? _a : (options.path = await (0, workspace_1.createDefaultPath)(host, options.project));
|
|
19
19
|
(_b = options.prefix) !== null && _b !== void 0 ? _b : (options.prefix = '');
|
|
20
20
|
(_c = options.flat) !== null && _c !== void 0 ? _c : (options.flat = true);
|
|
@@ -22,7 +22,8 @@ function generateFromFiles(options, extraTemplateValues = {}) {
|
|
|
22
22
|
options.name = parsedPath.name;
|
|
23
23
|
options.path = parsedPath.path;
|
|
24
24
|
(0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
|
|
25
|
-
const
|
|
25
|
+
const templateFilesDirectory = (_d = options.templateFilesDirectory) !== null && _d !== void 0 ? _d : './files';
|
|
26
|
+
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(templateFilesDirectory), [
|
|
26
27
|
options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
|
|
27
28
|
(0, schematics_1.applyTemplates)({
|
|
28
29
|
...schematics_1.strings,
|
|
@@ -13,7 +13,7 @@ exports.latestVersions = {
|
|
|
13
13
|
// but ts_library doesn't support JSON inputs.
|
|
14
14
|
...require('./latest-versions/package.json')['dependencies'],
|
|
15
15
|
// As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
|
|
16
|
-
Angular: '^15.0.0',
|
|
16
|
+
Angular: '^15.0.0-next.0',
|
|
17
17
|
// Since @angular-devkit/build-angular and @schematics/angular are always
|
|
18
18
|
// published together from the same monorepo, and they are both
|
|
19
19
|
// non-experimental, they will always have the same version.
|