Repository navigation
Exercise 4: apply
Kevin Schuchard edited this page Apr 30, 2019
·
14 revisions
The remaining exercises will happen in this repo, schematics-workshop. Switch back to this repository and check out the appropriate branch for each exercise.
Checkout the apply branch:
npm run clean
git checkout -f applyOpen the src/schematic-starter/index.ts file.
This exercise is similar to creating files with the tree.create() command, only here we're reading from a directory and optionally applying Rules against the template.
- Use the
url()function to retrieve the source from the'./files'directory.
const source = url('./files')- use the
apply()function to apply rules (empty for now) and invoke it with thecontext
return apply(source, rules)(context)npm testYou should have an index.html in the root of the sandbox folder. This file was read from the src/schematic-starter/files directory by the schematic executed in the sandbox.
Since the sandbox is version controlled, you can visually see the changes the schematic makes using your editor or git diff tool of choice.
- Try adding a nested folder and files in the
src/schematics-starter/filesfolder. - Use your version control system to see what files have changed. In the VSCode menu
View > SCM