-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(schematics): Add ng-add support with prompt for making our schem… #1552
feat(schematics): Add ng-add support with prompt for making our schem… #1552
Conversation
Preview docs changes for 6929ff4 at https://previews.ngrx.io/pr1552-6929ff4/ |
@brandonroberts I hope that's what you had in mind :) |
@itayod thanks for working on this! What I had in mind is that this would be adding an |
With pleasure! So just to make things clear, you want me to add |
Yes and yes |
6929ff4
to
20576a5
Compare
Preview docs changes for 20576a5 at https://previews.ngrx.io/pr1552-20576a5/ |
20576a5
to
0f98d7e
Compare
Preview docs changes for 0f98d7e at https://previews.ngrx.io/pr1552-0f98d7e/ |
0f98d7e
to
0c52347
Compare
Preview docs changes for 0c52347 at https://previews.ngrx.io/pr1552-0c52347/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for another PR 🎉
To make this package available we also have to add a BUILD file, you could use the effect package for an example.
After this we have to append the package to our existing schematics BUILD:
packages = [
"//modules/schematics/migrations:npm_package",
"//modules/schematics/schematics:npm_package", // this line is added
"//modules/schematics/schematics-core:npm_package",
],
modules/schematics/collection.json
Outdated
"aliases": ["init"], | ||
"factory": "./src/ng-add", | ||
"schema": "./src/ng-add/schema.json", | ||
"description": "Adds initial setup for Ngrx" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using the following description here?
"Installs the NgRx schematics package"
host.overwrite(path, JSON.stringify(workSpace, null, 2)); | ||
} | ||
|
||
export function updateWorkspace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used within the @ngrx/schematics package.
Wouldn't it be better to define these functions within the package itself?
@@ -0,0 +1,16 @@ | |||
{ | |||
"$schema": "http://json-schema.org/schema", | |||
"id": "SchematicsNgRxRoot", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a bit weird, but the other packages are using the following convention:
"id": "SchematicsNgRxRoot", | |
"id": "SchematicsNgRxSchematics", |
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"id": "SchematicsNgRxRoot", | ||
"title": "NgRx Root Schema", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"title": "NgRx Root Schema", | |
"title": "Scaffolding library for Angular applications using NgRx libraries", |
"setSchematicsDefault": { | ||
"type": "boolean", | ||
"default": true, | ||
"description": "Make @ngrx/schematics as the default schematics", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"description": "Make @ngrx/schematics as the default schematics", | |
"description": "Use @ngrx/schematics as the default collection", |
"title": "NgRx Root Schema", | ||
"type": "object", | ||
"properties": { | ||
"setSchematicsDefault": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using just default
or defaultCollection
here?
@@ -0,0 +1,3 @@ | |||
export interface Schema { | |||
setSchematicsDefault?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
"default": true, | ||
"description": "Make @ngrx/schematics as the default schematics", | ||
"x-prompt": | ||
"Would you like to make @ngrx/schematics as the project's default?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Would you like to make @ngrx/schematics as the project's default?" | |
"Would you want to use @ngrx/schematics as the default collection?" |
"title": "NgRx Root Schema", | ||
"type": "object", | ||
"properties": { | ||
"setSchematicsDefault": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding an alias?
"aliases": ["d"]
In order to not forget about it, we should also install the @ngrx/schematics package. |
That's what I thought 😄 |
We don't need to explicitly install the |
Gtn 😄 , I also was thinking about update the schematics settings in the
So all of the user's configuration for |
You don't need to replace those. It will use NgRx schematics by default if the collection is set. We may do something with the defaults later, but that varies on the developer's project. |
noop, | ||
} from '@angular-devkit/schematics'; | ||
import { updateWorkspace } from '../../schematics-core/utility/config'; | ||
import { Schema as RootStoreOptions } from './schema'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { Schema as RootStoreOptions } from './schema'; | |
import { Schema as SchematicOptions } from './schema'; |
} from '@angular-devkit/schematics/testing'; | ||
import * as path from 'path'; | ||
import { createWorkspace } from '../../../schematics-core/testing'; | ||
import { Schema as RootStoreOptions } from './schema'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { Schema as RootStoreOptions } from './schema'; | |
import { Schema as SchematicOptions } from './schema'; |
0c52347
to
4cc081b
Compare
Preview docs changes for 4cc081b at https://previews.ngrx.io/pr1552-4cc081b/ |
Preview docs changes for e2d1f20 at https://previews.ngrx.io/pr1552-e2d1f20/ |
Thanks again @itayod 👏 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Closes #1538
What is the new behavior?
Running
ng-add
will prompt the user to set@ngrx/schematics
as the default collection.Does this PR introduce a breaking change?