Schematics Utilities - ?️ Useful exported utilities for working with Schematics
source link: https://www.tuicool.com/articles/hit/fYZjA3e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Schematics Utilities
At the moment, none of the utilities from the Angular Schematics package are exported.
This project was created from that purpose - providing a collection of general and useful utilities for Schematics, based on non-exported existing utilities and further .
You might use this project as a polyfill until these utilities will be exported officially by the relevant teams (and then just replace the path you import). However, consider sticking with this project for additional and unique utilities which are planned for the future.
How to Install
To Install using npm, simply do:
npm install schematics-utilities
How to Use
import { Rule, Tree } from '@angular-devkit/schematics'; // 1. Import the needed utilities import { addPackageJsonDependency, NodeDependency, NodeDependencyType } from 'schematics-utilities'; function addDependencies(host: Tree): Tree { const dependencies: NodeDependency[] = [ { type: NodeDependencyType.Default, version: '4.17.10', name: 'lodash-es' } ]; // 2. Just use it whenever you need :) dependencies.forEach(dependency => addPackageJsonDependency(host, dependency)); return host; } export default function(): Rule { return (tree: Tree) => { addDependencies(tree); return tree; }; }
Check out the API docs for the available utilities.
Disclaimer
This repository contains code which is directly taken from:
All credits go to the respective developers! :clap:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK