【发布时间】:2019-06-21 16:41:59
【问题描述】:
在 @angular-devkit/schematics readme 中,我对 ClassOptions 的作用感到困惑。
如果将代码添加到项目中,则会显示错误,因为该文件不存在。
想知道这是做什么用的 + 一个例子?
import { strings } from '@angular-devkit/core';
import {
Rule, SchematicContext, SchematicsException, Tree,
apply, branchAndMerge, mergeWith, template, url,
} from '@angular-devkit/schematics';
import { Schema as ClassOptions } from './schema';
export default function (options: ClassOptions): Rule {
return (tree: Tree, context: SchematicContext) => {
if (!options.name) {
throw new SchematicsException('Option (name) is required.');
}
const templateSource = apply(
url('./files'),
[
template({
...strings,
...options,
}),
]
);
return branchAndMerge(mergeWith(templateSource));
};
}
【问题讨论】:
标签: angular angular-cli angular-schematics angular-devkit