This commit is contained in:
CHEVALLIER Abel
2025-11-13 16:23:22 +01:00
parent de9c515a47
commit cb235644dc
34924 changed files with 3811102 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { <%= classify(name) %>Guard } from './<%= dasherize(name) %><%= typeSeparator %>guard';
describe('<%= classify(name) %>Guard', () => {
let guard: <%= classify(name) %>Guard;
beforeEach(() => {
TestBed.configureTestingModule({});
guard = TestBed.inject(<%= classify(name) %>Guard);
});
it('should be created', () => {
expect(guard).toBeTruthy();
});
});

View File

@@ -0,0 +1,30 @@
import { Injectable } from '@angular/core';
import { <%= routerImports %> } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class <%= classify(name) %>Guard implements <%= implementations %> {
<% if (implements.includes('CanActivate')) { %>canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): MaybeAsync<GuardResult> {
return true;
}
<% } %><% if (implements.includes('CanActivateChild')) { %>canActivateChild(
childRoute: ActivatedRouteSnapshot,
state: RouterStateSnapshot): MaybeAsync<GuardResult> {
return true;
}
<% } %><% if (implements.includes('CanDeactivate')) { %>canDeactivate(
component: unknown,
currentRoute: ActivatedRouteSnapshot,
currentState: RouterStateSnapshot,
nextState?: RouterStateSnapshot): MaybeAsync<GuardResult> {
return true;
}
<% } %><% if (implements.includes('CanMatch')) { %>canMatch(
route: Route,
segments: UrlSegment[]): MaybeAsync<GuardResult> {
return true;
}<% } %>
}

10
node_modules/@schematics/angular/guard/index.d.ts generated vendored Executable file
View File

@@ -0,0 +1,10 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Rule } from '@angular-devkit/schematics';
import { Schema as GuardOptions } from './schema';
export default function (options: GuardOptions): Rule;

47
node_modules/@schematics/angular/guard/index.js generated vendored Executable file
View File

@@ -0,0 +1,47 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
const generate_from_files_1 = require("../utility/generate-from-files");
const schema_1 = require("./schema");
function default_1(options) {
if (!options.implements) {
throw new schematics_1.SchematicsException('Option "implements" is required.');
}
if (options.implements.length > 1 && options.functional) {
throw new schematics_1.SchematicsException('Can only specify one value for implements when generating a functional guard.');
}
if (options.functional) {
const guardType = options.implements[0] + 'Fn';
return (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './type-files' }, { guardType });
}
else {
const implementations = options.implements
.map((implement) => (implement === 'CanDeactivate' ? 'CanDeactivate<unknown>' : implement))
.join(', ');
const commonRouterNameImports = ['ActivatedRouteSnapshot', 'RouterStateSnapshot'];
const routerNamedImports = [...options.implements, 'MaybeAsync', 'GuardResult'];
if (options.implements.includes(schema_1.Implement.CanMatch)) {
routerNamedImports.push('Route', 'subPath');
if (options.implements.length > 1) {
routerNamedImports.push(...commonRouterNameImports);
}
}
else {
routerNamedImports.push(...commonRouterNameImports);
}
routerNamedImports.sort();
const routerImports = routerNamedImports.join(', ');
return (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './implements-files' }, {
implementations,
routerImports,
});
}
}

62
node_modules/@schematics/angular/guard/schema.d.ts generated vendored Executable file
View File

@@ -0,0 +1,62 @@
/**
* Creates a new route guard in your project. Route guards are used to control access to
* parts of your application by checking certain conditions before a route is activated.
* This schematic generates a new guard with the specified name, type, and options.
*/
export type Schema = {
/**
* Creates the new guard files at the top level of the current project. If set to false, a
* new folder with the guard's name will be created to contain the files.
*/
flat?: boolean;
/**
* Generate the guard as a function instead of a class. Functional guards can be simpler for
* basic scenarios.
*/
functional?: boolean;
/**
* Specifies the type(s) of guard to create. You can choose one or more of the following:
* `CanActivate` (controls access to a route), `CanActivateChild` (controls access to child
* routes), `CanDeactivate` (asks for confirmation before leaving a route), `CanMatch`
* (determines if a route can be matched).
*/
implements?: Implement[];
/**
* The name for the new route guard. This will be used to create the guard's class and spec
* files (e.g., `my-guard.guard.ts` and `my-guard.guard.spec.ts`).
*/
name: string;
/**
* The path where the guard files should be created, relative to the current workspace. If
* not provided, the guard will be created in the current directory.
*/
path?: string;
/**
* The name of the project where the guard should be created. If not specified, the CLI will
* determine the project from the current directory.
*/
project: string;
/**
* Skip the generation of a unit test file `spec.ts` for the new guard.
*/
skipTests?: boolean;
/**
* The separator character to use before the type within the generated file's name. For
* example, if you set the option to `.`, the file will be named `example.guard.ts`.
*/
typeSeparator?: TypeSeparator;
};
export declare enum Implement {
CanActivate = "CanActivate",
CanActivateChild = "CanActivateChild",
CanDeactivate = "CanDeactivate",
CanMatch = "CanMatch"
}
/**
* The separator character to use before the type within the generated file's name. For
* example, if you set the option to `.`, the file will be named `example.guard.ts`.
*/
export declare enum TypeSeparator {
Empty = "-",
TypeSeparator = "."
}

