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
{{ message }}
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: packages/schematics/README.md
+97-8Lines changed: 97 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -26,15 +26,94 @@ The tooling is responsible for the following tasks:
26
26
27
27
1. Create the Schematic Engine, and pass in a Collection and Schematic loader.
28
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.
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, parses the arguments as a JSON object and validate it with the Schema specified by the collection.
30
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
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
32
1. Output any logs propagated by the library, including debugging information.
33
33
34
34
The tooling API is composed of the following pieces:
35
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
36
+
## EngineHost
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, how to create a `SchematicDescription` from a `CollectionDescription` and a name, as well as how to create the `Rule` factory for that Schematics. Both of which are information necessary for the `Engine` to work properly.
38
+
39
+
All Description interfaces are generics that take interfaces as type parameters. Those interfaces can be used by the tooling to store additional information in the `CollectionDescription` and the `SchematicDescription`. The descriptions returned by the host are guaranteed to be the same objects when passing them as input.
40
+
41
+
### CollectionDescription
42
+
A `CollectionDescription` is the minimum amount of information that `Engine` needs to create a collection. It is currently only a `name`, which is used to validate the collection and cache it.
43
+
44
+
### SchematicDescription
45
+
A `SchematicDescription` is the minimum amount of information that `Engine` needs to create a schematic. It is currently a `name` (which is used to be cached), and a `CollectionDescription`. The collection description is asserted to be the same description as passed in. It is used later on to reference collections when schematics are created by name only.
46
+
47
+
### Source from URL
48
+
It is possible for schematics to create `Source`s from a URL. These are useful when we want to load a list of template files. There are 3 default URL protocols supported by the Engine:
49
+
50
+
-`null:` returns a Tree that's invalid and will throw exceptions.
51
+
-`empty:` returns a Tree that's empty.
52
+
-`host:` returns a copy of the host passed to this schematic, from the context.
53
+
54
+
### RuleFactory
55
+
The other method necessary to resolve a schematics is the `RuleFactory`, a function that takes an option argument and returns a `Rule`. That factory is created from both descriptions by the host and the result will be called by the Engine when necessary. Please note that the engine cache this `RuleFactory` based on both descriptions, so if a schematic is created twice the `getSchematicRuleFactory` host function will only be called once.
56
+
57
+
### Default MergeStrategy
58
+
The `EngineHost` can have an optional `defaultMergeStrategy` to specify how the tooling wants to set the default `MergeStrategy`. This will be used if schematics don't specify a merge strategy on their own.
59
+
60
+
## EngineHost Implementations
61
+
62
+
### NodeModulesEngineHost
63
+
The Schematics library provides an EngineHost that understands NPM node modules, using node modules to define collections and schematics.
64
+
65
+
This engine host use the following conventions:
66
+
67
+
1. A node package needs to define a `schematics` key in its `package.json`, which points to a JSON file that contains collection metadata. This metadata is of the follpwing type:
import {apply, mergeWith, template, url} from '@angular/schematics';
139
+
140
+
export default function(options: any) {
141
+
return mergeWith([
142
+
apply(url('./files'), [
143
+
template({ utils: stringUtils, ...options })
144
+
])
145
+
]);
146
+
};
147
+
```
60
148
61
149
62
150
# FutureWork
@@ -66,4 +154,5 @@ Schematics is not done yet. Here's a list of things we are considering:
66
154
*SmartdefaultsforOptions. HavingaJavaScriptfunction for default values based on other default values.
67
155
* Prompt for input options. This should only be prompted for the original schematics, dependencies to other schematics should not trigger another prompting.
68
156
* 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
-
157
+
* Better URL support for more consistency. Right now tools define their own URLs without having consistency between two tools, which means that there is still some cohesion between the schematic and the tool.
158
+
* Annotation support. Annotations are being designed right now, but they will be a type-safe way to attach metadata to a file that is updated if the file changes content. Such Annotation could tell if a file is, e.g., a test file, or binary, or the annotation could be the TypeScript AST of the file itself.
0 commit comments