60 lines
2.6 KiB
JavaScript
Executable file
60 lines
2.6 KiB
JavaScript
Executable file
"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.io/license
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("@angular-devkit/core");
|
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
const lint_fix_1 = require("../utility/lint-fix");
|
|
const parse_name_1 = require("../utility/parse-name");
|
|
const workspace_1 = require("../utility/workspace");
|
|
const schema_1 = require("./schema");
|
|
function default_1(options) {
|
|
return async (host) => {
|
|
if (options.path === undefined) {
|
|
options.path = await workspace_1.createDefaultPath(host, options.project);
|
|
}
|
|
if (!options.implements) {
|
|
throw new schematics_1.SchematicsException('Option "implements" is required.');
|
|
}
|
|
const implementations = options.implements
|
|
.map((implement) => (implement === 'CanDeactivate' ? 'CanDeactivate<unknown>' : implement))
|
|
.join(', ');
|
|
const commonRouterNameImports = ['ActivatedRouteSnapshot', 'RouterStateSnapshot'];
|
|
const routerNamedImports = [...options.implements, 'UrlTree'];
|
|
if (options.implements.includes(schema_1.Implement.CanLoad)) {
|
|
routerNamedImports.push('Route', 'UrlSegment');
|
|
if (options.implements.length > 1) {
|
|
routerNamedImports.push(...commonRouterNameImports);
|
|
}
|
|
}
|
|
else {
|
|
routerNamedImports.push(...commonRouterNameImports);
|
|
}
|
|
routerNamedImports.sort();
|
|
const implementationImports = routerNamedImports.join(', ');
|
|
const parsedPath = parse_name_1.parseName(options.path, options.name);
|
|
options.name = parsedPath.name;
|
|
options.path = parsedPath.path;
|
|
const templateSource = schematics_1.apply(schematics_1.url('./files'), [
|
|
options.skipTests ? schematics_1.filter((path) => !path.endsWith('.spec.ts.template')) : schematics_1.noop(),
|
|
schematics_1.applyTemplates({
|
|
implementations,
|
|
implementationImports,
|
|
...core_1.strings,
|
|
...options,
|
|
}),
|
|
schematics_1.move(parsedPath.path + (options.flat ? '' : '/' + core_1.strings.dasherize(options.name))),
|
|
]);
|
|
return schematics_1.chain([
|
|
schematics_1.mergeWith(templateSource),
|
|
options.lintFix ? lint_fix_1.applyLintFix(options.path) : schematics_1.noop(),
|
|
]);
|
|
};
|
|
}
|
|
exports.default = default_1;
|