Skip to content
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ This creates a skeleton `mycomponent.jsx` file inside your `src/components` dire

By default, the resulting file includes React lifecycle methods, like `componentWillMount`. You can skip these by passing in either `-l` or `--skip-lifecycle` to the command above. To know more run `$ react generate -h`.

#### Component file extension

By default, the resulting file will be of `.jsx` extension. You can specify `.js` by passing in either `-j` or `--js` to the command above.

#### Property Types

Currently supported property types:
Expand Down
4 changes: 3 additions & 1 deletion bin/react
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ program
program
.command("generate <name> [propName:PropType...]")
.option("-l, --skip-lifecycle", "Skip lifecycle method generation")
.option("-j, --js", "Generate JS file")
.description("Generate a new react component.")
.action(function(name, propDefs) {
var props = [];
Expand Down Expand Up @@ -64,13 +65,14 @@ program
});
});
var lifecycle = !this.skipLifecycle;
var extension = !this.js ? '.jsx' : '.js';
fs.readFile(path.join(__dirname, "../templates", "component.ejs"), 'utf8', function (err, data) {
var component = ejs.render(data, {
lifecycle: lifecycle,
name: name,
props: props
});
fs.writeFile(path.join(process.cwd(), "src/components", name.toLowerCase()+".jsx"), component);
fs.writeFile(path.join(process.cwd(), "src/components", name.toLowerCase()+extension), component);
});
});

Expand Down