[英]Nested Angular add schematics
I have a project Child that has an add schematic.我有一个项目 Child,它有一个添加原理图。 If Child becomes a dependency of a project Parent which also has an add schematic, how would ng-cli handle this?如果 Child 成为项目 Parent 的依赖项,该项目也有添加原理图,ng-cli 将如何处理? I don't see any references to ng add
cascading or calling through to dependency schemas.我没有看到任何对ng add
级联或调用依赖模式的引用。 Would Parent need to replicate Child's schematic, or is there a way to manually call through to Child's schematic in the Parent schematic? Parent 是否需要复制 Child 的原理图,或者有没有办法在 Parent 原理图中手动调用 Child 的原理图?
I really wish the documentation was better, but the solution ended up being a combination of two things:我真的希望文档更好,但解决方案最终是两件事的结合:
First you can call an external schematic like so:首先,您可以像这样调用外部原理图:
externalSchematic('@keysight/alloy', 'ng-add', options)
However, that alone is not enough since it won't be able to find your package.但是,仅此还不够,因为它无法找到您的包裹。 You'll need to install it first.您需要先安装它。 Here's the final solution:这是最终的解决方案:
export function ngAdd(options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
console.log('Adding Pathwave Core dependencies...\n');
dependencies.forEach(dep => addPackageJsonDependency(tree, dep));
const installTaskId = context.addTask(new NodePackageInstallTask());
// Chain won't work here since we need the externals to be actually installed before we call their schemas
// This ensures the externals are a dependency of the node install, so they exist when their schemas run.
context.addTask(new RunSchematicTask('addExternals', options), [installTaskId]);
};
}
export function addExternals(options: any): Rule {
return (_tree: Tree, _context: SchematicContext) => {
console.log('Running dependency schematics...\n');
return chain([
externalSchematic('@keysight/alloy', 'ng-add', options)
]);
};
}
addExternals
must be its own schematic in collection.json
: addExternals
在collection.json
中必须是它自己的原理图:
"addExternals": {
"description": "Calls dependency add schemas",
"private": true,
"factory": "./ng-add/index#addExternals"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.