-
Notifications
You must be signed in to change notification settings - Fork 403
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(cli): add @ngxs/cli for generate store #520
Conversation
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.
Looks good to me...
Angular schematics would be first prize but this offers a great experience. We'll done!
@kyusupov33 Is it possible to have any tests for this?
@markwhitfeld We don't create tests for current generator, because usage plop (micro-generator framework that makes it easy to create files with a level of uniformity) |
@splincode Yes, please do. @amcdnl Are you on board with the creation of a cli? |
packages/cli/README.md
Outdated
? Write store name, please... | ||
``` | ||
|
||
![](https://habrastorage.org/webt/g5/td/dz/g5tddzflkkwftfvpvim3ckwveau.gif) |
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.
Should rather move the gif locally and use that one as opposed to the external link.
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.
Agreed. Just add it to the repo.
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.
done
First off, THIS IS AMAZING! I was thinking about adding schematics but its kinda limited in what you can do. Ever since I noticed the Akita(?) CLI i was thinking about adding this to NGXS. I'll be reviewing this and try to cut a release this week! |
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.
Few nits.
packages/cli/README.md
Outdated
? Write store name, please... | ||
``` | ||
|
||
![](https://habrastorage.org/webt/g5/td/dz/g5tddzflkkwftfvpvim3ckwveau.gif) |
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.
Agreed. Just add it to the repo.
packages/cli/plopfile.js
Outdated
{ | ||
type: 'input', | ||
name: 'name', | ||
message: 'Write store name, please...' |
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.
How about just Store name:
the ...
makes me think I'm waiting on something.
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.
done
packages/cli/plopfile.js
Outdated
{ | ||
type: 'directory', | ||
name: 'directory', | ||
message: 'Choose a directory..', |
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.
How about just Directory:
. Again the ...
makes me think I'm waiting on something. Also would be good to say (Default CWD)
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.
done
packages/cli/plopfile.js
Outdated
{ | ||
type: 'list', | ||
name: 'storeType', | ||
choices: ['Empty Store', 'Filled Store'], |
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.
At first I was confused what empty vs filled is. Would be nice to help clarify that.
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 means that the user will have a choice:
- empty store (skeleton)
- A story filled with some data to learn how it works, for example
In the future, we can add a mini template for authorization, for example, both on the site. This will help a person who just starts using ngxs to look at it right away in the work, rather than studying the documentation. Perhaps it will be useful.
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.
@amcdnl if you want we can delete filled templates and leave only empty. In the future we want to add example templates like: todos, auth, etc.
It will be look like this:
$ ngxs
# Whitch store do you need?
1. Empty
2. Examples
If user choose 'Empty' store, then
# Store name: app
# Directory: src
If user choose 'Examples' store, then
# Select example:
1. Generate todos store
2. Generate auth store
# Directory: src
Examples store will help people to explore how ngxs is working.
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.
@amcdnl remove it
Ya, I agree tests would be nice too! |
About command names ... you're right. In the next commit, we'll fix it. |
Wow! Nicely done! |
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.
A few tweaks and one template rework ;-)
docs/plugins/cli.md
Outdated
![CLI Screenshot](../assets/cli.gif) | ||
|
||
## Install | ||
The Devtools plugin can be installed using NPM: |
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.
Should be "The CLI can be installed ..."
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.
done
packages/cli/README.md
Outdated
@@ -0,0 +1,2 @@ | |||
# @ngxs/cli | |||
Logger plugin for NGXS. See [repo](https://github.com/ngxs/store) for more info. |
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.
Should be "NGXS CLI" ...
packages/cli/src/templates/state.tpl
Outdated
}) | ||
export class {{pascalCase name}}State { | ||
@Action({{pascalCase name}}Action) | ||
add(ctx: StateContext<{{pascalCase name}}StateModel>, action) { |
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.
Add type for action:
action: {{pascalCase name}}Action
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.
done
packages/cli/src/templates/spec.tpl
Outdated
addItem() { | ||
this.store.dispatch(new {{pascalCase name}}Action('item-1')); | ||
} | ||
} |
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.
I think that it would be better to test the state class through the store directly and not via a component because component tests are quite expensive and are actually adding no real value here other than as a container for the store.
This spec file should be an example of how we recommend testing the state. Look here for inspiration:
https://ngxs.gitbook.io/ngxs/recipes/unit-testing
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.
done
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.
Amazing work. Just a few build pipeline issues to fix
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.
Use jasmine instead of Mocha and for your tests if possible.
packages/cli/tests/test.ts
Outdated
import * as path from 'path'; | ||
import * as rimraf from 'rimraf'; | ||
import * as nodePlop from 'node-plop'; | ||
import { expect } from 'chai'; |
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.
If possible, please could you use jasmine as opposed to chai and mocha for these tests?
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.
because Karma (Jasmine) does not work with node environment, we usage ts-mocha for testing CLI
node-plop usage child_process
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.
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.
Small tweak regarding command line param casing.
docs/plugins/cli.md
Outdated
--folderName name Use your own folder name, default: state --spec boolean Creates a spec file for store, default: true | ||
--name name Store name | ||
--directory path By default, the prompt is set to the current directory | ||
--folderName name Use your own folder name, default: state |
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.
@splincode @kyusupov33
Shouldn't the --folderName
(camel case) argument rather be --folder-name
(snake case I think it is called)?
I think that makes it have better support and less ambiguity across operating systems... or at least follows the broader convention.
The ng
cli has the following syntax for example (from our package.json):
ng test --watch=false --code-coverage --progress=false --project ngxs
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.
PS. Will have to update the cli demo gif to match the renamed param too ;-)
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.
done
packages/cli/tests/test.ts
Outdated
).to.equal(actionsOutput); | ||
const actionAppSnapshot = fs.readFileSync(path.resolve(expectedFiles.actions)).toString(); | ||
const actionsAppOutputCli = fs.readFileSync(path.resolve(generatedFiles.actions)).toString(); | ||
expect(actionAppSnapshot).to.equal(actionsAppOutputCli); |
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.
I like this, makes the tests much cleaner!
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.
done
PS. Thanks for all the work you are putting into this @splincode & @kyusupov33! |
@markwhitfeld @amcdnl I refactored the code, corrected the tests, corrected the documentation (screenshot) |
docs/plugins/cli.md
Outdated
$ ngxs --help | ||
|
||
Options | ||
|
||
--name name Store name | ||
--directory path By default, the prompt is set to the current directory | ||
--folderName name Use your own folder name, default: state | ||
--folde-name name Use your own folder name, default: state |
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.
Small spelling mistake ;-)
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.
done :)
@amcdnl This looks like it is good to go in my books. I'm not familiar with the release procedure. Will this go out automatically when it is merged? |
@markwhitfeld and @amcdnl |
@amcdnl
Can you create a separate repository and we will move the changes there? |
Merged! I might move this into its own repo since its not really tied to any core pieces. |
@amcdnl The problem is that they hurried to publish the project Not found 404 Could you add me to the community, and give me the right to write? Because the working project needs to be moved from here: |
closes #497
PR Checklist
Please check if your PR fulfills the following requirements:
https://ngxs.gitbook.io/ngxs/recipes/style-guide
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #497
What is the new behavior?
Now when you install @ngxs/cli it can helps to generate store structure on filled or empty format.
To do this, use the commands presented on the gif.
Does this PR introduce a breaking change?
Other information
If you want to verify that its work you need to:
Contributors:
@kyusupov33
@splincode