You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/angular/schematics/README.md
+15-6Lines changed: 15 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ What distinguish Schematics from other generators, such as Yeoman or Yarn Create
20
20
|**Sink**| The final destination of all `Action`s. |
21
21
22
22
# Tooling
23
-
Schematics is a library, and does not work by itself. A reference CLI is available in [`@angular/schematics-cli`](../schematics_cli/README.md). This document explain the library usage and the tooling API, but does not go into the tool implementation itself.
23
+
Schematics is a library, and does not work by itself. A [reference CLI](https://github.com/angular/devkit/tree/master/packages/_schematics_cli) is available on this repository, but is not published on NPM. This document explain the library usage and the tooling API, but does not go into the tool implementation itself.
24
24
25
25
The tooling is responsible for the following tasks:
26
26
@@ -34,7 +34,19 @@ The tooling is responsible for the following tasks:
34
34
The tooling API is composed of the following pieces:
35
35
36
36
## Engine
37
-
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 `Schematic
37
+
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`.
38
+
39
+
# Schematics (Generators)
40
+
Schematics are generators and part of a `Collection`.
41
+
42
+
## Collection
43
+
A Collection is defined by a `collection.json` file (in the reference CLI). This JSON defines the following properties:
44
+
45
+
| Prop Name | Type | Description |
46
+
|---|---|---|
47
+
|**name**|`string`| The name of the collection. |
48
+
| **version** | `string` | Unused fi
49
+
38
50
39
51
# Examples
40
52
@@ -57,13 +69,10 @@ A few things from this example:
57
69
1. The function receives the list of options from the tooling.
58
70
1. It returns a [`Rule`](src/engine/interface.ts#L73), which is a transformation from a `Tree` to another `Tree`.
59
71
60
-
61
-
62
72
# Future Work
63
73
64
74
Schematics is not done yet. Here's a list of things we are considering:
65
75
66
76
* Smart defaults for Options. Having a JavaScript function for default values based on other default values.
67
77
* Prompt for input options. This should only be prompted for the original schematics, dependencies to other schematics should not trigger another prompting.
68
-
* 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.
69
-
78
+
* 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.
Schematics are generators that transform an existing filesystem. It can create files, refactor existing files, or move files around.
6
6
7
-
What distinguish 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
-
9
-
# Glossary
10
-
11
-
| Term | Description |
12
-
|------|-------------|
13
-
|**Schematics**| A generator that execute 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**| A 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. |
21
-
22
-
# Tooling
23
-
Schematics is a library, and does not work by itself. A reference CLI is available in [`@angular/schematics-cli`](../schematics_cli/README.md). This document explain the library usage and the tooling API, but does not go into the tool implementation itself.
24
-
25
-
The tooling is responsible for the following tasks:
26
-
27
-
1. Create the Schematic Engine, and pass in a Collection and Schematic loader.
28
-
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
-
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, parse the arguments as a JSON object and validate it with the Schema specified by the collection.
30
-
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.
31
-
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.
32
-
1. Output any logs propagated by the library, including debugging information.
33
-
34
-
The tooling API is composed of the following pieces:
35
-
36
-
## Engine
37
-
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 `Schematic
38
-
39
-
# Examples
40
-
41
-
## Simple
42
-
An example of a simple Schematics which creates a "hello world" file, using an option to determine its path:
43
-
44
-
```typescript
45
-
import {Tree} from'@angular/schematics';
46
-
47
-
exportdefaultfunction MySchematic(options:any) {
48
-
return (tree:Tree) => {
49
-
tree.create(options.path+'/hi', 'Hello world!');
50
-
returntree;
51
-
};
52
-
}
53
-
```
54
-
55
-
A few things from this example:
56
-
57
-
1. The function receives the list of options from the tooling.
58
-
1. It returns a [`Rule`](src/engine/interface.ts#L73), which is a transformation from a `Tree` to another `Tree`.
59
-
60
-
61
-
62
-
# Future Work
63
-
64
-
Schematics is not done yet. Here's a list of things we are considering:
65
-
66
-
* Smart defaults for Options. Having a JavaScript function for default values based on other default values.
67
-
* Prompt for input options. This should only be prompted for the original schematics, dependencies to other schematics should not trigger another prompting.
68
-
* 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.
69
-
7
+
This library has helpers and conventions for making tools that uses the Schematics as backend to run generators.
0 commit comments