mirror of
https://github.com/react-webpack-generators/generator-react-webpack.git
synced 2025-12-08 18:01:59 +00:00
Merge pull request #92 from yonatanmn/master
alias for generators, rich option
This commit is contained in:
commit
486aea76b8
50
README.md
50
README.md
@ -54,7 +54,7 @@ Generates a [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) compon
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
```bash
|
```bash
|
||||||
yo react-webpack:component foo
|
yo react-webpack:component foo //or just: yo react-webpack:c foo
|
||||||
```
|
```
|
||||||
|
|
||||||
Produces `src/components/Foo.js` (*javascript - JSX*):
|
Produces `src/components/Foo.js` (*javascript - JSX*):
|
||||||
@ -103,13 +103,52 @@ And `src/styles/Foo.css` (or .sass, .less etc...) :
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### rich flag
|
||||||
|
|
||||||
|
For all you lazy programmers out there, we've added another shortcut - `rich` flag:
|
||||||
|
```bash
|
||||||
|
yo react-webpack:c foofoo --rich
|
||||||
|
```
|
||||||
|
This will give you all of react component's most common stuff :
|
||||||
|
````
|
||||||
|
var React = require('react/addons');
|
||||||
|
|
||||||
|
require('styles/Foofoo.sass');
|
||||||
|
|
||||||
|
var Foofoo = React.createClass({
|
||||||
|
mixins: [],
|
||||||
|
getInitialState: function() { return({}) },
|
||||||
|
getDefaultProps: function() {},
|
||||||
|
componentWillMount: function() {},
|
||||||
|
componentDidMount: function() {},
|
||||||
|
shouldComponentUpdate: function() {},
|
||||||
|
componentDidUpdate: function() {},
|
||||||
|
componentWillUnmount: function() {},
|
||||||
|
|
||||||
|
render: function () {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>Content for Foofoo</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Foofoo;
|
||||||
|
````
|
||||||
|
|
||||||
|
Just remove those you don't need, then fill and space out the rest.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Action
|
### Action
|
||||||
|
|
||||||
When using Flux or Reflux architecture, it generates an actionCreator in `src/actions` and it's corresponding test in `src/spec/actions`.
|
When using Flux or Reflux architecture, it generates an actionCreator in `src/actions` and it's corresponding test in `src/spec/actions`.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```bash
|
```bash
|
||||||
yo react-webpack:action bar
|
yo react-webpack:action bar //or just: yo react-webpack:a bar
|
||||||
```
|
```
|
||||||
Will create a file - `src/actions/BarActionCreators.js`
|
Will create a file - `src/actions/BarActionCreators.js`
|
||||||
|
|
||||||
@ -160,7 +199,7 @@ When using Flux or Reflux architecture, it generates a store in `src/stores` and
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
```bash
|
```bash
|
||||||
yo react-webpack:store baz
|
yo react-webpack:store baz //or just: yo react-webpack:s baz
|
||||||
```
|
```
|
||||||
Will create a file - `src/stores/BazStore.js`
|
Will create a file - `src/stores/BazStore.js`
|
||||||
|
|
||||||
@ -238,6 +277,11 @@ Sets the style file's template and extension
|
|||||||
|
|
||||||
[flux](https://facebook.github.io/flux/) or [reflux](https://github.com/spoike/refluxjs)
|
[flux](https://facebook.github.io/flux/) or [reflux](https://github.com/spoike/refluxjs)
|
||||||
|
|
||||||
|
### es6
|
||||||
|
|
||||||
|
If you are using `es6`, and want to use its export functionality (and not webpack's), just add `--es6` flag when you create a component, action or srore.
|
||||||
|
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
Running `grunt test` will run the unit tests with karma. Tests are written using [Jasmine](http://jasmine.github.io/) by default.
|
Running `grunt test` will run the unit tests with karma. Tests are written using [Jasmine](http://jasmine.github.io/) by default.
|
||||||
|
|||||||
1
a/index.js
Normal file
1
a/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('../action');
|
||||||
@ -3,8 +3,11 @@ var util = require('util');
|
|||||||
var ScriptBase = require('../script-base.js');
|
var ScriptBase = require('../script-base.js');
|
||||||
|
|
||||||
var ActionGenerator = module.exports = function ActionGenerator(args, options, config) {
|
var ActionGenerator = module.exports = function ActionGenerator(args, options, config) {
|
||||||
args[0] += 'ActionCreators';
|
if (!args[0]) console.log('\n Please specify a name for this action creator \n');
|
||||||
ScriptBase.apply(this, arguments);
|
else {
|
||||||
|
args[0] += 'ActionCreators';
|
||||||
|
ScriptBase.apply(this, arguments)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(ActionGenerator, ScriptBase);
|
util.inherits(ActionGenerator, ScriptBase);
|
||||||
|
|||||||
1
c/index.js
Normal file
1
c/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('../component');
|
||||||
@ -10,8 +10,10 @@ util.inherits(ComponentGenerator, ScriptBase);
|
|||||||
|
|
||||||
ComponentGenerator.prototype.createComponentFile = function createComponentFile() {
|
ComponentGenerator.prototype.createComponentFile = function createComponentFile() {
|
||||||
this.option('es6');
|
this.option('es6');
|
||||||
|
this.option('rich');
|
||||||
|
|
||||||
this.es6 = this.options.es6;
|
this.es6 = this.options.es6;
|
||||||
|
this.rich = this.options.rich;
|
||||||
|
|
||||||
this.generateComponentTestAndStyle(
|
this.generateComponentTestAndStyle(
|
||||||
'Component',
|
'Component',
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "generator-react-webpack",
|
"name": "generator-react-webpack",
|
||||||
"version": "1.2.2",
|
"version": "1.2.2",
|
||||||
"description": "Yeoman generator for ReactJS and Webpack",
|
"description": "Yeoman generator for Facebook's ReactJS, with webpack, livereload, grunt, Flux/Reflux architecture options and support for sass, less or stylus ",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"yeoman-generator",
|
"yeoman-generator",
|
||||||
"reactjs",
|
"reactjs",
|
||||||
|
|||||||
1
s/index.js
Normal file
1
s/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('../store');
|
||||||
@ -82,7 +82,6 @@ Generator.prototype.testTemplate = function (src, dest) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Generator.prototype.stylesTemplate = function (src, dest) {
|
Generator.prototype.stylesTemplate = function (src, dest) {
|
||||||
console.log(src);
|
|
||||||
yeoman.generators.Base.prototype.template.apply(this, [
|
yeoman.generators.Base.prototype.template.apply(this, [
|
||||||
src + this.stylesSuffix,
|
src + this.stylesSuffix,
|
||||||
path.join(this.options.stylesPath, dest) + this.stylesSuffix
|
path.join(this.options.stylesPath, dest) + this.stylesSuffix
|
||||||
|
|||||||
@ -3,9 +3,12 @@ var util = require('util');
|
|||||||
var ScriptBase = require('../script-base.js');
|
var ScriptBase = require('../script-base.js');
|
||||||
|
|
||||||
var StoreGenerator = module.exports = function StoreGenerator(args, options, config) {
|
var StoreGenerator = module.exports = function StoreGenerator(args, options, config) {
|
||||||
args[0] += 'Store';
|
if (!args[0]) console.log('\n Please specify a name for this store \n');
|
||||||
ScriptBase.apply(this, arguments);
|
else {
|
||||||
}
|
args[0] += 'Store';
|
||||||
|
ScriptBase.apply(this, arguments)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
util.inherits(StoreGenerator, ScriptBase);
|
util.inherits(StoreGenerator, ScriptBase);
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,10 @@
|
|||||||
<div id="content">
|
<div id="content">
|
||||||
<h1>If you can see this, something is broken (or JS is not enabled)!!.</h1>
|
<h1>If you can see this, something is broken (or JS is not enabled)!!.</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
__REACT_DEVTOOLS_GLOBAL_HOOK__ = parent.__REACT_DEVTOOLS_GLOBAL_HOOK__
|
||||||
|
</script>
|
||||||
<script type="text/javascript" src="assets/main.js"></script>
|
<script type="text/javascript" src="assets/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var React = require('react/addons');
|
var React = require('react/addons');<% if(rich && architecture === 'reflux'){%>
|
||||||
|
var Reflux = require('Reflux'); <%}%>
|
||||||
|
<% if(rich && architecture === 'flux' || architecture === 'reflux'){%>
|
||||||
|
//var Actions = require('actions/xxx')<%}%>
|
||||||
|
|
||||||
<% if (stylesLanguage === 'css') { %>require('styles/<%= classedFileName %>.css');<% } %><%
|
<% if (stylesLanguage === 'css') { %>require('styles/<%= classedFileName %>.css');<% } %><%
|
||||||
if (stylesLanguage === 'sass') { %>require('styles/<%= classedFileName %>.sass');<% } %><%
|
if (stylesLanguage === 'sass') { %>require('styles/<%= classedFileName %>.sass');<% } %><%
|
||||||
@ -8,7 +11,16 @@ if (stylesLanguage === 'scss') { %>require('styles/<%= classedFileName %>.scss
|
|||||||
if (stylesLanguage === 'less') { %>require('styles/<%= classedFileName %>.less');<% } %><%
|
if (stylesLanguage === 'less') { %>require('styles/<%= classedFileName %>.less');<% } %><%
|
||||||
if (stylesLanguage === 'stylus') { %>require('styles/<%= classedFileName %>.styl');<% } %>
|
if (stylesLanguage === 'stylus') { %>require('styles/<%= classedFileName %>.styl');<% } %>
|
||||||
|
|
||||||
var <%= classedName %> = React.createClass({
|
var <%= classedName %> = React.createClass({<% if(rich){%>
|
||||||
|
mixins: [<% if(architecture === 'reflux'){%>Reflux.ListenerMixin<%}%>],
|
||||||
|
getInitialState: function() { return({}) },
|
||||||
|
getDefaultProps: function() {},
|
||||||
|
componentWillMount: function() {},
|
||||||
|
componentDidMount: function() {},
|
||||||
|
shouldComponentUpdate: function() {},
|
||||||
|
componentDidUpdate: function() {},
|
||||||
|
componentWillUnmount: function() {},<%}%>
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user