Skip to content

Instantly share code, notes, and snippets.

@doriansmiley
Created December 28, 2020 05:20
Show Gist options
  • Select an option

  • Save doriansmiley/d9d0a285d2dbc3343363af2399aad134 to your computer and use it in GitHub Desktop.

Select an option

Save doriansmiley/d9d0a285d2dbc3343363af2399aad134 to your computer and use it in GitHub Desktop.
Angular Schematic for Generating TypeScript Packages
{
"$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"
}
}
}
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);
}
}
{
"$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