1- # simple-scaffolder
2- Scaffolder allows you to create your structured files based on templates.
1+ # simple-scaffold
2+ Simple Scaffold allows you to create your structured files based on templates.
33
44## Install
55You can either use it as a command line tool or import into your own code and run from there.
66
7- You can install simple-scaffold globally like so:
8-
97``` bash
108# npm
11- npm install -g simple-scaffold
9+ npm install [-g] simple-scaffold
1210# yarn
13- yarn global add simple-scaffold
11+ yarn [ global] add simple-scaffold
1412```
1513
1614## Use as a command line tool
17- ### Command line options
15+ The first non-token argument (that has no ` -- ` prefix) will be used as the scaffold name.
16+ The rest is ignored, of course except for the available arguments below.
1817
1918``` bash
2019simple-scaffold MyComponent --template scaffolds/component/** /* \
2120 --output src/components \
2221 --locals myProp=" propname" ,myVal=123
2322```
2423
25- ##### ` --template glob [--template glob2 [...]] `
26- A glob pattern of template files to load.
24+ You can add this as a script in your ` package.json ` :
25+
26+ ``` json
27+ {
28+ "scripts" : {
29+ "scaffold" : " node node_modules/simple-scaffold/dist/cmd.js --template scaffolds/component/**/* --output src/components --locals myProp=\" propname\" ,myVal=123"
30+ }
31+ }
32+ ```
33+
34+ ## Scaffolding
35+ Scaffolding will replace {{vars}} in both the file name and its contents and put the transformed files
36+ in ` <output>/<{{Name}} ` .
37+
38+ Your context will be pre-populated with the following:
39+ - ` {{Name}} ` : CapitalizedName of the component
40+ - ` {{name}} ` : camelCasedName of the component
41+
42+ Any ` locals ` you add in the config will populate with their names wrapped in ` {{ ` and ` }} ` .
43+ They are all stringified, so be sure to parse them accordingly by creating a script, if necessary.
2744
45+ ### Command line options
46+ ##### ` --template glob [--template glob2 [...]] ` (required)
47+ A glob pattern of template files to load.
2848
2949A template file may be of any type and extension, and supports [ Handlebars] ( https://handlebarsjs.com ) as a parsing engine for the file names and contents, so you may customize both with variables from your configuration.
3050
31- You may load more than one template list by simple adding more ` --template ` arguments.
51+ You can load more than one template list by simple adding more ` --template ` arguments.
3252
33- ##### ` --output path `
53+ ##### ` --output path ` (optional)
3454The output directory to put the new files in. They will attempt to maintain their regular structure as they are found, if possible.
3555
3656Your new scaffold will be placed under a directory with the scaffold name from the argumemts.
3757
3858You may also pass a function to transform the output path for each file individually.
3959This function takes 2 arguments: filename, and base glob path
4060
41- ##### ` --locals key=value[,key=value[,...]] `
61+ ##### ` --locals key=value[,key=value[,...]] ` (optional)
4262Pass a KV map to the template for parsing.
4363
4464### Use in Node.js
45- You can also build the scaffold yourself.
65+ You can also build the scaffold yourself, if you want to create more complex arguments or scaffold groups .
4666Simply pass a config object to the constructor, and invoke ` run() ` when you are ready to start.
47- The config takes the same arguments as the command line:
67+ The config takes similar arguments to the command line:
4868
4969``` javascript
5070const SimpleScaffold = require (' simple-scaffold' ).default
@@ -60,32 +80,26 @@ const scaffold = new SimpleScaffold({
6080```
6181
6282## Example Scaffold Input
63- Scaffolding will replace interpolations in both the file name and contents.
64-
65- Your context will be pre-populated with
66- - ` {{Name}} ` : CapitalizedName of the component
67- - ` {{name}} ` : camelCasedName of the component
68-
69- Any ` locals ` you add in the config will populate with their names wrapped in ` {{ ` and ` }} ` .
7083
7184### Input Directory structure
7285```
7386- project
7487 - scaffold
88+ - {{Name}}.js
7589 - {{Name}}.css
7690 - src
7791 - components
7892 - ...
7993```
8094
81- #### project/scaffold/{{Name}}.css
82- ``` css
83- .{{className }} {
84- border : 1px solid black ;
85- }
95+ #### project/scaffold/{{Name}}.js
96+ ``` js
97+ const React = require (' react' )
8698
87- .{{className }}-child {
88- background : red ;
99+ module .exports = class {{Name}} extends React .Component {
100+ render () {
101+ < div className= " {{className}}" > {{Name}} Component< / div>
102+ }
89103}
90104```
91105
@@ -108,13 +122,13 @@ simple-scaffold MyComponent \
108122 - ...
109123```
110124
111- #### project/src/components/MyComponent/MyComponent.css
112- ```css
113- .my-component {
114- border: 1px solid black;
115- }
125+ #### project/scaffold/MyComponent/MyComponent.js
126+ ```js
127+ const React = require(' react' )
116128
117- .my-component-child {
118- background: red;
129+ module.exports = class MyComponent extends React.Component {
130+ render() {
131+ <div className="my-component">MyComponent Component</div>
132+ }
119133}
120134```
0 commit comments