我的问题是可以扩展模式属性吗?
我尝试了什么:
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"
}
}
库/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);
};
}
但看起来原理图没有扩展,因为当我运行
ng g lib megalib --unitTestRunner=jest --legacy
它时会抛出这个错误:
Unknown option: '--legacy'
为什么我要扩展(不是复制):当nrwl/angular
架构和原理图代码更新时,我也会得到这些更改。
环境:
angular/*
9.0.0-rc.8
@nrwl/*
8.11.1
升级版:
我也尝试与$ref
结合使用allOf
,但它仅适用于http
,请参阅此问题。