Skip to content

Commit aabf4d0

Browse files
committed
submodule component
1 parent d7ebd1b commit aabf4d0

5 files changed

Lines changed: 74 additions & 1 deletion

File tree

component/index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
var generators = require('yeoman-generator');
4+
var mkdirp = require('mkdirp');
5+
var yosay = require('yosay');
6+
var chalk = require('chalk');
7+
var S = require('string');
8+
9+
module.exports = generators.Base.extend({
10+
_createProjectFileSystem: function() {
11+
var sourceRoot = this.sourceRoot();
12+
var componentRoot = this.componentRoot;
13+
var componentName = S(this.componentName).capitalize().s;
14+
var templateContext = {
15+
componentName: componentName
16+
};
17+
var componentDir = componentRoot + '/' + componentName;
18+
mkdirp(componentRoot + '/' + componentName);
19+
20+
21+
this.fs.copyTpl(sourceRoot + '/_package.json', componentDir + '/package.json', templateContext);
22+
this.fs.copyTpl(sourceRoot + '/ComponentPage.js', componentDir + '/' + componentName + '.js', templateContext);
23+
this.fs.copyTpl(sourceRoot + '/ComponentPage.scss', componentDir + '/' + componentName + '.scss', templateContext);
24+
},
25+
26+
constructor: function() {
27+
generators.Base.apply(this, arguments);
28+
29+
this.argument('componentName', {
30+
required: true,
31+
type: String,
32+
desc: 'Name of the component',
33+
});
34+
35+
this.argument('componentRoot', {
36+
required: true,
37+
type: String,
38+
desc: 'Root of the component',
39+
});
40+
41+
this.log('Creating module ' + this.componentName + '.');
42+
},
43+
44+
initializing: function() {
45+
var message = chalk.bgBlack.bold('\nWelcome to React-Vertical Project\n') + chalk.underline('JS React/Flux Compiler\n');
46+
this.log(yosay(message));
47+
},
48+
49+
configuring: function() {
50+
this.config.save();
51+
},
52+
53+
writing: function() {
54+
this._createProjectFileSystem();
55+
},
56+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React, { PropTypes, Component } from 'react';
2+
import styles from './<%= componentName %>.scss';
3+
4+
export default class <%= componentName %> extends Component {
5+
static propTypes = {};
6+
7+
render() {
8+
return ();
9+
}
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.<%= componentName %> {}

component/templates/_package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "<%= componentName %>",
3+
"version": "0.0.0",
4+
"private": true,
5+
"main": "./<%= componentName %>.js"
6+
}

module/templates/ModulePage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PropTypes, Component } from 'react';
22
import { bindActionCreators } from 'redux';
33
import { connect } from 'react-redux';
44
import styles from './<%= modulePage %>.scss';
5-
import * as <%= moduleCommonName %> from '../../actions/<%= moduleActions %>';
5+
import * as <%= moduleActions %> from '../../actions/<%= moduleActions %>';
66

77
class <%= modulePage %> extends Component {
88
static propTypes = {

0 commit comments

Comments
 (0)