Created
December 28, 2020 05:20
-
-
Save doriansmiley/d9d0a285d2dbc3343363af2399aad134 to your computer and use it in GitHub Desktop.
Angular Schematic for Generating TypeScript Packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json", | |
| "schematics": { | |
| "create": { | |
| "description": "Creates a stub TypeScript project.", | |
| "factory": "./create/index#create", | |
| "schema": "./create/schema.json" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| Rule, | |
| SchematicContext, | |
| Tree, | |
| apply, | |
| mergeWith, | |
| chain, | |
| url, | |
| move, | |
| MergeStrategy, template, | |
| } from '@angular-devkit/schematics'; | |
| import {strings} from '@angular-devkit/core'; | |
| import {Schema} from './schema'; | |
| export function create(_options: Schema): Rule { | |
| return (host: Tree, _context: SchematicContext) => { | |
| const {dst} = _options; | |
| _context.logger.info( JSON.stringify({..._options})); | |
| const templateSource = apply(url('./files'), [ | |
| template({ | |
| ..._options, | |
| ...strings | |
| }), | |
| move(dst), | |
| ]); | |
| const rule = chain([ | |
| mergeWith(templateSource, MergeStrategy.Overwrite) | |
| ]); | |
| return rule(host, _context); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "http://json-schema.org/schema", | |
| "id": "typescript-starter-create", | |
| "title": "TypeScript project stub schematic", | |
| "type": "object", | |
| "properties": { | |
| "name": { | |
| "x-prompt": "Enter your project name.", | |
| "type": "string", | |
| "description": "The name of the project.", | |
| "$default": { | |
| "$source": "argv", | |
| "index": 0 | |
| } | |
| }, | |
| "dst": { | |
| "x-prompt": "Enter your destination.", | |
| "type": "string", | |
| "description": "The destination directory to be written to.", | |
| "$default": { | |
| "$source": "argv", | |
| "index": 1 | |
| } | |
| } | |
| }, | |
| "required": ["name", "dst"], | |
| "additionalProperties": false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment