import { normalize } from '@angular-devkit/core'; import { apply, branchAndMerge, chain, mergeWith, move, Rule, SchematicContext, SchematicsException, template, Tree, url, } from '@angular-devkit/schematics'; import * as stringUtils from '../strings'; import { Schema as ModuleOptions } from './schema'; export default function (options: ModuleOptions): Rule { options.path = options.path ? normalize(options.path) : options.path; const sourceDir = options.sourceDir; if (!sourceDir) { throw new SchematicsException(`sourceDir option is required.`); } return (host: Tree, context: SchematicContext) => { const templateSource = apply(url('./files'), [ template({ ...stringUtils, 'if-flat': (s: string) => s, ...options as object, }), move(sourceDir), ]); return chain([ branchAndMerge(chain([ mergeWith(templateSource), ])), ])(host, context); }; }