Skip to content
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

Merged
merged 1 commit into from
Aug 7, 2018
Merged

feat(cli): add @ngxs/cli for generate store #520

merged 1 commit into from
Aug 7, 2018

Conversation

kyusupov33
Copy link
Contributor

@kyusupov33 kyusupov33 commented Jul 24, 2018

closes #497

PR Checklist
Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes

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?

[ ] Yes
[x] No

Other information

If you want to verify that its work you need to:

  1. checkout current branch, then
$ cd packages/cli
$ npm install
$ npm bin -g ngxs
$ npm link
  1. You can try to use ngxs command in any directory and create store.

Contributors:

@kyusupov33
@splincode

Copy link
Member

@markwhitfeld markwhitfeld left a 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 markwhitfeld requested a review from amcdnl July 24, 2018 16:16
@kyusupov33
Copy link
Contributor Author

@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)
https://github.com/amwmedia/plop

@markwhitfeld
Copy link
Member

@splincode Yes, please do.
Could you add the demo gif to the repo and use that one from the readme and docs (as opposed to the external link)?
Also, do you think that the command should be just 'ngxs' or should it be 'ngxs generate state' (similar to the angular cli)? it would allow for other usages of the ngxs cli.... maybe generate state is a reasonable default for no params...

@amcdnl Are you on board with the creation of a cli?

? Write store name, please...
```

![](https://habrastorage.org/webt/g5/td/dz/g5tddzflkkwftfvpvim3ckwveau.gif)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@amcdnl
Copy link
Member

amcdnl commented Jul 25, 2018

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!

Copy link
Member

@amcdnl amcdnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few nits.

? Write store name, please...
```

![](https://habrastorage.org/webt/g5/td/dz/g5tddzflkkwftfvpvim3ckwveau.gif)
Copy link
Member

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.

{
type: 'input',
name: 'name',
message: 'Write store name, please...'
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
type: 'directory',
name: 'directory',
message: 'Choose a directory..',
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
type: 'list',
name: 'storeType',
choices: ['Empty Store', 'Filled Store'],
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amcdnl remove it

@amcdnl
Copy link
Member

amcdnl commented Jul 25, 2018

Ya, I agree tests would be nice too!

@kyusupov33
Copy link
Contributor Author

About command names ... you're right. In the next commit, we'll fix it.

@markwhitfeld markwhitfeld mentioned this pull request Jul 29, 2018
3 tasks
@markwhitfeld
Copy link
Member

Wow! Nicely done!

Copy link
Member

@markwhitfeld markwhitfeld left a 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 ;-)

![CLI Screenshot](../assets/cli.gif)

## Install
The Devtools plugin can be installed using NPM:
Copy link
Member

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 ..."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,2 @@
# @ngxs/cli
Logger plugin for NGXS. See [repo](https://github.com/ngxs/store) for more info.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "NGXS CLI" ...

})
export class {{pascalCase name}}State {
@Action({{pascalCase name}}Action)
add(ctx: StateContext<{{pascalCase name}}StateModel>, action) {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

addItem() {
this.store.dispatch(new {{pascalCase name}}Action('item-1'));
}
}
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@markwhitfeld markwhitfeld left a 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

Copy link
Member

@markwhitfeld markwhitfeld left a 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.

import * as path from 'path';
import * as rimraf from 'rimraf';
import * as nodePlop from 'node-plop';
import { expect } from 'chai';
Copy link
Member

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?

Copy link
Member

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

angular/angular-cli#8357

node-plop usage child_process

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@markwhitfeld markwhitfeld left a 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.

--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
Copy link
Member

@markwhitfeld markwhitfeld Aug 3, 2018

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

Copy link
Member

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 ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

).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);
Copy link
Member

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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@markwhitfeld
Copy link
Member

PS. Thanks for all the work you are putting into this @splincode & @kyusupov33!

@splincode
Copy link
Member

image

@splincode
Copy link
Member

@markwhitfeld @amcdnl I refactored the code, corrected the tests, corrected the documentation (screenshot)

cli

$ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small spelling mistake ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

@markwhitfeld
Copy link
Member

@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?
Also, do we want to keep the version numbers matching?

@kyusupov33
Copy link
Contributor Author

kyusupov33 commented Aug 3, 2018

@markwhitfeld and @amcdnl
Thanks for the reviews, we tried to make cli as efficient as possible for use

@splincode
Copy link
Member

@amcdnl
I wanted to demonstrate how CLI works
I rewritten everything into to typescript:
https://github.com/Angular-RU/ngxs-cli

$ npm i ngxs-cli -g
$ ngxs

Can you create a separate repository and we will move the changes there?
So that we could transfer everything there
https://github.com/ngxs/cli

@amcdnl amcdnl merged commit 9dd8720 into ngxs:master Aug 7, 2018
@amcdnl
Copy link
Member

amcdnl commented Aug 7, 2018

Merged! I might move this into its own repo since its not really tied to any core pieces.

@splincode
Copy link
Member

@amcdnl The problem is that they hurried to publish the project

Not found 404
https://www.npmjs.com/package/@ngxs/cli

Could you add me to the community, and give me the right to write?
https://github.com/ngxs/cli

Because the working project needs to be moved from here:
https://github.com/Angular-RU/ngxs-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add command for generate store with CLI
4 participants