@angular-devkit/schematics 12.0.0-rc.0 → 12.0.0
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/README.md +81 -61
- package/collection-schema.json +2 -7
- package/package.json +3 -3
- package/src/_golden-api.d.ts +1 -1
- package/src/_golden-api.js +1 -1
- package/src/engine/engine.d.ts +2 -2
- package/src/engine/engine.js +35 -22
- package/src/engine/index.d.ts +1 -1
- package/src/engine/index.js +7 -7
- package/src/engine/interface.d.ts +2 -2
- package/src/engine/interface.js +7 -0
- package/src/engine/schematic.d.ts +1 -1
- package/src/engine/schematic.js +13 -8
- package/src/exception/exception.d.ts +1 -1
- package/src/exception/exception.js +15 -7
- package/src/formats/format-validator.d.ts +1 -1
- package/src/formats/format-validator.js +4 -6
- package/src/formats/html-selector.d.ts +1 -1
- package/src/formats/html-selector.js +19 -12
- package/src/formats/index.d.ts +1 -1
- package/src/formats/index.js +3 -6
- package/src/formats/path.d.ts +1 -1
- package/src/formats/path.js +1 -1
- package/src/index.d.ts +3 -3
- package/src/index.js +20 -14
- package/src/rules/base.d.ts +7 -0
- package/src/rules/base.js +10 -10
- package/src/rules/call.d.ts +1 -1
- package/src/rules/call.js +7 -7
- package/src/rules/move.d.ts +7 -0
- package/src/rules/move.js +5 -5
- package/src/rules/random.d.ts +1 -1
- package/src/rules/random.js +17 -5
- package/src/rules/rename.d.ts +7 -0
- package/src/rules/rename.js +4 -4
- package/src/rules/schematic.d.ts +7 -0
- package/src/rules/schematic.js +5 -5
- package/src/rules/template.d.ts +1 -1
- package/src/rules/template.js +15 -9
- package/src/rules/url.d.ts +7 -0
- package/src/rules/url.js +3 -3
- package/src/sink/dryrun.d.ts +2 -2
- package/src/sink/dryrun.js +8 -8
- package/src/sink/host.d.ts +2 -2
- package/src/sink/host.js +8 -1
- package/src/sink/sink.d.ts +2 -2
- package/src/sink/sink.js +41 -29
- package/src/tree/action.d.ts +2 -2
- package/src/tree/action.js +24 -13
- package/src/tree/delegate.d.ts +2 -2
- package/src/tree/delegate.js +46 -13
- package/src/tree/empty.d.ts +1 -1
- package/src/tree/empty.js +6 -4
- package/src/tree/entry.d.ts +2 -2
- package/src/tree/entry.js +19 -4
- package/src/tree/host-tree.d.ts +2 -2
- package/src/tree/host-tree.js +18 -20
- package/src/tree/interface.d.ts +2 -2
- package/src/tree/interface.js +12 -3
- package/src/tree/null.d.ts +2 -2
- package/src/tree/null.js +22 -12
- package/src/tree/recorder.d.ts +7 -0
- package/src/tree/recorder.js +9 -7
- package/src/tree/scoped.d.ts +2 -2
- package/src/tree/scoped.js +31 -14
- package/src/tree/static.d.ts +7 -0
- package/src/tree/static.js +3 -3
- package/src/utility/linked-list.d.ts +1 -1
- package/src/utility/linked-list.js +4 -2
- package/src/utility/update-buffer.d.ts +2 -2
- package/src/utility/update-buffer.js +11 -11
- package/src/workflow/base.d.ts +1 -1
- package/src/workflow/base.js +16 -12
- package/src/workflow/index.d.ts +1 -1
- package/src/workflow/index.js +7 -7
- package/src/workflow/interface.d.ts +1 -1
- package/src/workflow/interface.js +7 -0
- package/tasks/index.d.ts +1 -1
- package/tasks/index.js +3 -3
- package/tasks/node/index.d.ts +1 -1
- package/tasks/node/index.js +11 -4
- package/tasks/package-manager/executor.d.ts +1 -1
- package/tasks/package-manager/executor.js +9 -7
- package/tasks/package-manager/install-task.d.ts +1 -1
- package/tasks/package-manager/install-task.js +7 -0
- package/tasks/package-manager/link-task.d.ts +1 -1
- package/tasks/package-manager/link-task.js +7 -0
- package/tasks/package-manager/options.d.ts +2 -1
- package/tasks/package-manager/options.js +3 -3
- package/tasks/repo-init/executor.d.ts +7 -0
- package/tasks/repo-init/executor.js +6 -11
- package/tasks/repo-init/init-task.d.ts +1 -1
- package/tasks/repo-init/init-task.js +7 -0
- package/tasks/repo-init/options.d.ts +1 -1
- package/tasks/repo-init/options.js +3 -3
- package/tasks/run-schematic/executor.d.ts +1 -1
- package/tasks/run-schematic/executor.js +7 -0
- package/tasks/run-schematic/options.d.ts +1 -1
- package/tasks/run-schematic/options.js +3 -3
- package/tasks/run-schematic/task.d.ts +1 -1
- package/tasks/run-schematic/task.js +7 -0
- package/tasks/tslint-fix/executor.d.ts +7 -0
- package/tasks/tslint-fix/executor.js +23 -19
- package/tasks/tslint-fix/options.d.ts +1 -1
- package/tasks/tslint-fix/options.js +7 -0
- package/tasks/tslint-fix/task.d.ts +1 -1
- package/tasks/tslint-fix/task.js +7 -0
- package/tasks/tslint-fix/test/custom-rule.d.ts +1 -1
- package/tasks/tslint-fix/test/custom-rule.js +8 -1
- package/tasks/tslint-fix/test/rules/customRuleRule.js +5 -5
- package/tasks/tslint-fix/test/run-task.d.ts +1 -1
- package/tasks/tslint-fix/test/run-task.js +8 -1
- package/testing/index.d.ts +1 -1
- package/testing/index.js +7 -7
- package/testing/schematic-test-runner.d.ts +1 -1
- package/testing/schematic-test-runner.js +21 -13
- package/tools/description.d.ts +1 -1
- package/tools/description.js +7 -0
- package/tools/export-ref.d.ts +7 -0
- package/tools/export-ref.js +12 -6
- package/tools/fallback-engine-host.d.ts +2 -3
- package/tools/fallback-engine-host.js +9 -12
- package/tools/file-system-engine-host-base.d.ts +2 -2
- package/tools/file-system-engine-host-base.js +23 -16
- package/tools/file-system-engine-host.d.ts +7 -0
- package/tools/file-system-engine-host.js +4 -4
- package/tools/file-system-utility.d.ts +1 -1
- package/tools/file-system-utility.js +6 -6
- package/tools/index.d.ts +1 -1
- package/tools/index.js +7 -7
- package/tools/node-module-engine-host.d.ts +1 -1
- package/tools/node-module-engine-host.js +5 -4
- package/tools/node-modules-test-engine-host.d.ts +1 -1
- package/tools/node-modules-test-engine-host.js +13 -2
- package/tools/schema-option-transform.d.ts +1 -1
- package/tools/schema-option-transform.js +4 -6
- package/tools/workflow/node-workflow.d.ts +2 -1
- package/tools/workflow/node-workflow.js +5 -4
package/README.md
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
# Schematics
|
|
2
|
+
|
|
2
3
|
> A scaffolding library for the modern web.
|
|
3
4
|
|
|
4
5
|
## Description
|
|
6
|
+
|
|
5
7
|
Schematics are generators that transform an existing filesystem. They can create files, refactor existing files, or move files around.
|
|
6
8
|
|
|
7
9
|
What distinguishes Schematics from other generators, such as Yeoman or Yarn Create, is that schematics are purely descriptive; no changes are applied to the actual filesystem until everything is ready to be committed. There is no side effect, by design, in Schematics.
|
|
8
10
|
|
|
9
11
|
# Glossary
|
|
10
12
|
|
|
11
|
-
| Term
|
|
12
|
-
|
|
13
|
-
| **Schematics** | A generator that executes descriptive code without side effects on an existing file system.
|
|
14
|
-
| **Collection** | A list of schematics metadata. Schematics can be referred by name inside a collection.
|
|
15
|
-
| **Tool** | The code using the Schematics library.
|
|
16
|
-
| **Tree** | A staging area for changes, containing the original file system, and a list of changes to apply to it.
|
|
17
|
-
| **Rule** | A function that applies actions to a `Tree`. It returns a new `Tree` that will contain all transformations to be applied.
|
|
18
|
-
| **Source** | A function that creates an entirely new `Tree` from an empty filesystem. For example, a file source could read files from disk and create a Create Action for each of those.
|
|
19
|
-
| **Action** | An atomic operation to be validated and committed to a filesystem or a `Tree`. Actions are created by schematics.
|
|
20
|
-
| **Sink** | The final destination of all `Action`s.
|
|
13
|
+
| Term | Description |
|
|
14
|
+
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| **Schematics** | A generator that executes descriptive code without side effects on an existing file system. |
|
|
16
|
+
| **Collection** | A list of schematics metadata. Schematics can be referred by name inside a collection. |
|
|
17
|
+
| **Tool** | The code using the Schematics library. |
|
|
18
|
+
| **Tree** | A staging area for changes, containing the original file system, and a list of changes to apply to it. |
|
|
19
|
+
| **Rule** | A function that applies actions to a `Tree`. It returns a new `Tree` that will contain all transformations to be applied. |
|
|
20
|
+
| **Source** | A function that creates an entirely new `Tree` from an empty filesystem. For example, a file source could read files from disk and create a Create Action for each of those. |
|
|
21
|
+
| **Action** | An atomic operation to be validated and committed to a filesystem or a `Tree`. Actions are created by schematics. |
|
|
22
|
+
| **Sink** | The final destination of all `Action`s. |
|
|
21
23
|
|
|
22
24
|
# Tooling
|
|
25
|
+
|
|
23
26
|
Schematics is a library, and does not work by itself. A [reference CLI](https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics_cli/bin/schematics.ts) is available on this repository, and is published on NPM at [@angular-devkit/schematics-cli](https://www.npmjs.com/package/@angular-devkit/schematics-cli). This document explains the library usage and the tooling API, but does not go into the tool implementation itself.
|
|
24
27
|
|
|
25
28
|
The tooling is responsible for the following tasks:
|
|
@@ -27,7 +30,7 @@ The tooling is responsible for the following tasks:
|
|
|
27
30
|
1. Create the Schematic Engine, and pass in a Collection and Schematic loader.
|
|
28
31
|
1. Understand and respect the Schematics metadata and dependencies between collections. Schematics can refer to dependencies, and it's the responsibility of the tool to honor those dependencies. The reference CLI uses NPM packages for its collections.
|
|
29
32
|
1. Create the Options object. Options can be anything, but the schematics can specify a JSON Schema that should be respected. The reference CLI, for example, parses the arguments as a JSON object and validates it with the Schema specified by the collection.
|
|
30
|
-
|
|
33
|
+
1. Schematics provides some JSON Schema formats for validation that tooling should add. These validate paths, html selectors and app names. Please check the reference CLI for how these can be added.
|
|
31
34
|
1. Call the schematics with the original Tree. The tree should represent the initial state of the filesystem. The reference CLI uses the current directory for this.
|
|
32
35
|
1. Create a Sink and commit the result of the schematics to the Sink. Many sinks are provided by the library; FileSystemSink and DryRunSink are examples.
|
|
33
36
|
1. Output any logs propagated by the library, including debugging information.
|
|
@@ -35,25 +38,30 @@ The tooling is responsible for the following tasks:
|
|
|
35
38
|
The tooling API is composed of the following pieces:
|
|
36
39
|
|
|
37
40
|
## Engine
|
|
41
|
+
|
|
38
42
|
The `SchematicEngine` is responsible for loading and constructing `Collection`s and `Schematics`. When creating an engine, the tooling provides an `EngineHost` interface that understands how to create a `CollectionDescription` from a name, and how to create a `SchematicDescription`.
|
|
39
43
|
|
|
40
44
|
# Schematics (Generators)
|
|
45
|
+
|
|
41
46
|
Schematics are generators and part of a `Collection`.
|
|
42
47
|
|
|
43
48
|
## Collection
|
|
49
|
+
|
|
44
50
|
A Collection is defined by a `collection.json` file (in the reference CLI). This JSON defines the following properties:
|
|
45
51
|
|
|
46
|
-
| Prop Name
|
|
47
|
-
|
|
48
|
-
| **name**
|
|
49
|
-
| **version** | `string` | Unused field.
|
|
52
|
+
| Prop Name | Type | Description |
|
|
53
|
+
| ----------- | -------- | --------------------------- |
|
|
54
|
+
| **name** | `string` | The name of the collection. |
|
|
55
|
+
| **version** | `string` | Unused field. |
|
|
50
56
|
|
|
51
57
|
## Schematic
|
|
52
58
|
|
|
53
59
|
# Operators, Sources and Rules
|
|
60
|
+
|
|
54
61
|
A `Source` is a generator of a `Tree`; it creates an entirely new root tree from nothing. A `Rule` is a transformation from one `Tree` to another. A `Schematic` (at the root) is a `Rule` that is normally applied on the filesystem.
|
|
55
62
|
|
|
56
63
|
## Operators
|
|
64
|
+
|
|
57
65
|
`FileOperator`s apply changes to a single `FileEntry` and return a new `FileEntry`. The result follows these rules:
|
|
58
66
|
|
|
59
67
|
1. If the `FileEntry` returned is null, a `DeleteAction` will be added to the action list.
|
|
@@ -63,66 +71,71 @@ A `Source` is a generator of a `Tree`; it creates an entirely new root tree from
|
|
|
63
71
|
It is impossible to create files using a `FileOperator`.
|
|
64
72
|
|
|
65
73
|
## Provided Operators
|
|
74
|
+
|
|
66
75
|
The Schematics library provides multiple `Operator` factories by default that cover basic use cases:
|
|
67
76
|
|
|
68
|
-
| FileOperator
|
|
69
|
-
|
|
77
|
+
| FileOperator | Description |
|
|
78
|
+
| -------------------------------- | --------------------------------------------------- |
|
|
70
79
|
| `contentTemplate<T>(options: T)` | Apply a content template (see the Template section) |
|
|
71
|
-
| `pathTemplate<T>(options: T)`
|
|
80
|
+
| `pathTemplate<T>(options: T)` | Apply a path template (see the Template section) |
|
|
72
81
|
|
|
73
82
|
## Provided Sources
|
|
83
|
+
|
|
74
84
|
The Schematics library additionally provides multiple `Source` factories by default:
|
|
75
85
|
|
|
76
|
-
| Source
|
|
77
|
-
|
|
78
|
-
| `empty()`
|
|
79
|
-
| `source(tree: Tree)`
|
|
80
|
-
| `url(url: string)`
|
|
81
|
-
| `apply(source: Source, rules: Rule[])` | Apply a list of `Rule`s to a source, and return the resulting `Source`.
|
|
86
|
+
| Source | Description |
|
|
87
|
+
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
+
| `empty()` | Creates a source that returns an empty `Tree`. |
|
|
89
|
+
| `source(tree: Tree)` | Creates a `Source` that returns the `Tree` passed in as argument. |
|
|
90
|
+
| `url(url: string)` | Loads a list of files from the given URL and returns a `Tree` with the files as `CreateAction` applied to an empty `Tree`. |
|
|
91
|
+
| `apply(source: Source, rules: Rule[])` | Apply a list of `Rule`s to a source, and return the resulting `Source`. |
|
|
82
92
|
|
|
83
93
|
## Provided Rules
|
|
84
|
-
The schematics library also provides `Rule` factories by default:
|
|
85
94
|
|
|
86
|
-
|
|
87
|
-
|---|---|
|
|
88
|
-
| `noop()` | Returns the input `Tree` as is. |
|
|
89
|
-
| `chain(rules: Rule[])` | Returns a `Rule` that's the concatenation of other `Rule`s. |
|
|
90
|
-
| `forEach(op: FileOperator)` | Returns a `Rule` that applies an operator to every file of the input `Tree`. |
|
|
91
|
-
| `move(root: string)` | Moves all the files from the input to a subdirectory. |
|
|
92
|
-
| `merge(other: Tree)` | Merge the input `Tree` with the other `Tree`. |
|
|
93
|
-
| `contentTemplate<T>(options: T)` | Apply a content template (see the Template section) to the entire `Tree`. |
|
|
94
|
-
| `pathTemplate<T>(options: T)` | Apply a path template (see the Template section) to the entire `Tree`. |
|
|
95
|
-
| `template<T>(options: T)` | Apply both path and content templates (see the Template section) to the entire `Tree`. |
|
|
96
|
-
| `filter(predicate: FilePredicate<boolean>)` | Returns the input `Tree` with files that do not pass the `FilePredicate`. |
|
|
95
|
+
The schematics library also provides `Rule` factories by default:
|
|
97
96
|
|
|
97
|
+
| Rule | Description |
|
|
98
|
+
| ------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
99
|
+
| `noop()` | Returns the input `Tree` as is. |
|
|
100
|
+
| `chain(rules: Rule[])` | Returns a `Rule` that's the concatenation of other `Rule`s. |
|
|
101
|
+
| `forEach(op: FileOperator)` | Returns a `Rule` that applies an operator to every file of the input `Tree`. |
|
|
102
|
+
| `move(root: string)` | Moves all the files from the input to a subdirectory. |
|
|
103
|
+
| `merge(other: Tree)` | Merge the input `Tree` with the other `Tree`. |
|
|
104
|
+
| `contentTemplate<T>(options: T)` | Apply a content template (see the Template section) to the entire `Tree`. |
|
|
105
|
+
| `pathTemplate<T>(options: T)` | Apply a path template (see the Template section) to the entire `Tree`. |
|
|
106
|
+
| `template<T>(options: T)` | Apply both path and content templates (see the Template section) to the entire `Tree`. |
|
|
107
|
+
| `filter(predicate: FilePredicate<boolean>)` | Returns the input `Tree` with files that do not pass the `FilePredicate`. |
|
|
98
108
|
|
|
99
109
|
# Templating
|
|
110
|
+
|
|
100
111
|
As referenced above, some functions are based upon a file templating system, which consists of path and content templating.
|
|
101
112
|
|
|
102
113
|
The system operates on placeholders defined inside files or their paths as loaded in the `Tree` and fills these in as defined in the following, using values passed into the `Rule` which applies the templating (i.e. `template<T>(options: T)`).
|
|
103
114
|
|
|
104
115
|
## Path Templating
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
|
108
|
-
|
|
|
116
|
+
|
|
117
|
+
| Placeholder | Description |
|
|
118
|
+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
119
|
+
| **variable** | Replaced with the value of `variable`. |
|
|
120
|
+
| **variable@function** | Replaced with the result of the call `function(variable)`. Can be chained to the left (`__variable@function1@function2__ ` etc). |
|
|
109
121
|
|
|
110
122
|
## Content Templating
|
|
111
|
-
| Placeholder | Description |
|
|
112
|
-
|---|---|
|
|
113
|
-
| <%= expression %> | Replaced with the result of the call of the given expression. This only supports direct expressions, no structural (for/if/...) JavaScript. |
|
|
114
|
-
| <%- expression %> | Same as above, but the value of the result will be escaped for HTML when inserted (i.e. replacing '<' with '<') |
|
|
115
|
-
| <% inline code %> | Inserts the given code into the template structure, allowing to insert structural JavaScript. |
|
|
116
|
-
| <%# text %> | A comment, which gets entirely dropped. |
|
|
117
123
|
|
|
124
|
+
| Placeholder | Description |
|
|
125
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
126
|
+
| <%= expression %> | Replaced with the result of the call of the given expression. This only supports direct expressions, no structural (for/if/...) JavaScript. |
|
|
127
|
+
| <%- expression %> | Same as above, but the value of the result will be escaped for HTML when inserted (i.e. replacing '<' with '<') |
|
|
128
|
+
| <% inline code %> | Inserts the given code into the template structure, allowing to insert structural JavaScript. |
|
|
129
|
+
| <%# text %> | A comment, which gets entirely dropped. |
|
|
118
130
|
|
|
119
131
|
# Examples
|
|
120
132
|
|
|
121
133
|
## Simple
|
|
134
|
+
|
|
122
135
|
An example of a simple Schematics which creates a "hello world" file, using an option to determine its path:
|
|
123
136
|
|
|
124
137
|
```typescript
|
|
125
|
-
import {Tree} from '@angular-devkit/schematics';
|
|
138
|
+
import { Tree } from '@angular-devkit/schematics';
|
|
126
139
|
|
|
127
140
|
export default function MySchematic(options: any) {
|
|
128
141
|
return (tree: Tree) => {
|
|
@@ -138,6 +151,7 @@ A few things from this example:
|
|
|
138
151
|
1. It returns a [`Rule`](src/engine/interface.ts#L73), which is a transformation from a `Tree` to another `Tree`.
|
|
139
152
|
|
|
140
153
|
## Templating
|
|
154
|
+
|
|
141
155
|
A simplified example of a Schematics which creates a file containing a new Class, using an option to determine its name:
|
|
142
156
|
|
|
143
157
|
```typescript
|
|
@@ -152,8 +166,15 @@ export class <%= classify(name) %> {
|
|
|
152
166
|
|
|
153
167
|
import { strings } from '@angular-devkit/core';
|
|
154
168
|
import {
|
|
155
|
-
Rule,
|
|
156
|
-
|
|
169
|
+
Rule,
|
|
170
|
+
SchematicContext,
|
|
171
|
+
SchematicsException,
|
|
172
|
+
Tree,
|
|
173
|
+
apply,
|
|
174
|
+
branchAndMerge,
|
|
175
|
+
mergeWith,
|
|
176
|
+
template,
|
|
177
|
+
url,
|
|
157
178
|
} from '@angular-devkit/schematics';
|
|
158
179
|
import { Schema as ClassOptions } from './schema';
|
|
159
180
|
|
|
@@ -163,15 +184,12 @@ export default function (options: ClassOptions): Rule {
|
|
|
163
184
|
throw new SchematicsException('Option (name) is required.');
|
|
164
185
|
}
|
|
165
186
|
|
|
166
|
-
const templateSource = apply(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}),
|
|
173
|
-
]
|
|
174
|
-
);
|
|
187
|
+
const templateSource = apply(url('./files'), [
|
|
188
|
+
template({
|
|
189
|
+
...strings,
|
|
190
|
+
...options,
|
|
191
|
+
}),
|
|
192
|
+
]);
|
|
175
193
|
|
|
176
194
|
return branchAndMerge(mergeWith(templateSource));
|
|
177
195
|
};
|
|
@@ -179,14 +197,16 @@ export default function (options: ClassOptions): Rule {
|
|
|
179
197
|
```
|
|
180
198
|
|
|
181
199
|
Additional things from this example:
|
|
200
|
+
|
|
182
201
|
1. `strings` provides the used `dasherize` and `classify` functions, among others.
|
|
183
202
|
1. The files are on-disk in the same root directory as the `index.ts` and loaded into a `Tree`.
|
|
184
203
|
1. Then the `template` `Rule` fills in the specified templating placeholders. For this, it only knows about the variables and functions passed to it via the options-object.
|
|
185
204
|
1. Finally, the resulting `Tree`, containing the new file, is merged with the existing files of the project which the Schematic is run on.
|
|
186
205
|
|
|
187
206
|
# Future Work
|
|
207
|
+
|
|
188
208
|
Schematics is not done yet. Here's a list of things we are considering:
|
|
189
209
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
210
|
+
- Smart defaults for Options. Having a JavaScript function for default values based on other default values.
|
|
211
|
+
- Prompt for input options. This should only be prompted for the original schematics, dependencies to other schematics should not trigger another prompting.
|
|
212
|
+
- Tasks for running tooling-specific jobs before and after a schematics has been scaffolded. Such tasks can involve initialize git, or npm install. A specific list of tasks should be provided by the tool, with unsupported tasks generating an error.
|
package/collection-schema.json
CHANGED
|
@@ -59,17 +59,12 @@
|
|
|
59
59
|
"description": "Whether or not this schematic can be called from an external schematic, or a tool. This implies hidden: true."
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"required": [
|
|
63
|
-
"factory",
|
|
64
|
-
"description"
|
|
65
|
-
]
|
|
62
|
+
"required": ["factory", "description"]
|
|
66
63
|
}
|
|
67
64
|
},
|
|
68
65
|
"version": {
|
|
69
66
|
"type": "string"
|
|
70
67
|
}
|
|
71
68
|
},
|
|
72
|
-
"required": [
|
|
73
|
-
"schematics"
|
|
74
|
-
]
|
|
69
|
+
"required": ["schematics"]
|
|
75
70
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-devkit/schematics",
|
|
3
|
-
"version": "12.0.0
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Angular Schematics - Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"typings": "src/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"schematics"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@angular-devkit/core": "12.0.0
|
|
21
|
+
"@angular-devkit/core": "12.0.0",
|
|
22
22
|
"ora": "5.4.0",
|
|
23
23
|
"rxjs": "6.6.7"
|
|
24
24
|
},
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"url": "https://github.com/angular/angular-cli.git"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": "
|
|
30
|
+
"node": "^12.14.1 || ^14.0.0",
|
|
31
31
|
"npm": "^6.11.0 || ^7.5.6",
|
|
32
32
|
"yarn": ">= 1.13.0"
|
|
33
33
|
},
|
package/src/_golden-api.d.ts
CHANGED
package/src/_golden-api.js
CHANGED
package/src/engine/engine.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
/**
|
|
3
2
|
* @license
|
|
4
|
-
* Copyright Google
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
4
|
*
|
|
6
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
6
|
* found in the LICENSE file at https://angular.io/license
|
|
8
7
|
*/
|
|
8
|
+
/// <reference types="node" />
|
|
9
9
|
import { BaseException } from '@angular-devkit/core';
|
|
10
10
|
import { Observable } from 'rxjs';
|
|
11
11
|
import { Url } from 'url';
|
package/src/engine/engine.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchematicEngine = exports.TaskScheduler = exports.CollectionImpl = exports.UnknownTaskDependencyException = exports.UnregisteredTaskException = exports.SchematicEngineConflictingException = exports.PrivateSchematicException = exports.UnknownSchematicException = exports.CircularCollectionException = exports.UnknownCollectionException = exports.UnknownUrlSourceProtocol = void 0;
|
|
4
2
|
/**
|
|
5
3
|
* @license
|
|
6
|
-
* Copyright Google
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
7
5
|
*
|
|
8
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
9
7
|
* found in the LICENSE file at https://angular.io/license
|
|
10
8
|
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SchematicEngine = exports.TaskScheduler = exports.CollectionImpl = exports.UnknownTaskDependencyException = exports.UnregisteredTaskException = exports.SchematicEngineConflictingException = exports.PrivateSchematicException = exports.UnknownSchematicException = exports.CircularCollectionException = exports.UnknownCollectionException = exports.UnknownUrlSourceProtocol = void 0;
|
|
11
11
|
const core_1 = require("@angular-devkit/core");
|
|
12
12
|
const rxjs_1 = require("rxjs");
|
|
13
13
|
const operators_1 = require("rxjs/operators");
|
|
@@ -16,11 +16,15 @@ const null_1 = require("../tree/null");
|
|
|
16
16
|
const static_1 = require("../tree/static");
|
|
17
17
|
const schematic_1 = require("./schematic");
|
|
18
18
|
class UnknownUrlSourceProtocol extends core_1.BaseException {
|
|
19
|
-
constructor(url) {
|
|
19
|
+
constructor(url) {
|
|
20
|
+
super(`Unknown Protocol on url "${url}".`);
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
exports.UnknownUrlSourceProtocol = UnknownUrlSourceProtocol;
|
|
22
24
|
class UnknownCollectionException extends core_1.BaseException {
|
|
23
|
-
constructor(name) {
|
|
25
|
+
constructor(name) {
|
|
26
|
+
super(`Unknown collection "${name}".`);
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
exports.UnknownCollectionException = UnknownCollectionException;
|
|
26
30
|
class CircularCollectionException extends core_1.BaseException {
|
|
@@ -42,7 +46,9 @@ class PrivateSchematicException extends core_1.BaseException {
|
|
|
42
46
|
}
|
|
43
47
|
exports.PrivateSchematicException = PrivateSchematicException;
|
|
44
48
|
class SchematicEngineConflictingException extends core_1.BaseException {
|
|
45
|
-
constructor() {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(`A schematic was called from a different engine as its parent.`);
|
|
51
|
+
}
|
|
46
52
|
}
|
|
47
53
|
exports.SchematicEngineConflictingException = SchematicEngineConflictingException;
|
|
48
54
|
class UnregisteredTaskException extends core_1.BaseException {
|
|
@@ -64,8 +70,12 @@ class CollectionImpl {
|
|
|
64
70
|
this._engine = _engine;
|
|
65
71
|
this.baseDescriptions = baseDescriptions;
|
|
66
72
|
}
|
|
67
|
-
get description() {
|
|
68
|
-
|
|
73
|
+
get description() {
|
|
74
|
+
return this._description;
|
|
75
|
+
}
|
|
76
|
+
get name() {
|
|
77
|
+
return this.description.name || '<unknown>';
|
|
78
|
+
}
|
|
69
79
|
createSchematic(name, allowPrivate = false) {
|
|
70
80
|
return this._engine.createSchematic(name, this, allowPrivate);
|
|
71
81
|
}
|
|
@@ -91,7 +101,7 @@ class TaskScheduler {
|
|
|
91
101
|
if (!dependencies) {
|
|
92
102
|
return new Set();
|
|
93
103
|
}
|
|
94
|
-
const tasks = dependencies.map(dep => {
|
|
104
|
+
const tasks = dependencies.map((dep) => {
|
|
95
105
|
const task = this._taskIds.get(dep);
|
|
96
106
|
if (!task) {
|
|
97
107
|
throw new UnknownTaskDependencyException(dep);
|
|
@@ -131,8 +141,12 @@ class SchematicEngine {
|
|
|
131
141
|
this._schematicCache = new WeakMap();
|
|
132
142
|
this._taskSchedulers = new Array();
|
|
133
143
|
}
|
|
134
|
-
get workflow() {
|
|
135
|
-
|
|
144
|
+
get workflow() {
|
|
145
|
+
return this._workflow || null;
|
|
146
|
+
}
|
|
147
|
+
get defaultMergeStrategy() {
|
|
148
|
+
return this._host.defaultMergeStrategy || interface_1.MergeStrategy.Default;
|
|
149
|
+
}
|
|
136
150
|
createCollection(name, requester) {
|
|
137
151
|
let collection = this._collectionCache.get(name);
|
|
138
152
|
if (collection) {
|
|
@@ -175,13 +189,12 @@ class SchematicEngine {
|
|
|
175
189
|
interactive = parent.interactive;
|
|
176
190
|
}
|
|
177
191
|
let context = {
|
|
178
|
-
debug: parent && parent.debug || false,
|
|
192
|
+
debug: (parent && parent.debug) || false,
|
|
179
193
|
engine: this,
|
|
180
|
-
logger: (parent && parent.logger && parent.logger.createChild(schematic.description.name))
|
|
181
|
-
|
|
194
|
+
logger: (parent && parent.logger && parent.logger.createChild(schematic.description.name)) ||
|
|
195
|
+
new core_1.logging.NullLogger(),
|
|
182
196
|
schematic,
|
|
183
|
-
strategy:
|
|
184
|
-
? parent.strategy : this.defaultMergeStrategy,
|
|
197
|
+
strategy: parent && parent.strategy !== undefined ? parent.strategy : this.defaultMergeStrategy,
|
|
185
198
|
interactive,
|
|
186
199
|
addTask,
|
|
187
200
|
};
|
|
@@ -251,8 +264,10 @@ class SchematicEngine {
|
|
|
251
264
|
}
|
|
252
265
|
createSourceFromUrl(url, context) {
|
|
253
266
|
switch (url.protocol) {
|
|
254
|
-
case 'null:':
|
|
255
|
-
|
|
267
|
+
case 'null:':
|
|
268
|
+
return () => new null_1.NullTree();
|
|
269
|
+
case 'empty:':
|
|
270
|
+
return () => static_1.empty();
|
|
256
271
|
default:
|
|
257
272
|
const hostSource = this._host.createSourceFromUrl(url, context);
|
|
258
273
|
if (!hostSource) {
|
|
@@ -263,15 +278,13 @@ class SchematicEngine {
|
|
|
263
278
|
}
|
|
264
279
|
executePostTasks() {
|
|
265
280
|
const executors = new Map();
|
|
266
|
-
const taskObservable = rxjs_1.from(this._taskSchedulers)
|
|
267
|
-
.pipe(operators_1.concatMap(scheduler => scheduler.finalize()), operators_1.concatMap(task => {
|
|
281
|
+
const taskObservable = rxjs_1.from(this._taskSchedulers).pipe(operators_1.concatMap((scheduler) => scheduler.finalize()), operators_1.concatMap((task) => {
|
|
268
282
|
const { name, options } = task.configuration;
|
|
269
283
|
const executor = executors.get(name);
|
|
270
284
|
if (executor) {
|
|
271
285
|
return executor(options, task.context);
|
|
272
286
|
}
|
|
273
|
-
return this._host.createTaskExecutor(name)
|
|
274
|
-
.pipe(operators_1.concatMap(executor => {
|
|
287
|
+
return this._host.createTaskExecutor(name).pipe(operators_1.concatMap((executor) => {
|
|
275
288
|
executors.set(name, executor);
|
|
276
289
|
return executor(options, task.context);
|
|
277
290
|
}));
|
package/src/engine/index.d.ts
CHANGED
package/src/engine/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
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
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
@@ -10,13 +17,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
18
|
};
|
|
12
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
/**
|
|
14
|
-
* @license
|
|
15
|
-
* Copyright Google Inc. All Rights Reserved.
|
|
16
|
-
*
|
|
17
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
18
|
-
* found in the LICENSE file at https://angular.io/license
|
|
19
|
-
*/
|
|
20
20
|
__exportStar(require("./engine"), exports);
|
|
21
21
|
__exportStar(require("./interface"), exports);
|
|
22
22
|
__exportStar(require("./schematic"), exports);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
/**
|
|
3
2
|
* @license
|
|
4
|
-
* Copyright Google
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
4
|
*
|
|
6
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
6
|
* found in the LICENSE file at https://angular.io/license
|
|
8
7
|
*/
|
|
8
|
+
/// <reference types="node" />
|
|
9
9
|
import { analytics, logging } from '@angular-devkit/core';
|
|
10
10
|
import { Observable } from 'rxjs';
|
|
11
11
|
import { Url } from 'url';
|
package/src/engine/interface.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
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
|
+
*/
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/src/engine/schematic.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchematicImpl = exports.InvalidSchematicsNameException = void 0;
|
|
4
2
|
/**
|
|
5
3
|
* @license
|
|
6
|
-
* Copyright Google
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
7
5
|
*
|
|
8
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
9
7
|
* found in the LICENSE file at https://angular.io/license
|
|
10
8
|
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SchematicImpl = exports.InvalidSchematicsNameException = void 0;
|
|
11
11
|
const core_1 = require("@angular-devkit/core");
|
|
12
12
|
const rxjs_1 = require("rxjs");
|
|
13
13
|
const operators_1 = require("rxjs/operators");
|
|
@@ -29,12 +29,17 @@ class SchematicImpl {
|
|
|
29
29
|
throw new InvalidSchematicsNameException(_description.name);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
get description() {
|
|
33
|
-
|
|
32
|
+
get description() {
|
|
33
|
+
return this._description;
|
|
34
|
+
}
|
|
35
|
+
get collection() {
|
|
36
|
+
return this._collection;
|
|
37
|
+
}
|
|
34
38
|
call(options, host, parentContext, executionOptions) {
|
|
35
39
|
const context = this._engine.createContext(this, parentContext, executionOptions);
|
|
36
|
-
return host
|
|
37
|
-
.
|
|
40
|
+
return host.pipe(operators_1.first(), operators_1.concatMap((tree) => this._engine
|
|
41
|
+
.transformOptions(this, options, context)
|
|
42
|
+
.pipe(operators_1.map((o) => [tree, o]))), operators_1.concatMap(([tree, transformedOptions]) => {
|
|
38
43
|
let input;
|
|
39
44
|
let scoped = false;
|
|
40
45
|
if (executionOptions && executionOptions.scope) {
|
|
@@ -44,7 +49,7 @@ class SchematicImpl {
|
|
|
44
49
|
else {
|
|
45
50
|
input = tree;
|
|
46
51
|
}
|
|
47
|
-
return call_1.callRule(this._factory(transformedOptions), rxjs_1.of(input), context).pipe(operators_1.map(output => {
|
|
52
|
+
return call_1.callRule(this._factory(transformedOptions), rxjs_1.of(input), context).pipe(operators_1.map((output) => {
|
|
48
53
|
if (output === input) {
|
|
49
54
|
return tree;
|
|
50
55
|
}
|