import { Rule, Tree, chain, applyTemplates, apply, url, SchematicsException, noop, mergeWith } from "@angular-devkit/schematics"; import { strings } from "@angular-devkit/core"; import { getProject, buildDefaultPath } from "../utility/project"; import { parseName } from '../utility/parse-name'; import { applyLintFix } from '../utility/lint-fix'; export default function(options: any): Rule { return (host: Tree) => { if (!options.project) { throw new SchematicsException('Option (project) is required.'); } const project = getProject(host, options.project); // console.log(`project `, project); // console.log(`project `, host); // console.log(`options 1 `, options); if (options.path === undefined) { options.path = buildDefaultPath(project); } const parsedPath = parseName(options.path, options.name); // console.log(`options `, options); // console.log(`project `, project); // console.log(`buildDefaultPath `, buildDefaultPath(project)); // console.log(`parsedPath `, parsedPath); options.name = parsedPath.name; options.path = parsedPath.path; const templateSource = apply(url('./files'), [ applyTemplates({ ...strings, 'if-flat': (s: string) => options.flat ? '' : s, ...options, }) ]); return chain([ mergeWith(templateSource), options.lintFix ? applyLintFix(options.path) : noop(), ]); }; }