-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Bug Report or Feature Request (mark with an x
)
- [x ] bug report -> please search issues before submitting
- [ ] feature request
Area
- [ ] devkit
- [x ] schematics
Versions
Windows 10
Angular CLI: 6.0.8
Node: 8.11.3
OS: win32 x64
Angular:
...
Package Version
@angular-devkit/architect 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
Repro steps
- Install @angular/cli 6.0.8 globally
- Create a new schematic in C:\Projects\Schematics and do an npm install
- cwd should be C:\Projects\Schematics
- In the collection.json, add "extends": ["@schematics/angular"]
- In the collection.json, add an application schematic under the "schematics" collection like so:
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"extends": ["@schematics/angular"],
"schematics": {
"application": {
"description": "A blank schematic.",
"factory": "./application",
"schema": "./application/schema.json"
}
}
}
- In "./application/schema.json", add a required 'name' and 'directory' property
{
"$schema": "http://json-schema.org/schema",
"id": "testschema",
"title": "test schema",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"directory": {
"type": "string",
"format": "path",
"description": "The directory name to create the app in.",
"alias": "dir"
}
},
"required": [
"name",
"directory"
]
}
-
in the schematic's package.json, change the 'name' to test-schematic
-
npm run build
-
npm link
-
cd to C:\Projects
-
npm link test-schematic
-
npm install
-
ng new --collection=test-schematic --name=test --directory=test
Now you will see this error in the terminal:
Schematic input does not validate against the Schema: {"projectRoot":"","name":"test","inlineStyle":false,"inlineTemplate":false,"prefix":"app","routing":false,"style":"css","skipTests":false,"skipPackageJson":false}Errors:
Data path "" should have required property 'directory'.
Even though the --directory option was supplied.
Adding a console.log(options) to the entry function after attempting the same command will show an object with
'directory': undefined
- downgrade global @angular/cli to version 1.7.3
- ng new test --collection=test-schematic --directory=test will now work properly
The log given by the failure
Schematic input does not validate against the Schema: {"projectRoot":"","name":"test","inlineStyle":false,"inlineTemplate":false,"prefix":"app","routing":false,"style":"css","skipTests":false,"skipPackageJson":false}Errors:
Data path "" should have required property 'directory'.
Desired functionality
- all custom option values passed into the cli for a custom collection should be used and not discarded.
- Should NOT have to extend @schematics/angular for ng-new to work with custom collections.
(angular cli v1.7.3 lets you use ng-new on custom collections without having to extend the base angular schematics).
Mention any other details that might be useful
Adding unit tests and running a test run with the schematics-cli allows all unit tests to pass with the directory option passed in successfully, but angular-cli doesnt recognize directory in the custom collection.