super-react
Advanced tools
Comparing version 0.1.3 to 0.2.0
31
index.js
@@ -25,2 +25,7 @@ #!/usr/bin/env node | ||
var settings = { | ||
"template_type": "es5", | ||
"extension": "js" | ||
}; | ||
/** | ||
@@ -41,4 +46,14 @@ * ErrorHandler For Promise Rejects | ||
var rendered; | ||
//Don't need js extension in import or require statements in template | ||
function extHelper(ext) { | ||
if (ext === "js") { | ||
return ""; | ||
} else { | ||
return ext; | ||
} | ||
} | ||
//Open template | ||
fs.readFileAsync(path.join(__dirname, 'templates/', 'ReactClass.js')) | ||
fs.readFileAsync(path.join(__dirname, 'templates/', 'ReactClass.' + settings["template_type"] + '.js')) | ||
.then(function (contents){ | ||
@@ -48,3 +63,3 @@ var compiled = _.template(contents); | ||
//Compile lodash template for React class | ||
rendered = compiled({name: name, children: children}); | ||
rendered = compiled({name: name, children: children, ext: extHelper(settings["extension"])}); | ||
@@ -59,3 +74,3 @@ //Create the output folder and if exists silently catch error | ||
//Write the component to file if it doesnt already exist | ||
return fs.writeFileAsync(path.join(output_folder, name + ".js"), rendered, {flag: 'wx'}); | ||
return fs.writeFileAsync(path.join(output_folder, name + "." + settings["extension"]), rendered, {flag: 'wx'}); | ||
}) | ||
@@ -154,4 +169,14 @@ .caught(errorHandler); | ||
if (key === '_') { | ||
if (_.contains(args[key], "es6")) { | ||
/* Global Settings Object */ | ||
settings['template_type'] = "es6"; | ||
} | ||
scaffoldByArgs(_.first(args[key])); | ||
} | ||
if (key === 'ext') { | ||
/* Global Settings Object */ | ||
settings['extension'] = args[key]; | ||
} | ||
if (key === 'file') { | ||
@@ -158,0 +183,0 @@ var filename = args[key]; |
{ | ||
"name": "super-react", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "Opinionated Command Line Tool for Scaffolding out Nested React Components Into Files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,3 +14,3 @@ #Super React | ||
``` | ||
super-react "[emmet_string]" [--file=<components_scaffold>.json] [--output=<path>] | ||
super-react "[emmet_string]" [--file=<components_scaffold>.json] [--output=<path>] [--es6] [--ext=<custom_extension>] | ||
``` | ||
@@ -71,6 +71,32 @@ | ||
``` | ||
super-react "App>Description+ListContainer>List" --output=./my_components | ||
super-react "App>Description+ListContainer>List" --output=./my_components --ext=jsx --es6 | ||
``` | ||
Creates components in ```./my_components``` | ||
Creates components in ```./my_components``` with files with the extension jsx (i.e. ```App.jsx```) and a class with ES6 style JS in the following: | ||
``` | ||
import React from 'react'; | ||
import Description from './Description.jsx' | ||
import ListContainer from './ListContainer.jsx' | ||
let App = React.createClass({ | ||
mixins : [], | ||
propTypes: { | ||
}, | ||
render() { | ||
var styles = {}; | ||
return ( | ||
<div> | ||
<Description /> | ||
<ListContainer /> | ||
</div> | ||
); | ||
} | ||
}); | ||
export default App; | ||
``` | ||
##Scaffold Components From JSON File | ||
@@ -110,2 +136,8 @@ | ||
##Changelog | ||
* v0.2.0 Added --es6 and --ext flags | ||
##Roadmap | ||
* v0.3.0 Add folder/directory scaffolding syntax in addition to React files | ||
##Contribute? | ||
@@ -112,0 +144,0 @@ |
8545
7
209
146