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

Replace plop with hygen (http://hygen.io). #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions _templates/generator/new/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


18 changes: 18 additions & 0 deletions _templates/generator/with-prompt/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first prompt based hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


13 changes: 13 additions & 0 deletions _templates/generator/with-prompt/prompt.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/prompt.js
---

// see more examples for prompts
// https://github.com/SBoudrias/Inquirer.js/tree/master/examples
module.exports = [
{
type: 'input',
name: 'message',
message: "What's your message?"
}
]
7 changes: 7 additions & 0 deletions _templates/module/new/inject-import.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
to: src/redux/reducer.js
inject: true
after: "import .* combineReducers"
skip_if: "import <%= Name %>Reducer"
---
import <%= Name %>Reducer from '../modules/<%= name %>/<%= Name %>State';
7 changes: 7 additions & 0 deletions _templates/module/new/inject-reducer.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
to: src/redux/reducer.js
inject: true
after: "const reducers = {"
skip_if: "<%= name %>: <%= Name %>Reducer"
---
<%= name %>: <%= Name %>Reducer,
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
to: src/modules/<%= name %>/<%= Name %>State.js
---
import { Map } from 'immutable';

// Initial state
Expand All @@ -6,19 +9,21 @@ const initialState = Map({
});

// Actions
const ACTION = '{{properCase name }}State/ACTION';
const ACTION = '<%= Name %>State/ACTION';

// Action creators
export function act() {
return { type: ACTION };
}

// Reducer
export default function {{properCase name }}StateReducer(state = initialState, action = {}) {
export default function <%= Name %>StateReducer(state = initialState, action = {}) {
switch (action.type) {
case ACTION:
return state;
default:
return state;
}
}
}


Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
to: src/modules/<%= name %>/<%= Name %>View.js
---
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
StyleSheet,
View
} from 'react-native';

class {{properCase name }}View extends Component {
static displayName = '{{properCase name }}View';
class <%= Name %>View extends Component {
static displayName = '<%= Name %>View';

static propTypes = {
dispatch: PropTypes.func.isRequired,
Expand All @@ -30,4 +33,4 @@ const styles = StyleSheet.create({
}
});

export default {{properCase name }}View;
export default <%= Name %>View;
14 changes: 14 additions & 0 deletions _templates/module/new/viewcontainer.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: src/modules/<%= name %>/<%= Name %>ViewContainer.js
---
import { connect } from 'react-redux';
import <%= Name %>View from './<%= Name %>View';

export default connect(
state => ({

}),
dispatch => ({

})
)(<%= Name %>View);
26 changes: 26 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,29 @@ export default connect(
Often this file doesn't contain a lot of code, but it's important to define the Container in its own file anyway to be able to support platform-specific view implementations, as well as test the Views and their data bindings separately.

If a View needs data from other modules (i.e. other parts of the application state than the subtree managed by that module), the Container is the correct place to access. In database-speak, this way you can keep your data "normalized" (to a degree), and "join" them when required.


## Generating a module

Using `hygen` you can generate a new module easily:

```
yarn hygen -- module new --name hello
Loaded templates: _templates
inject: src/redux/reducer.js
inject: src/redux/reducer.js
added: src/modules/hello/HelloState.js
added: src/modules/hello/HelloView.js
added: src/modules/hello/HelloViewContainer.js
```

Note we're using a double dash (`--`) to instruct `yarn` to pass arguments properly. In addition, your module name should be camelCased.

If you want to make generators of your own for any boilerplate that meets your way, that's easy too:

```
yarn hygen -- generator new --name my-generator
```

For more about `hygen` [look here](http://hygen.io)

11 changes: 0 additions & 11 deletions generators/module/ModuleViewContainer.js.hbs

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-react": "^6.7.1",
"fetch-mock": "^5.5.0",
"hygen": "^1.3.4",
"istanbul": "1.0.0-alpha.2",
"jest": "^17.0.2",
"plop": "^1.7.4",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^16.0.0",
"react-native-mock": "~0.2.5",
Expand Down
49 changes: 0 additions & 49 deletions plopfile.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import {loop, combineReducers} from 'redux-loop-symbol-ponyfill';
import NavigatorStateReducer from '../modules/navigator/NavigatorState';
import CounterStateReducer from '../modules/counter/CounterState';
import SessionStateReducer, {RESET_STATE} from '../modules/session/SessionState';
// ## Generator Reducer Imports

const reducers = {
// Counter sample app state. This can be removed in a live application
counter: CounterStateReducer,
// ## Generator Reducers

// Navigator states
navigatorState: NavigatorStateReducer,
Expand Down
Loading