This file contains 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
expect(tree.readContent("/projects/bar/src/app/test/test.ts")) | |
.toContain( | |
"export class Test {\n" + | |
"\n" + | |
"}" | |
); |
This file contains 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 {getWorkspace} from '@schematics/angular/utility/config'; | |
import {buildDefaultPath} from '@schematics/angular/utility/project'; | |
import {parseName} from '@schematics/angular/utility/parse-name'; | |
import {Tree} from '@angular-devkit/schematics'; | |
export function setupOptions(host: Tree, options: any): Tree { | |
const workspace = getWorkspace(host); | |
if (!options.project) { | |
options.project = Object.keys(workspace.projects)[0]; | |
} |
This file contains 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
const movePath = (options.flat) ? | |
normalize(options.path) : | |
normalize(options.path + '/' + strings.dasherize(options.name)); |
This file contains 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
const templateSource = apply(url('./files'), [ | |
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')), | |
template({ | |
...strings, | |
...options, | |
}), | |
move(movePath), | |
]); |
This file contains 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
const rule = mergeWith(templateSource, MergeStrategy.Default); |
This file contains 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
export function simpleSchematic(options: any): Rule { | |
return (tree: Tree, _context: SchematicContext) => { | |
setupOptions(tree, options); | |
const movePath = (options.flat) ? | |
normalize(options.path) : | |
normalize(options.path + '/' + strings.dasherize(options.name)); | |
const templateSource = apply(url('./files'), [ | |
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')), |
This file contains 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
export class Hello { | |
} |
This file contains 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
export class <%= classify(name) %> { | |
} |
This file contains 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": "simpleSchema", | |
"title": "Creates a simple schematic.", | |
"type": "object", | |
"properties": { | |
"project": { | |
"type": "string", | |
"description": "The name of the project.", | |
"$default": { |
This file contains 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": { | |
"simple-schematic": { | |
"description": "A basic schematic.", | |
"factory": "./simple-schematic/index#simpleSchematic", | |
"schema": "./simple-schematic/schema.json" | |
} | |
} | |
} |