1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | const schematics_1 = require("@angular-devkit/schematics");
|
---|
11 | const generate_from_files_1 = require("../utility/generate-from-files");
|
---|
12 | const schema_1 = require("./schema");
|
---|
13 | function default_1(options) {
|
---|
14 | if (!options.implements) {
|
---|
15 | throw new schematics_1.SchematicsException('Option "implements" is required.');
|
---|
16 | }
|
---|
17 | const implementations = options.implements
|
---|
18 | .map((implement) => (implement === 'CanDeactivate' ? 'CanDeactivate<unknown>' : implement))
|
---|
19 | .join(', ');
|
---|
20 | const commonRouterNameImports = ['ActivatedRouteSnapshot', 'RouterStateSnapshot'];
|
---|
21 | const routerNamedImports = [...options.implements, 'UrlTree'];
|
---|
22 | if (options.implements.includes(schema_1.Implement.CanLoad)) {
|
---|
23 | routerNamedImports.push('Route', 'UrlSegment');
|
---|
24 | if (options.implements.length > 1) {
|
---|
25 | routerNamedImports.push(...commonRouterNameImports);
|
---|
26 | }
|
---|
27 | }
|
---|
28 | else {
|
---|
29 | routerNamedImports.push(...commonRouterNameImports);
|
---|
30 | }
|
---|
31 | routerNamedImports.sort();
|
---|
32 | const implementationImports = routerNamedImports.join(', ');
|
---|
33 | return generate_from_files_1.generateFromFiles(options, {
|
---|
34 | implementations,
|
---|
35 | implementationImports,
|
---|
36 | });
|
---|
37 | }
|
---|
38 | exports.default = default_1;
|
---|