@schematics/angular 14.0.0-next.12 → 14.0.0-next.13
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/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +4 -2
- package/e2e/index.js +3 -3
- package/package.json +10 -3
- package/service-worker/index.js +3 -3
- package/utility/dependency.d.ts +45 -0
- package/utility/dependency.js +97 -0
- package/utility/index.d.ts +10 -0
- package/utility/index.js +21 -0
- package/utility/workspace-models.d.ts +6 -0
- package/utility/workspace-models.js +6 -0
- package/utility/workspace.d.ts +36 -3
- package/utility/workspace.js +70 -30
package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core'
|
|
1
|
+
import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';<% if(standalone) {%>
|
|
2
|
+
import { CommonModule } from '@angular/common';<% } %>
|
|
2
3
|
|
|
3
4
|
@Component({<% if(!skipSelector) {%>
|
|
4
5
|
selector: '<%= selector %>',<%}%><% if(standalone) {%>
|
|
5
|
-
standalone: true
|
|
6
|
+
standalone: true,
|
|
7
|
+
imports: [CommonModule], <%}%><% if(inlineTemplate) { %>
|
|
6
8
|
template: `
|
|
7
9
|
<p>
|
|
8
10
|
<%= dasherize(name) %> works!
|
package/e2e/index.js
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const core_1 = require("@angular-devkit/core");
|
|
11
11
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
12
|
+
const utility_1 = require("../utility");
|
|
12
13
|
const dependencies_1 = require("../utility/dependencies");
|
|
13
14
|
const json_file_1 = require("../utility/json-file");
|
|
14
15
|
const latest_versions_1 = require("../utility/latest-versions");
|
|
15
16
|
const paths_1 = require("../utility/paths");
|
|
16
|
-
const workspace_1 = require("../utility/workspace");
|
|
17
17
|
const workspace_models_1 = require("../utility/workspace-models");
|
|
18
18
|
function addScriptsToPackageJson() {
|
|
19
19
|
return (host) => {
|
|
@@ -27,7 +27,7 @@ function addScriptsToPackageJson() {
|
|
|
27
27
|
function default_1(options) {
|
|
28
28
|
return async (host) => {
|
|
29
29
|
const appProject = options.relatedAppName;
|
|
30
|
-
const workspace = await (0,
|
|
30
|
+
const workspace = await (0, utility_1.readWorkspace)(host);
|
|
31
31
|
const project = workspace.projects.get(appProject);
|
|
32
32
|
if (!project) {
|
|
33
33
|
throw new schematics_1.SchematicsException(`Project name "${appProject}" doesn't not exist.`);
|
|
@@ -49,8 +49,8 @@ function default_1(options) {
|
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
});
|
|
52
|
+
await (0, utility_1.writeWorkspace)(host, workspace);
|
|
52
53
|
return (0, schematics_1.chain)([
|
|
53
|
-
(0, workspace_1.updateWorkspace)(workspace),
|
|
54
54
|
(0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
55
55
|
(0, schematics_1.applyTemplates)({
|
|
56
56
|
utils: schematics_1.strings,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematics/angular",
|
|
3
|
-
"version": "14.0.0-next.
|
|
3
|
+
"version": "14.0.0-next.13",
|
|
4
4
|
"description": "Schematics specific to Angular",
|
|
5
5
|
"homepage": "https://github.com/angular/angular-cli",
|
|
6
6
|
"keywords": [
|
|
@@ -13,10 +13,17 @@
|
|
|
13
13
|
"code generation",
|
|
14
14
|
"schematics"
|
|
15
15
|
],
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./utility": "./utility/index.js",
|
|
19
|
+
"./utility/*": "./utility/*.js",
|
|
20
|
+
"./migrations/migration-collection.json": "./migrations/migration-collection.json",
|
|
21
|
+
"./*": "./*.js"
|
|
22
|
+
},
|
|
16
23
|
"schematics": "./collection.json",
|
|
17
24
|
"dependencies": {
|
|
18
|
-
"@angular-devkit/core": "14.0.0-next.
|
|
19
|
-
"@angular-devkit/schematics": "14.0.0-next.
|
|
25
|
+
"@angular-devkit/core": "14.0.0-next.13",
|
|
26
|
+
"@angular-devkit/schematics": "14.0.0-next.13",
|
|
20
27
|
"jsonc-parser": "3.0.0"
|
|
21
28
|
},
|
|
22
29
|
"repository": {
|
package/service-worker/index.js
CHANGED
|
@@ -34,13 +34,13 @@ const core_1 = require("@angular-devkit/core");
|
|
|
34
34
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
35
35
|
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
36
36
|
const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
37
|
+
const utility_1 = require("../utility");
|
|
37
38
|
const ast_utils_1 = require("../utility/ast-utils");
|
|
38
39
|
const change_1 = require("../utility/change");
|
|
39
40
|
const dependencies_1 = require("../utility/dependencies");
|
|
40
41
|
const ng_ast_utils_1 = require("../utility/ng-ast-utils");
|
|
41
42
|
const paths_1 = require("../utility/paths");
|
|
42
43
|
const project_targets_1 = require("../utility/project-targets");
|
|
43
|
-
const workspace_1 = require("../utility/workspace");
|
|
44
44
|
function addDependencies() {
|
|
45
45
|
return (host, context) => {
|
|
46
46
|
const packageName = '@angular/service-worker';
|
|
@@ -119,7 +119,7 @@ function getTsSourceFile(host, path) {
|
|
|
119
119
|
}
|
|
120
120
|
function default_1(options) {
|
|
121
121
|
return async (host, context) => {
|
|
122
|
-
const workspace = await (0,
|
|
122
|
+
const workspace = await (0, utility_1.readWorkspace)(host);
|
|
123
123
|
const project = workspace.projects.get(options.project);
|
|
124
124
|
if (!project) {
|
|
125
125
|
throw new schematics_1.SchematicsException(`Invalid project name (${options.project})`);
|
|
@@ -148,9 +148,9 @@ function default_1(options) {
|
|
|
148
148
|
(0, schematics_1.move)(project.root),
|
|
149
149
|
]);
|
|
150
150
|
context.addTask(new tasks_1.NodePackageInstallTask());
|
|
151
|
+
await (0, utility_1.writeWorkspace)(host, workspace);
|
|
151
152
|
return (0, schematics_1.chain)([
|
|
152
153
|
(0, schematics_1.mergeWith)(templateSource),
|
|
153
|
-
(0, workspace_1.updateWorkspace)(workspace),
|
|
154
154
|
addDependencies(),
|
|
155
155
|
updateAppModule(buildOptions.main),
|
|
156
156
|
]);
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* An enum used to specify the type of a dependency found within a package manifest
|
|
11
|
+
* file (`package.json`).
|
|
12
|
+
*/
|
|
13
|
+
export declare enum DependencyType {
|
|
14
|
+
Default = "dependencies",
|
|
15
|
+
Dev = "devDependencies",
|
|
16
|
+
Peer = "peerDependencies"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Adds a package as a dependency to a `package.json`. By default the `package.json` located
|
|
20
|
+
* at the schematic's root will be used. The `manifestPath` option can be used to explicitly specify
|
|
21
|
+
* a `package.json` in different location. The type of the dependency can also be specified instead
|
|
22
|
+
* of the default of the `dependencies` section by using the `type` option for either `devDependencies`
|
|
23
|
+
* or `peerDependencies`.
|
|
24
|
+
*
|
|
25
|
+
* When using this rule, {@link NodePackageInstallTask} does not need to be included directly by
|
|
26
|
+
* a schematic. A package manager install task will be automatically scheduled as needed.
|
|
27
|
+
*
|
|
28
|
+
* @param name The name of the package to add.
|
|
29
|
+
* @param specifier The package specifier for the package to add. Typically a SemVer range.
|
|
30
|
+
* @param options An optional object that can contain the `type` of the dependency
|
|
31
|
+
* and/or a path (`packageJsonPath`) of a manifest file (`package.json`) to modify.
|
|
32
|
+
* @returns A Schematics {@link Rule}
|
|
33
|
+
*/
|
|
34
|
+
export declare function addDependency(name: string, specifier: string, options?: {
|
|
35
|
+
/**
|
|
36
|
+
* The type of the dependency determines the section of the `package.json` to which the
|
|
37
|
+
* dependency will be added. Defaults to {@link DependencyType.Default} (`dependencies`).
|
|
38
|
+
*/
|
|
39
|
+
type?: DependencyType;
|
|
40
|
+
/**
|
|
41
|
+
* The path of the package manifest file (`package.json`) that will be modified.
|
|
42
|
+
* Defaults to `/package.json`.
|
|
43
|
+
*/
|
|
44
|
+
packageJsonPath?: string;
|
|
45
|
+
}): Rule;
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.addDependency = exports.DependencyType = void 0;
|
|
34
|
+
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
35
|
+
const path = __importStar(require("path"));
|
|
36
|
+
const installTasks = new WeakMap();
|
|
37
|
+
/**
|
|
38
|
+
* An enum used to specify the type of a dependency found within a package manifest
|
|
39
|
+
* file (`package.json`).
|
|
40
|
+
*/
|
|
41
|
+
var DependencyType;
|
|
42
|
+
(function (DependencyType) {
|
|
43
|
+
DependencyType["Default"] = "dependencies";
|
|
44
|
+
DependencyType["Dev"] = "devDependencies";
|
|
45
|
+
DependencyType["Peer"] = "peerDependencies";
|
|
46
|
+
})(DependencyType = exports.DependencyType || (exports.DependencyType = {}));
|
|
47
|
+
/**
|
|
48
|
+
* Adds a package as a dependency to a `package.json`. By default the `package.json` located
|
|
49
|
+
* at the schematic's root will be used. The `manifestPath` option can be used to explicitly specify
|
|
50
|
+
* a `package.json` in different location. The type of the dependency can also be specified instead
|
|
51
|
+
* of the default of the `dependencies` section by using the `type` option for either `devDependencies`
|
|
52
|
+
* or `peerDependencies`.
|
|
53
|
+
*
|
|
54
|
+
* When using this rule, {@link NodePackageInstallTask} does not need to be included directly by
|
|
55
|
+
* a schematic. A package manager install task will be automatically scheduled as needed.
|
|
56
|
+
*
|
|
57
|
+
* @param name The name of the package to add.
|
|
58
|
+
* @param specifier The package specifier for the package to add. Typically a SemVer range.
|
|
59
|
+
* @param options An optional object that can contain the `type` of the dependency
|
|
60
|
+
* and/or a path (`packageJsonPath`) of a manifest file (`package.json`) to modify.
|
|
61
|
+
* @returns A Schematics {@link Rule}
|
|
62
|
+
*/
|
|
63
|
+
function addDependency(name, specifier, options = {}) {
|
|
64
|
+
const { type = DependencyType.Default, packageJsonPath = '/package.json' } = options;
|
|
65
|
+
return (tree, context) => {
|
|
66
|
+
var _a;
|
|
67
|
+
const manifest = tree.readJson(packageJsonPath);
|
|
68
|
+
const dependencySection = manifest[type];
|
|
69
|
+
if (!dependencySection) {
|
|
70
|
+
// Section is not present. The dependency can be added to a new object literal for the section.
|
|
71
|
+
manifest[type] = { [name]: specifier };
|
|
72
|
+
}
|
|
73
|
+
else if (dependencySection[name] === specifier) {
|
|
74
|
+
// Already present with same specifier
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
else if (dependencySection[name]) {
|
|
78
|
+
// Already present but different specifier
|
|
79
|
+
throw new Error(`Package dependency "${name}" already exists with a different specifier.`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Add new dependency in alphabetical order
|
|
83
|
+
const entries = Object.entries(dependencySection);
|
|
84
|
+
entries.push([name, specifier]);
|
|
85
|
+
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
86
|
+
manifest[type] = Object.fromEntries(entries);
|
|
87
|
+
}
|
|
88
|
+
tree.overwrite(packageJsonPath, JSON.stringify(manifest, null, 2));
|
|
89
|
+
const installPaths = (_a = installTasks.get(context)) !== null && _a !== void 0 ? _a : new Set();
|
|
90
|
+
if (!installPaths.has(packageJsonPath)) {
|
|
91
|
+
context.addTask(new tasks_1.NodePackageInstallTask({ workingDirectory: path.dirname(packageJsonPath) }));
|
|
92
|
+
installPaths.add(packageJsonPath);
|
|
93
|
+
installTasks.set(context, installPaths);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
exports.addDependency = addDependency;
|
|
@@ -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
|
+
export { ProjectDefinition, TargetDefinition, WorkspaceDefinition, getWorkspace as readWorkspace, updateWorkspace, writeWorkspace, } from './workspace';
|
|
9
|
+
export { Builders as AngularBuilder } from './workspace-models';
|
|
10
|
+
export { DependencyType, addDependency } from './dependency';
|
package/utility/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
exports.addDependency = exports.DependencyType = exports.AngularBuilder = exports.writeWorkspace = exports.updateWorkspace = exports.readWorkspace = void 0;
|
|
11
|
+
// Workspace related rules and types
|
|
12
|
+
var workspace_1 = require("./workspace");
|
|
13
|
+
Object.defineProperty(exports, "readWorkspace", { enumerable: true, get: function () { return workspace_1.getWorkspace; } });
|
|
14
|
+
Object.defineProperty(exports, "updateWorkspace", { enumerable: true, get: function () { return workspace_1.updateWorkspace; } });
|
|
15
|
+
Object.defineProperty(exports, "writeWorkspace", { enumerable: true, get: function () { return workspace_1.writeWorkspace; } });
|
|
16
|
+
var workspace_models_1 = require("./workspace-models");
|
|
17
|
+
Object.defineProperty(exports, "AngularBuilder", { enumerable: true, get: function () { return workspace_models_1.Builders; } });
|
|
18
|
+
// Package dependency related rules and types
|
|
19
|
+
var dependency_1 = require("./dependency");
|
|
20
|
+
Object.defineProperty(exports, "DependencyType", { enumerable: true, get: function () { return dependency_1.DependencyType; } });
|
|
21
|
+
Object.defineProperty(exports, "addDependency", { enumerable: true, get: function () { return dependency_1.addDependency; } });
|
|
@@ -9,6 +9,12 @@ export declare enum ProjectType {
|
|
|
9
9
|
Application = "application",
|
|
10
10
|
Library = "library"
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* An enum of the official Angular builders.
|
|
14
|
+
* Each enum value provides the fully qualified name of the associated builder.
|
|
15
|
+
* This enum can be used when analyzing the `builder` fields of project configurations from the
|
|
16
|
+
* `angular.json` workspace file.
|
|
17
|
+
*/
|
|
12
18
|
export declare enum Builders {
|
|
13
19
|
AppShell = "@angular-devkit/build-angular:app-shell",
|
|
14
20
|
Server = "@angular-devkit/build-angular:server",
|
|
@@ -13,6 +13,12 @@ var ProjectType;
|
|
|
13
13
|
ProjectType["Application"] = "application";
|
|
14
14
|
ProjectType["Library"] = "library";
|
|
15
15
|
})(ProjectType = exports.ProjectType || (exports.ProjectType = {}));
|
|
16
|
+
/**
|
|
17
|
+
* An enum of the official Angular builders.
|
|
18
|
+
* Each enum value provides the fully qualified name of the associated builder.
|
|
19
|
+
* This enum can be used when analyzing the `builder` fields of project configurations from the
|
|
20
|
+
* `angular.json` workspace file.
|
|
21
|
+
*/
|
|
16
22
|
var Builders;
|
|
17
23
|
(function (Builders) {
|
|
18
24
|
Builders["AppShell"] = "@angular-devkit/build-angular:app-shell";
|
package/utility/workspace.d.ts
CHANGED
|
@@ -7,9 +7,42 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { json, workspaces } from '@angular-devkit/core';
|
|
9
9
|
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
10
|
-
export declare
|
|
11
|
-
export declare
|
|
12
|
-
export declare
|
|
10
|
+
export declare type WorkspaceDefinition = workspaces.WorkspaceDefinition;
|
|
11
|
+
export declare type ProjectDefinition = workspaces.ProjectDefinition;
|
|
12
|
+
export declare type TargetDefinition = workspaces.TargetDefinition;
|
|
13
|
+
/**
|
|
14
|
+
* Updates the workspace file (`angular.json`) found within the root of the schematic's tree.
|
|
15
|
+
* The workspace object model can be directly modified within the provided updater function
|
|
16
|
+
* with changes being written to the workspace file after the updater function returns.
|
|
17
|
+
* The spacing and overall layout of the file (including comments) will be maintained where
|
|
18
|
+
* possible when updating the file.
|
|
19
|
+
*
|
|
20
|
+
* @param updater An update function that can be used to modify the object model for the
|
|
21
|
+
* workspace. A {@link WorkspaceDefinition} is provided as the first argument to the function.
|
|
22
|
+
*/
|
|
23
|
+
export declare function updateWorkspace(updater: (workspace: WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>): Rule;
|
|
24
|
+
/**
|
|
25
|
+
* Reads a workspace file (`angular.json`) from the provided {@link Tree} instance.
|
|
26
|
+
*
|
|
27
|
+
* @param tree A schematics {@link Tree} instance used to access the workspace file.
|
|
28
|
+
* @param path The path where a workspace file should be found. If a file is specified, the file
|
|
29
|
+
* path will be used. If a directory is specified, the file `angular.json` will be used from
|
|
30
|
+
* within the specified directory. Defaults to `/angular.json`.
|
|
31
|
+
* @returns A {@link WorkspaceDefinition} representing the workspace found at the specified path.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getWorkspace(tree: Tree, path?: string): Promise<WorkspaceDefinition>;
|
|
34
|
+
/**
|
|
35
|
+
* Writes a workspace file (`angular.json`) to the provided {@link Tree} instance.
|
|
36
|
+
* The spacing and overall layout of an exisitng file (including comments) will be maintained where
|
|
37
|
+
* possible when writing the file.
|
|
38
|
+
*
|
|
39
|
+
* @param tree A schematics {@link Tree} instance used to access the workspace file.
|
|
40
|
+
* @param workspace The {@link WorkspaceDefinition} to write.
|
|
41
|
+
* @param path The path where a workspace file should be written. If a file is specified, the file
|
|
42
|
+
* path will be used. If not provided, the definition's underlying file path stored during reading
|
|
43
|
+
* will be used.
|
|
44
|
+
*/
|
|
45
|
+
export declare function writeWorkspace(tree: Tree, workspace: WorkspaceDefinition, path?: string): Promise<void>;
|
|
13
46
|
/**
|
|
14
47
|
* Build a default project path for generating.
|
|
15
48
|
* @param project The project which will have its default path generated.
|
package/utility/workspace.js
CHANGED
|
@@ -7,49 +7,89 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.allTargetOptions = exports.allWorkspaceTargets = exports.createDefaultPath = exports.buildDefaultPath = exports.getWorkspace = exports.updateWorkspace = void 0;
|
|
10
|
+
exports.allTargetOptions = exports.allWorkspaceTargets = exports.createDefaultPath = exports.buildDefaultPath = exports.writeWorkspace = exports.getWorkspace = exports.updateWorkspace = void 0;
|
|
11
11
|
const core_1 = require("@angular-devkit/core");
|
|
12
12
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
13
|
const workspace_models_1 = require("./workspace-models");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function updateWorkspace(updaterOrWorkspace) {
|
|
32
|
-
return async (tree) => {
|
|
33
|
-
const host = createHost(tree);
|
|
34
|
-
if (typeof updaterOrWorkspace === 'function') {
|
|
35
|
-
const { workspace } = await core_1.workspaces.readWorkspace('/', host);
|
|
36
|
-
const result = await updaterOrWorkspace(workspace);
|
|
37
|
-
await core_1.workspaces.writeWorkspace(workspace, host);
|
|
38
|
-
return result || schematics_1.noop;
|
|
14
|
+
const DEFAULT_WORKSPACE_PATH = '/angular.json';
|
|
15
|
+
/**
|
|
16
|
+
* A {@link workspaces.WorkspaceHost} backed by a Schematics {@link Tree} instance.
|
|
17
|
+
*/
|
|
18
|
+
class TreeWorkspaceHost {
|
|
19
|
+
constructor(tree) {
|
|
20
|
+
this.tree = tree;
|
|
21
|
+
}
|
|
22
|
+
async readFile(path) {
|
|
23
|
+
return this.tree.readText(path);
|
|
24
|
+
}
|
|
25
|
+
async writeFile(path, data) {
|
|
26
|
+
if (this.tree.exists(path)) {
|
|
27
|
+
this.tree.overwrite(path, data);
|
|
39
28
|
}
|
|
40
29
|
else {
|
|
41
|
-
|
|
42
|
-
return schematics_1.noop;
|
|
30
|
+
this.tree.create(path, data);
|
|
43
31
|
}
|
|
32
|
+
}
|
|
33
|
+
async isDirectory(path) {
|
|
34
|
+
// approximate a directory check
|
|
35
|
+
return !this.tree.exists(path) && this.tree.getDir(path).subfiles.length > 0;
|
|
36
|
+
}
|
|
37
|
+
async isFile(path) {
|
|
38
|
+
return this.tree.exists(path);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Updates the workspace file (`angular.json`) found within the root of the schematic's tree.
|
|
43
|
+
* The workspace object model can be directly modified within the provided updater function
|
|
44
|
+
* with changes being written to the workspace file after the updater function returns.
|
|
45
|
+
* The spacing and overall layout of the file (including comments) will be maintained where
|
|
46
|
+
* possible when updating the file.
|
|
47
|
+
*
|
|
48
|
+
* @param updater An update function that can be used to modify the object model for the
|
|
49
|
+
* workspace. A {@link WorkspaceDefinition} is provided as the first argument to the function.
|
|
50
|
+
*/
|
|
51
|
+
function updateWorkspace(updater) {
|
|
52
|
+
return async (tree) => {
|
|
53
|
+
const host = new TreeWorkspaceHost(tree);
|
|
54
|
+
const { workspace } = await core_1.workspaces.readWorkspace(DEFAULT_WORKSPACE_PATH, host);
|
|
55
|
+
const result = await updater(workspace);
|
|
56
|
+
await core_1.workspaces.writeWorkspace(workspace, host);
|
|
57
|
+
return result || schematics_1.noop;
|
|
44
58
|
};
|
|
45
59
|
}
|
|
46
60
|
exports.updateWorkspace = updateWorkspace;
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
// TODO: This should be renamed `readWorkspace` once deep imports are restricted (already exported from `utility` with that name)
|
|
62
|
+
/**
|
|
63
|
+
* Reads a workspace file (`angular.json`) from the provided {@link Tree} instance.
|
|
64
|
+
*
|
|
65
|
+
* @param tree A schematics {@link Tree} instance used to access the workspace file.
|
|
66
|
+
* @param path The path where a workspace file should be found. If a file is specified, the file
|
|
67
|
+
* path will be used. If a directory is specified, the file `angular.json` will be used from
|
|
68
|
+
* within the specified directory. Defaults to `/angular.json`.
|
|
69
|
+
* @returns A {@link WorkspaceDefinition} representing the workspace found at the specified path.
|
|
70
|
+
*/
|
|
71
|
+
async function getWorkspace(tree, path = DEFAULT_WORKSPACE_PATH) {
|
|
72
|
+
const host = new TreeWorkspaceHost(tree);
|
|
49
73
|
const { workspace } = await core_1.workspaces.readWorkspace(path, host);
|
|
50
74
|
return workspace;
|
|
51
75
|
}
|
|
52
76
|
exports.getWorkspace = getWorkspace;
|
|
77
|
+
/**
|
|
78
|
+
* Writes a workspace file (`angular.json`) to the provided {@link Tree} instance.
|
|
79
|
+
* The spacing and overall layout of an exisitng file (including comments) will be maintained where
|
|
80
|
+
* possible when writing the file.
|
|
81
|
+
*
|
|
82
|
+
* @param tree A schematics {@link Tree} instance used to access the workspace file.
|
|
83
|
+
* @param workspace The {@link WorkspaceDefinition} to write.
|
|
84
|
+
* @param path The path where a workspace file should be written. If a file is specified, the file
|
|
85
|
+
* path will be used. If not provided, the definition's underlying file path stored during reading
|
|
86
|
+
* will be used.
|
|
87
|
+
*/
|
|
88
|
+
async function writeWorkspace(tree, workspace, path) {
|
|
89
|
+
const host = new TreeWorkspaceHost(tree);
|
|
90
|
+
return core_1.workspaces.writeWorkspace(workspace, host, path);
|
|
91
|
+
}
|
|
92
|
+
exports.writeWorkspace = writeWorkspace;
|
|
53
93
|
/**
|
|
54
94
|
* Build a default project path for generating.
|
|
55
95
|
* @param project The project which will have its default path generated.
|