| Sep | OCT | Nov |
| 04 | ||
| 2019 | 2020 | 2021 |
COLLECTED BY
Collection: Arquivo.pt: the Portuguese web-archive
| Term | Description |
|---|---|
| Schematics | A generator that executes descriptive code without side effects on an existing file system. |
| Collection | A list of schematics metadata. Schematics can be referred by name inside a collection. |
| Tool | The code using the Schematics library. |
| Tree | A staging area for changes, containing the original file system, and a list of changes to apply to it. |
| Rule | A function that applies actions to a Tree. It returns a new Tree that will contain all transformations to be applied. |
| 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. |
| Action | An atomic operation to be validated and committed to a filesystem or a Tree. Actions are created by schematics. |
| Sink | The final destination of all Actions. |
SchematicEngine is responsible for loading and constructing Collections 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.
Collection.
collection.json file (in the reference CLI). This JSON defines the following properties:
| Prop Name | Type | Description |
|---|---|---|
| name | string |
The name of the collection. |
| version | string |
Unused field. |
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.
FileOperators apply changes to a single FileEntry and return a new FileEntry. The result follows these rules:
(一)If the FileEntry returned is null, a DeleteAction will be added to the action list.
(二)If the path changed, a RenameAction will be added to the action list.
(三)If the content changed, an OverwriteAction will be added to the action list.
It is impossible to create files using a FileOperator.
Operator factories by default that cover basic use cases:
| FileOperator | Description |
|---|---|
contentTemplate<T>(options: T) |
Apply a content template (see the Template section) |
pathTemplate<T>(options: T) |
Apply a path template (see the Template section) |
Source factories by default:
| Source | Description |
|---|---|
empty() |
Creates a source that returns an empty Tree. |
source(tree: Tree) |
Creates a Source that returns the Tree passed in as argument. |
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. |
apply(source: Source, rules: Rule[]) |
Apply a list of Rules to a source, and return the resulting Source. |
Rule factories by default:
| Rule | Description |
|---|---|
noop() |
Returns the input Tree as is. |
chain(rules: Rule[]) |
Returns a Rule that's the concatenation of other Rules. |
forEach(op: FileOperator) |
Returns a Rule that applies an operator to every file of the input Tree. |
move(root: string) |
Moves all the files from the input to a subdirectory. |
merge(other: Tree) |
Merge the input Tree with the other Tree. |
contentTemplate<T>(options: T) |
Apply a content template (see the Template section) to the entire Tree. |
pathTemplate<T>(options: T) |
Apply a path template (see the Template section) to the entire Tree. |
template<T>(options: T) |
Apply both path and content templates (see the Template section) to the entire Tree. |
filter(predicate: FilePredicate<boolean>) |
Returns the input Tree with files that do not pass the FilePredicate. |
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)).
| Placeholder | Description |
|---|---|
| variable | Replaced with the value of variable. |
| variable@function | Replaced with the result of the call function(variable). Can be chained to the left (__variable@function1@function2__ etc). |
| Placeholder | Description |
|---|---|
| <%= expression %> | Replaced with the result of the call of the given expression. This only supports direct expressions, no structural (for/if/...) JavaScript. |
| <%- expression %> | Same as above, but the value of the result will be escaped for HTML when inserted (i.e. replacing '<' with '<') |
| <% inline code %> | Inserts the given code into the template structure, allowing to insert structural JavaScript. |
| <%# text %> | A comment, which gets entirely dropped. |
A few things from this example: (一)The function receives the list of options from the tooling. (二)It returns a;
Rule, which is a transformation from a Tree to another Tree.
// files/__name@dasherize__.ts
Additional things from this example: (一)// index.ts;;;
strings provides the used dasherize and classify functions, among others.
(二)The files are on-disk in the same root directory as the index.ts and loaded into a Tree.
(三)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.
(四)Finally, the resulting Tree, containing the new file, is merged with the existing files of the project which the Schematic is run on.
npm i @angular-devkit/schematics