Вложенные Angular добавить схемы - PullRequest
0 голосов
/ 21 января 2020

У меня есть проект Child, в котором есть схема добавления c. Если Child становится зависимостью от Parent проекта, который также имеет схему add c, как это будет обрабатывать ng-cli? Я не вижу никаких ссылок на ng add каскадирование или обращение к схемам зависимостей. Требуется ли для родителя реплицировать дочерние схемы c, или есть способ вручную вызвать дочерние схемы c в родительской схеме c?

1 Ответ

0 голосов
/ 22 января 2020

Я действительно с sh документация была лучше, но решение оказалось комбинацией двух вещей:

Сначала вы можете вызвать внешнюю схему c примерно так:

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 должно быть собственной схемой c в collection.json:

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