我正在构建一个 Angular 自定义原理图。我创建了 files 目录,它看起来像这样:
我正在尝试将此组件添加到最终应用程序中。我的索引文件如下所示:
function addSideNav(options: any) {
return (host: Tree, context: SchematicContext) => {
try {
host.delete('src/app/app.component.html');
const workspace = getWorkspace(host);
if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
}
const project = getProject(host, options.project);
if (options.path === undefined) {
options.path = buildDefaultPath(project);
}
const templateSource = apply(url('./files'), [
template({
...options,
...strings
}),
move(options.path)
]);
// context.logger.log("info", `✅️ Added SideNav to the tree`);
return mergeWith(templateSource);
} catch (e) {
context.logger.log("error", ` Failed to add the SideNav to the tree`);
throw new SchematicsException(`Error detailes: ${e}`);
}};}
之后我这样调用这个函数:
export default function (options: any): Rule {
return chain([
addPackageJsonDependencies(),
installPackageJsonDependencies(),
addSideNav(options),
addMaterialStyle(options),
addPolyfillToScripts(options),
addToAppModule(options)
]); }
当我在本地使用 npm 链接对其进行测试时-效果很好。一切都创建得很好。
但是当我发布它 npm 并从 npm 安装它时 - 除了 ts 文件之外的所有文件都被创建:
side.nav.component.ts
而且我没有收到任何警告。
我在这里想念什么?