@schematics/angular 15.1.0-next.1 → 15.1.0-next.3

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/collection.json CHANGED
@@ -115,6 +115,11 @@
115
115
  "factory": "./web-worker",
116
116
  "schema": "./web-worker/schema.json",
117
117
  "description": "Create a Web Worker."
118
+ },
119
+ "environments": {
120
+ "factory": "./environments",
121
+ "schema": "./environments/schema.json",
122
+ "description": "Generate project environment files."
118
123
  }
119
124
  }
120
125
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Rule } from '@angular-devkit/schematics';
9
+ import { Schema as EnvironmentOptions } from './schema';
10
+ export default function (options: EnvironmentOptions): Rule;
@@ -0,0 +1,105 @@
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 utility_1 = require("@schematics/angular/utility");
12
+ const path_1 = require("path");
13
+ const ENVIRONMENTS_DIRECTORY = 'environments';
14
+ const ENVIRONMENT_FILE_CONTENT = 'export const environment = {};\n';
15
+ function default_1(options) {
16
+ return (0, utility_1.updateWorkspace)((workspace) => {
17
+ var _a;
18
+ const project = workspace.projects.get(options.project);
19
+ if (!project) {
20
+ throw new schematics_1.SchematicsException(`Project name "${options.project}" doesn't not exist.`);
21
+ }
22
+ const type = project.extensions['projectType'];
23
+ if (type !== 'application') {
24
+ return log('error', 'Only application project types are support by this schematic.' + type
25
+ ? ` Project "${options.project}" has a "projectType" of "${type}".`
26
+ : ` Project "${options.project}" has no "projectType" defined.`);
27
+ }
28
+ const buildTarget = project.targets.get('build');
29
+ if (!buildTarget) {
30
+ return log('error', `No "build" target found for project "${options.project}".` +
31
+ ' A "build" target is required to generate environment files.');
32
+ }
33
+ const serverTarget = project.targets.get('server');
34
+ const sourceRoot = (_a = project.sourceRoot) !== null && _a !== void 0 ? _a : path_1.posix.join(project.root, 'src');
35
+ // The generator needs to be iterated prior to returning to ensure all workspace changes that occur
36
+ // within the generator are present for `updateWorkspace` when it writes the workspace file.
37
+ return (0, schematics_1.chain)([
38
+ ...generateConfigurationEnvironments(buildTarget, serverTarget, sourceRoot, options.project),
39
+ ]);
40
+ });
41
+ }
42
+ exports.default = default_1;
43
+ function createIfMissing(path) {
44
+ return (tree, context) => {
45
+ if (tree.exists(path)) {
46
+ context.logger.info(`Skipping creation of already existing environment file "${path}".`);
47
+ }
48
+ else {
49
+ tree.create(path, ENVIRONMENT_FILE_CONTENT);
50
+ }
51
+ };
52
+ }
53
+ function log(type, text) {
54
+ return (_, context) => context.logger[type](text);
55
+ }
56
+ function* generateConfigurationEnvironments(buildTarget, serverTarget, sourceRoot, projectName) {
57
+ var _a, _b, _c;
58
+ if (!buildTarget.builder.startsWith(utility_1.AngularBuilder.Browser)) {
59
+ yield log('warn', `"build" target found for project "${projectName}" has a third-party builder "${buildTarget.builder}".` +
60
+ ' The generated project options may not be compatible with this builder.');
61
+ }
62
+ if (serverTarget && !serverTarget.builder.startsWith(utility_1.AngularBuilder.Server)) {
63
+ yield log('warn', `"server" target found for project "${projectName}" has a third-party builder "${buildTarget.builder}".` +
64
+ ' The generated project options may not be compatible with this builder.');
65
+ }
66
+ // Create default environment file
67
+ const defaultFilePath = path_1.posix.join(sourceRoot, ENVIRONMENTS_DIRECTORY, 'environment.ts');
68
+ yield createIfMissing(defaultFilePath);
69
+ const configurationEntries = [
70
+ ...Object.entries((_a = buildTarget.configurations) !== null && _a !== void 0 ? _a : {}),
71
+ ...Object.entries((_b = serverTarget === null || serverTarget === void 0 ? void 0 : serverTarget.configurations) !== null && _b !== void 0 ? _b : {}),
72
+ ];
73
+ const addedFiles = new Set();
74
+ for (const [name, configurationOptions] of configurationEntries) {
75
+ if (!configurationOptions) {
76
+ // Invalid configuration
77
+ continue;
78
+ }
79
+ // Default configuration will use the default environment file
80
+ if (name === buildTarget.defaultConfiguration) {
81
+ continue;
82
+ }
83
+ const configurationFilePath = path_1.posix.join(sourceRoot, ENVIRONMENTS_DIRECTORY, `environment.${name}.ts`);
84
+ // Add file replacement option entry for the configuration environment file
85
+ const replacements = ((_c = configurationOptions['fileReplacements']) !== null && _c !== void 0 ? _c : (configurationOptions['fileReplacements'] = []));
86
+ const existing = replacements.find((value) => value.replace === defaultFilePath);
87
+ if (existing) {
88
+ if (existing.with === configurationFilePath) {
89
+ yield log('info', `Skipping addition of already existing file replacements option for "${defaultFilePath}" to "${configurationFilePath}".`);
90
+ }
91
+ else {
92
+ yield log('warn', `Configuration "${name}" has a file replacements option for "${defaultFilePath}" but with a different replacement.` +
93
+ ` Expected "${configurationFilePath}" but found "${existing.with}". This may result in unexpected build behavior.`);
94
+ }
95
+ }
96
+ else {
97
+ replacements.push({ replace: defaultFilePath, with: configurationFilePath });
98
+ }
99
+ // Create configuration specific environment file if not already added
100
+ if (!addedFiles.has(configurationFilePath)) {
101
+ addedFiles.add(configurationFilePath);
102
+ yield createIfMissing(configurationFilePath);
103
+ }
104
+ }
105
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generates and configures environment files for a project.
3
+ */
4
+ export interface Schema {
5
+ /**
6
+ * The name of the project.
7
+ */
8
+ project: string;
9
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
3
+ // CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "SchematicsAngularEnvironment",
4
+ "title": "Angular Environments Options Schema",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "description": "Generates and configures environment files for a project.",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "description": "The name of the project.",
12
+ "$default": {
13
+ "$source": "projectName"
14
+ }
15
+ }
16
+ },
17
+ "required": ["project"]
18
+ }
package/guard/schema.json CHANGED
@@ -47,6 +47,7 @@
47
47
  "default": false
