Как я могу расширить angular schemati c свойства? - PullRequest
3 голосов
/ 29 января 2020

Мой вопрос, возможно ли расширить свойства схемы?

Что я пробовал:
collection. json

{
  "$schema": "http://schema.angular.io/schematics/collection/2",
  "name": "@my/schematics",
  "description": "my default collection, containing all schematics that are used normally",
  "schematics": {
    "library": {
      "extends": "@nrwl/angular:library", <--- extends nrwl library
      "aliases": [ "lib" ],
      "factory": "./library",
      "description": "Create my library.",
      "schema": "./library/schema.json"
    }
}

library / schema. json

{
  "$schema": "http://schema.angular.io/schematics/collection/2",
  "id": "SchematicsAngularLibrary",
  "title": "Create my library",
  "type": "object",
  "properties": {
    "legacy": {    <--- adds custom property
      "type": "boolean",
      "description": "Legacy mode",
      "default": false
    }
  },
  "required": []
}

и моя упрощенная схема библиотеки / index.ts

import { chain, externalSchematic, Rule, Tree, SchematicContext } from '@angular-devkit/schematics';

export default function(schema: Schema): Rule {
  return function(host: Tree, context: SchematicContext) {
    const isLegacyMode = schema.legacy; // <--- this is what I am trying to achieve

    return chain([
      externalSchematic('@nrwl/angular', 'library', options),
    ])(host, context);
  };
}

Но похоже, что схемы c не были расширены, потому что когда я запускаю
ng g lib megalib --unitTestRunner=jest --legacy
это выдает эту ошибку:
Unknown option: '--legacy'

Почему я хочу расширить (не копировать): когда будет обновлена ​​схема nrwl/angular и код схемы c, я тоже получу эти изменения.

Среда:
angular/* 9.0.0-r c .8
@nrwl/* 8.11.1

UPD:

Также я пытался использовать $ref в сочетании с allOf, но он работает только с http, см. эту проблему.

...