嵌套Angular添加原理图

Nested Angular add schematics

我有一个项目 Child,它有一个添加原理图。如果 Child 成为项目 Parent 的依赖项,该项目也有添加原理图,ng-cli 将如何处理?我没有看到任何对 ng add 级联或调用依赖模式的引用。 Parent 是否需要复制 Child 的原理图,或者有没有办法在 Parent 原理图中手动调用 Child 的原理图?

我真的希望文档更好,但解决方案最终是两件事的结合:

首先你可以像这样调用外部原理图:

externalSchematic('@keysight/alloy', 'ng-add', options)

但是,仅此还不够,因为它无法找到您的包裹。您需要先安装它。这是最终解决方案:

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一定是自己在collection.json中的原理图:

    "addExternals": {
      "description": "Calls dependency add schemas",
      "private": true,
      "factory": "./ng-add/index#addExternals"
    }