Skip to content

Commit f5b0ae4

Browse files
author
Lucas Reppe Welander
committed
Added the --pure flag to generate a stateless component
1 parent f78fb46 commit f5b0ae4

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,33 @@ if (argv.init) {
9999
} else {
100100

101101
if (cfg.es6) {
102-
fs.readFile(path.join(__dirname, 'lib/files/component.jsx'), 'utf8', (e, contents) => {
103-
if (e) return cb(err);
102+
if (argv.pure) {
103+
fs.readFile(path.join(__dirname, 'lib/files/pure-component.jsx'), 'utf8', (e, contents) => {
104+
if (e) return cb(err);
104105

105-
contents = contents.replace(/__tpl_name__/g, argv._[0]);
106-
contents = contents.replace(/__tpl_cfg_css__/g, cfg.css);
106+
contents = contents.replace(/__tpl_name__/g, argv._[0]);
107+
contents = contents.replace(/__tpl_cfg_css__/g, cfg.css);
107108

108-
fs.appendFile(path.join(process.cwd(), cfg.path, `${argv._[0]}/${argv._[0]}.${cfg.extension}`), contents, cb);
109-
})
109+
fs.appendFile(path.join(process.cwd(), cfg.path, `${argv._[0]}/index.${cfg.extension}`), contents, cb);
110+
})
111+
} else {
112+
fs.readFile(path.join(__dirname, 'lib/files/component.jsx'), 'utf8', (e, contents) => {
113+
if (e) return cb(err);
114+
115+
contents = contents.replace(/__tpl_name__/g, argv._[0]);
116+
contents = contents.replace(/__tpl_cfg_css__/g, cfg.css);
117+
118+
fs.appendFile(path.join(process.cwd(), cfg.path, `${argv._[0]}/index.${cfg.extension}`), contents, cb);
119+
})
120+
}
110121
} else {
111122
fs.readFile(path.join(__dirname, 'lib/files/functions-component.jsx'), 'utf8', (e, contents) => {
112123
if (e) return cb(err);
113124

114125
contents = contents.replace(/__tpl_name__/g, argv._[0]);
115126
contents = contents.replace(/__tpl_cfg_css__/g, cfg.css);
116127

117-
fs.appendFile(path.join(process.cwd(), cfg.path, `${argv._[0]}/${argv._[0]}.${cfg.extension}`), contents, cb);
128+
fs.appendFile(path.join(process.cwd(), cfg.path, `${argv._[0]}/index.${cfg.extension}`), contents, cb);
118129
})
119130
}
120131
}

lib/files/pure-component.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import './__tpl_name__.__tpl_cfg_css__';
3+
4+
const __tpl_name__ = () => {
5+
return (
6+
<div>
7+
<h2>Current pure component: __tpl_name__</h2>
8+
</div>
9+
);
10+
};
11+
12+
__tpl_name__.propTypes = {};
13+
14+
export default __tpl_name__;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-modules-template",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "A small react component creator",
55
"main": "index.js",
66
"preferGlobal": "true",

0 commit comments

Comments
 (0)