Skip to content

Commit 97a7066

Browse files
committed
Stories
2 parents 4020f29 + 7f72c2f commit 97a7066

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
First, install [Yeoman](http://yeoman.io) and generator-react-component using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).
88

99
```bash
10-
npm install -g yo
11-
npm install -g generator-react-component
10+
npm i -g yo
11+
npm i -g @guidesmiths/generator-react-component
1212
```
1313

1414
Then generate your new project:

bin/publish.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const semver = require('semver');
2+
const { join } = require('path');
3+
const { writeFileSync } = require('fs');
4+
const pkg = require('../package.json');
5+
6+
const increment = process.argv[2];
7+
pkg.version = semver.inc(pkg.version, increment);
8+
writeFileSync(join(__dirname, '..', 'package.json'), JSON.stringify(pkg, null, 2));

generators/app/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const yosay = require('yosay');
55
const fs = require('fs');
66
const path = require('path');
77

8-
const templatesFolder = path.join(__dirname, 'templates');
9-
108
module.exports = yeoman.Base.extend({
119
prompting: function() {
1210
return this.prompt([{
@@ -16,22 +14,26 @@ module.exports = yeoman.Base.extend({
1614
default: 'ReactComponent'
1715
}]).then(function(answers) {
1816
this.props = answers;
17+
this.props.nameUp = this._capitalizeFirstLetter(this._toCamelCase(this.props.name));
1918
}.bind(this));
2019
},
2120
writing: function() {
22-
this._copyFiles('hello.txt', 'hello.js');
21+
this._copyFiles('name.component.js', this._prefix(this.props.name+'.component.js'));
22+
this._copyFiles('name.container.js', this._prefix(this.props.name+'.container.js'));
23+
this._copyFiles('name.stories.js', this._prefix(this.props.name+'.stories.js'));
24+
this._copyFiles('mock-data.json', this._prefix('mock-data.json'));
25+
this._copyFiles('name.css', this._prefix(this.props.name+'.css'));
2326
},
2427
end: function() {
2528
var outputMsg = `\n\nYour react component ${this.props.name} has been created.`;
2629
this.log(yosay(outputMsg));
2730
},
31+
_prefix: function(file) {
32+
return this.props.name + '/' + file;
33+
},
2834
_copyFiles: function(from, to) {
2935
this.props.nameUp = this._capitalizeFirstLetter(this._toCamelCase(this.props.name));
30-
this.fs.copyTpl(this.templatePath('name.component.js'), this.destinationPath(this.props.name+'.component.js'), this.props);
31-
this.fs.copyTpl(this.templatePath('name.container.js'), this.destinationPath(this.props.name+'.container.js'), this.props);
32-
this.fs.copyTpl(this.templatePath('name.stories.js'), this.destinationPath(this.props.name+'.stories.js'), this.props);
33-
this.fs.copyTpl(this.templatePath('name.css'), this.destinationPath(this.props.name+'.css'), this.props);
34-
this.fs.copyTpl(this.templatePath('mock-data.json'), this.destinationPath('mock-data.json'), this.props);
36+
this.fs.copyTpl(this.templatePath(from), this.destinationPath(to), this.props);
3537
},
3638
_toCamelCase: function(str) {
3739
return str

hello.js

-1
This file was deleted.

package.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "generator-react-component",
3-
"version": "0.0.0",
2+
"name": "@guidesmiths/generator-react-component",
3+
"version": "0.1.0",
44
"description": "A generator for a react component",
55
"homepage": "https://github.com/guidesmiths/react-component",
66
"author": {
@@ -26,7 +26,8 @@
2626
},
2727
"devDependencies": {
2828
"eslint": "^3.1.1",
29-
"eslint-config-imperative-es6": "^1.0.0"
29+
"eslint-config-imperative-es6": "^1.0.0",
30+
"semver": "^5.5.0"
3031
},
3132
"eslintConfig": {
3233
"extends": "imperative-es6",
@@ -35,6 +36,10 @@
3536
}
3637
},
3738
"repository": "GuideSmiths Ltd/generator-react-component",
38-
"scripts": {},
39+
"scripts": {
40+
"publish-patch": "node ./bin/publish patch && npm publish",
41+
"publish-minor": "node ./bin/publish minor && npm publish",
42+
"publish-major": "node ./bin/publish major && npm publish"
43+
},
3944
"license": "ISC"
40-
}
45+
}

0 commit comments

Comments
 (0)