21
node_modules/@schematics/angular/guard/schema.js generated vendored Executable file
View File

@@ -0,0 +1,21 @@
"use strict";
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeSeparator = exports.Implement = void 0;
var Implement;
(function (Implement) {
Implement["CanActivate"] = "CanActivate";
Implement["CanActivateChild"] = "CanActivateChild";
Implement["CanDeactivate"] = "CanDeactivate";
Implement["CanMatch"] = "CanMatch";
})(Implement || (exports.Implement = Implement = {}));
/**
* The separator character to use before the type within the generated file's name. For
* example, if you set the option to `.`, the file will be named `example.guard.ts`.
*/
var TypeSeparator;
(function (TypeSeparator) {
TypeSeparator["Empty"] = "-";
TypeSeparator["TypeSeparator"] = ".";
})(TypeSeparator || (exports.TypeSeparator = TypeSeparator = {}));

70
node_modules/@schematics/angular/guard/schema.json generated vendored Executable file
View File

@@ -0,0 +1,70 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "SchematicsAngularGuard",
"title": "Angular Guard Options Schema",
"type": "object",
"description": "Creates a new route guard in your project. Route guards are used to control access to parts of your application by checking certain conditions before a route is activated. This schematic generates a new guard with the specified name, type, and options.",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"description": "The name for the new route guard. This will be used to create the guard's class and spec files (e.g., `my-guard.guard.ts` and `my-guard.guard.spec.ts`).",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use for the guard?"
},
"skipTests": {
"type": "boolean",
"description": "Skip the generation of a unit test file `spec.ts` for the new guard.",
"default": false
},
"flat": {
"type": "boolean",
"description": "Creates the new guard files at the top level of the current project. If set to false, a new folder with the guard's name will be created to contain the files.",
"default": true
},
"path": {
"type": "string",
"format": "path",
"$default": {
"$source": "workingDirectory"
},
"description": "The path where the guard files should be created, relative to the current workspace. If not provided, the guard will be created in the current directory.",
"visible": false
},
"project": {
"type": "string",
"description": "The name of the project where the guard should be created. If not specified, the CLI will determine the project from the current directory.",
"$default": {
"$source": "projectName"
}
},
"functional": {
"type": "boolean",
"description": "Generate the guard as a function instead of a class. Functional guards can be simpler for basic scenarios.",
"default": true
},
"implements": {
"alias": "guardType",
"type": "array",
"description": "Specifies the type(s) of guard to create. You can choose one or more of the following: `CanActivate` (controls access to a route), `CanActivateChild` (controls access to child routes), `CanDeactivate` (asks for confirmation before leaving a route), `CanMatch` (determines if a route can be matched).",
"uniqueItems": true,
"minItems": 1,
"items": {
"enum": ["CanActivate", "CanActivateChild", "CanDeactivate", "CanMatch"],
"type": "string"
},
"default": ["CanActivate"],
"x-prompt": "Which type of guard would you like to create?"
},
"typeSeparator": {
"type": "string",
"default": "-",
"enum": ["-", "."],
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.guard.ts`."
}
},
"required": ["name", "project"]
}

View File

@@ -0,0 +1,17 @@
import { TestBed } from '@angular/core/testing';
import { <%= guardType %> } from '@angular/router';
import { <%= camelize(name) %>Guard } from './<%= dasherize(name) %><%= typeSeparator %>guard';
describe('<%= camelize(name) %>Guard', () => {
const executeGuard: <%= guardType %><% if (guardType === 'CanDeactivateFn') { %><unknown><% } %> = (...guardParameters) =>
TestBed.runInInjectionContext(() => <%= camelize(name) %>Guard(...guardParameters));
beforeEach(() => {
TestBed.configureTestingModule({});
});
it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});

View File

@@ -0,0 +1,9 @@
import { <%= guardType %> } from '@angular/router';
export const <%= camelize(name) %>Guard: <%= guardType %><% if (guardType === 'CanDeactivateFn') { %><unknown><% } %> = <%
if (guardType === 'CanMatchFn') { %>(route, segments)<% }
%><% if (guardType === 'CanActivateFn') { %>(route, state)<% }
%><% if (guardType === 'CanActivateChildFn') { %>(childRoute, state)<% }
%><% if (guardType === 'CanDeactivateFn') { %>(component, currentRoute, currentState, nextState)<% } %> => {
return true;
};