48
48
  },
49
49
  "implements": {
50
+ "alias": "guardType",
50
51
  "type": "array",
51
52
  "description": "Specifies which type of guard to create.",
52
53
  "uniqueItems": true,
@@ -6,4 +6,4 @@ export const <%= camelize(name) %>Guard: <%= guardType %><% if (guardType === 'C
6
6
  %><% if (guardType === 'CanActivateChildFn') { %>(childRoute, state)<% }
7
7
  %><% if (guardType === 'CanDeactivateFn') { %>(component, currentRoute, currentState, nextState)<% } %> => {
8
8
  return true;
9
- }
9
+ };
@@ -1,4 +1,5 @@
1
1
  import { TestBed } from '@angular/core/testing';
2
+ import { HttpInterceptorFn } from '@angular/common/http';
2
3
 
3
4
  import { <%= camelize(name) %>Interceptor } from './<%= dasherize(name) %>.interceptor';
4
5
 
@@ -2,4 +2,4 @@ import { HttpInterceptorFn } from '@angular/common/http';
2
2
 
3
3
  export const <%= camelize(name) %>Interceptor: HttpInterceptorFn = (req, next) => {
4
4
  return next(req);
5
- }
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematics/angular",
3
- "version": "15.1.0-next.1",
3
+ "version": "15.1.0-next.3",
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.1.0-next.1",
27
- "@angular-devkit/schematics": "15.1.0-next.1",
26
+ "@angular-devkit/core": "15.1.0-next.3",
27
+ "@angular-devkit/schematics": "15.1.0-next.3",
28
28
  "jsonc-parser": "3.2.0"
29
29
  },
30
30
  "repository": {
@@ -2,4 +2,4 @@ import { ResolveFn } from '@angular/router';
2
2
 
3
3
  export const <%= camelize(name) %>Resolver: ResolveFn<boolean> = (route, state) => {
4
4
  return true;
5
- }
5
+ };
@@ -14,7 +14,7 @@
14
14
  "karma": "~6.4.0",
15
15
  "ng-packagr": "^15.0.0-next.0",
16
16
  "protractor": "~7.0.0",
17
- "rxjs": "~7.5.0",
17
+ "rxjs": "~7.6.0",
18
18
  "tslib": "^2.3.0",
19
19
  "ts-node": "~10.9.0",
20
20
  "typescript": "~4.8.2",