Skip to content

Commit 4519fdb

Browse files
authored
Merge pull request #44 from codeBelt/command-line-3.0
Improve Command Line and add validation. v3.0
2 parents 656f31c + 508bdda commit 4519fdb

25 files changed

+1924
-1724
lines changed

.prettierrc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2-
"printWidth": 150,
3-
"singleQuote": true,
4-
"trailingComma": "es5",
52
"arrowParens": "always",
6-
"bracketSpacing": false
3+
"jsxSingleQuote": false,
4+
"printWidth": 100,
5+
"semi": true,
6+
"singleQuote": true,
7+
"tabWidth": 2,
8+
"trailingComma": "es5"
79
}

README.md

Lines changed: 85 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,43 @@ $ yarn add generate-template-files
3131
3. Run `node generate.js` within Terminal (Mac) or Powershell (Win) once you've added your template files.
3232

3333
```js
34-
const {generateTemplateFiles} = require('generate-template-files');
34+
const { generateTemplateFiles } = require('generate-template-files');
3535

3636
const config = require('../package.json');
3737

3838
generateTemplateFiles([
39-
{
40-
option: 'Create Redux Store',
41-
defaultCase: '(pascalCase)',
42-
entry: {
43-
folderPath: './tools/templates/react/redux-store/',
44-
},
45-
stringReplacers: ['__store__', {question: 'Insert model name', slot: '__model__'}],
46-
output: {
47-
path: './src/stores/__store__(lowerCase)',
48-
pathAndFileNameDefaultCase: '(kebabCase)',
49-
},
39+
{
40+
option: 'Create Redux Store',
41+
defaultCase: '(pascalCase)',
42+
entry: {
43+
folderPath: './tools/templates/react/redux-store/',
5044
},
51-
{
52-
option: 'Create Reduce Action',
53-
defaultCase: '(pascalCase)',
54-
entry: {
55-
folderPath: './tools/templates/react/redux-store/__store__Action.ts',
56-
},
57-
stringReplacers: ['__store__', '__model__'],
58-
dynamicReplacers: [
59-
{slot: '__version__', slotValue: config.version},
60-
{slot: '__description__', slotValue: config.description},
61-
],
62-
output: {
63-
path: './src/stores/__store__/__store__(lowerCase)/__store__(pascalCase)Action.ts',
64-
pathAndFileNameDefaultCase: '(kebabCase)',
65-
},
66-
onComplete: (results) => {
67-
console.log(`results`, results);
68-
},
45+
stringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }],
46+
output: {
47+
path: './src/stores/__store__(lowerCase)',
48+
pathAndFileNameDefaultCase: '(kebabCase)',
49+
overwrite: true,
50+
},
51+
},
52+
{
53+
option: 'Create Reduce Action',
54+
defaultCase: '(pascalCase)',
55+
entry: {
56+
folderPath: './tools/templates/react/redux-store/__store__Action.ts',
6957
},
58+
stringReplacers: ['__store__', '__model__'],
59+
dynamicReplacers: [
60+
{ slot: '__version__', slotValue: config.version },
61+
{ slot: '__description__', slotValue: config.description },
62+
],
63+
output: {
64+
path: './src/stores/__store__/__store__(lowerCase)/__store__(pascalCase)Action.ts',
65+
pathAndFileNameDefaultCase: '(kebabCase)',
66+
},
67+
onComplete: (results) => {
68+
console.log(`results`, results);
69+
},
70+
},
7071
]);
7172
```
7273

@@ -88,15 +89,16 @@ The `generateTemplateFiles` function takes an array of `IConfigItem` items.
8889

8990
#### `IConfigItem`
9091

91-
- `option` - The name of the option to choose when asked.
92-
- `defaultCase` - The default [Case Converters](#case-converters) to use with the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) in the template files. Default is `(noCase)`.
93-
- `entry.folderPath` - Path to a folder of files or a single template file.
92+
- `option` - The name of the option to choose when asked.
93+
- `defaultCase` - The default [Case Converters](#case-converters) to use with the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) in the template files. Default is `(noCase)`.
94+
- `entry.folderPath` - Path to a folder of files or a single template file.
9495

95-
- `stringReplacers` - An array of [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) used to replace content in the designated `entry.folderPath`.
96-
- `dynamicReplacers` - (Optional) An array of IReplacer used to replace content in the designated `entry.folderPath`.
97-
- `output.path` - The desired output path for generated files. [Case Converters](#case-converters) and [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) can be used to make the path somewhat dynamic.
98-
- `output.pathAndFileNameDefaultCase` - The [Case Converters](#case-converters) to use for the file path and file name(s).
99-
- `onComplete` - (Optional) Takes a callback function that is called once the file(s) have been outputted. A [IResults](#iresults) object will be passed to the callback.
96+
- `stringReplacers` - An array of [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) used to replace content in the designated `entry.folderPath`.
97+
- `dynamicReplacers` - (Optional) An array of IReplacer used to replace content in the designated `entry.folderPath`.
98+
- `output.path` - The desired output path for generated files. [Case Converters](#case-converters) and [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) can be used to make the path somewhat dynamic.
99+
- `output.pathAndFileNameDefaultCase` - The [Case Converters](#case-converters) to use for the file path and file name(s).
100+
- `output.overwrite` - (Optional) When `true` it will overwrite any files that are named the same.
101+
- `onComplete` - (Optional) Takes a callback function that is called once the file(s) have been outputted. A [IResults](#iresults) object will be passed to the callback.
100102

101103
###### Example
102104

@@ -126,9 +128,9 @@ The `generateTemplateFiles` function takes an array of `IConfigItem` items.
126128

127129
Below is an example of what you receive from the `onComplete` callback. It has the output path, list of files created and the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) with the value entered.
128130

129-
- `output.path` - The file(s) output path
130-
- `output.files` - List of files created
131-
- `stringReplacers` - List of [Replacer Slots](#replacer-slots-or-ireplacerslotquestion); name and values entered during the setup process
131+
- `output.path` - The file(s) output path
132+
- `output.files` - List of files created
133+
- `stringReplacers` - List of [Replacer Slots](#replacer-slots-or-ireplacerslotquestion); name and values entered during the setup process
132134

133135
###### Example data you would get from the onComplete callback
134136

@@ -164,14 +166,14 @@ Below is an example of what you receive from the `onComplete` callback. It has t
164166
[Replacer Slots](#replacer-slots-or-ireplacerslotquestion) are unique string value(s) to be replaced by the generator. An array of string values and/or `IReplacerSlotQuestion` objects can be used.
165167

166168
```javascript
167-
stringReplacers: ['__store__', {question: 'Insert model name', slot: '__model__'}];
169+
stringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }];
168170
```
169171

170172
Replacer slot can be any string value you want to use. You can use something like this in your template files and/or in the file path names.
171173

172-
- `~replacerSlot~`
173-
- `{{something else}}`
174-
- `__AnythingYouWant__`
174+
- `~replacerSlot~`
175+
- `{{something else}}`
176+
- `__AnythingYouWant__`
175177

176178
#### `IReplacerSlotQuestion`
177179

@@ -181,8 +183,8 @@ Below is an example of a `IReplacerSlotQuestion`
181183
{question: 'Insert model name', slot: '__model__'}
182184
```
183185

184-
- `question` - The question to ask the use what value should be used for the replacer `slot`
185-
- `slot` - The string value for the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion)
186+
- `question` - The question to ask the use what value should be used for the replacer `slot`
187+
- `slot` - The string value for the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion)
186188

187189
#### Dynamic Replacer Slots
188190

@@ -200,9 +202,9 @@ dynamicReplacers: [
200202

201203
Example
202204

203-
- In the generator template `__replacerSlot__` is appended by the `(pascalCase)` converter such as `__replacerSlot__(pascalCase)`.
204-
- When the generator is ran, the string `"product reducer"` is provided for `__replacerSlot__`.
205-
- As a result, the converter will produce `ProductReducer`.
205+
- In the generator template `__replacerSlot__` is appended by the `(pascalCase)` converter such as `__replacerSlot__(pascalCase)`.
206+
- When the generator is ran, the string `"product reducer"` is provided for `__replacerSlot__`.
207+
- As a result, the converter will produce `ProductReducer`.
206208

207209
Here is the string `Lives down BY the River` with each of the converters:
208210

@@ -220,32 +222,56 @@ Here is the string `Lives down BY the River` with each of the converters:
220222

221223
One Rule: no spaces between the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) and [Case Converters](#case-converters). If there is a space, [Case Converters](#case-converters) will not work.
222224

223-
- :white_check_mark: `__name__(camelCase)`
224-
- :warning: `__name__ (camelCase)`
225+
- :white_check_mark: `__name__(camelCase)`
226+
- :warning: `__name__ (camelCase)`
225227

226228
## Command Line Usage
227229

228230
You can use `generate-template-files` with the command line to generate your template files.
229231

232+
```js
233+
// generate.js
234+
const { generateTemplateFilesCommandLine } = require('generate-template-files');
235+
236+
generateTemplateFilesCommandLine([
237+
{
238+
option: 'Create Reduce Action',
239+
defaultCase: '(pascalCase)',
240+
entry: {
241+
folderPath: './tools/templates/react/redux-store/__store__Action.ts',
242+
},
243+
stringReplacers: ['__store__', '__model__'],
244+
dynamicReplacers: [
245+
{ slot: '__version__', slotValue: config.version },
246+
{ slot: '__description__', slotValue: config.description },
247+
],
248+
output: {
249+
path: './src/stores/__store__/__store__(lowerCase)/__store__(pascalCase)Action.ts',
250+
pathAndFileNameDefaultCase: '(kebabCase)',
251+
},
252+
},
253+
]);
254+
```
255+
230256
###### Minimum Options
231257

232258
```txt
233-
node ./tools/generate.js angular-ngrx-store __name__=some-name
259+
node ./tools/generate.js create-reduce-action __store__=some-name __model__=some-other-name
234260
```
235261

236262
###### All Options
237263

238264
```txt
239-
node ./tools/generate.js angular-ngrx-store __name__=some-name __model__=some-other-name --outputpath=./src/here --overwrite
265+
node ./tools/generate.js create-reduce-action __store__=some-name __model__=some-other-name --outputpath=./src/here --overwrite
240266
```
241267

242268
**Command LIne Script Overview**
243269

244-
- `node ./tools/generate.js` - Runs the `generate-template-files` library
245-
- `angular-ngrx-store` - The template name; It uses the same option name in the [IConfigItem](#iconfigitem) but converts all options names to kebab-case. For example `option: 'Angular Ngrx Store'` will be converted to `angular-ngrx-store` when using the command line
246-
- `__name__=some-name` - Are [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) and will be converted to `{ slot: "__name__", slotValue: "some-name" }`
247-
- `--outputpath=./src/here` - Will override the `output.path` in the [IConfigItem](#iconfigitem)
248-
- `--overwrite` - Will overwrite files if the files already exists
270+
- `node ./tools/generate.js` - Runs the `generate-template-files` library
271+
- `create-reduce-action` - The template name; It uses the same option name in the [IConfigItem](#iconfigitem) but converts all options names to kebab-case. For example `option: 'Create Reduce Action'` will be converted to `create-reduce-action` when using the command line
272+
- `__store__=some-name` - Are [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) and will be converted to `{ slot: "__store__", slotValue: "some-name" }`
273+
- `--outputpath=./src/here` - Will override the `output.path` in the [IConfigItem](#iconfigitem)
274+
- `--overwrite` - Will overwrite files if the files already exists
249275

250276
[npm-url]: https://npmjs.org/package/generate-template-files
251277
[downloads-img]: http://img.shields.io/npm/dm/generate-template-files.svg?style=flat-square

examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"---------- Normal Example -------------------------------------------": "",
77
"generate": "node ./tools/generate.js",
88
"---------- Command Line Example -------------------------------------": "",
9-
"commandline": "node ./tools/generate.js angular-ngrx-store __name__=some-name __model__=some-other-name --outputpath=./src/here --overwrite"
9+
"commandlineSimple": "node ./tools/commandLine.js angular-ngrx-store __name__=some-name __model__=some-other-name",
10+
"commandline": "node ./tools/commandLine.js angular-ngrx-store __name__=some-name __model__=some-other-name --outputpath=./src/here --overwrite"
1011
},
1112
"devDependencies": {
1213
"file-name": "0.1.0",

examples/tools/commandLine.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {items} = require('./items');
2+
const {generateTemplateFilesCommandLine} = require('../../dist/generate-template-files.cjs');
3+
// Note: In your file it will be like this:
4+
// const {generateTemplateFilesCommandLine} = require('generate-template-files');
5+
6+
// node ./tools/commandLine.js angular-ngrx-store __name__=some-name __model__=some-other-name --outputpath=./src/here --overwrite
7+
8+
generateTemplateFilesCommandLine(items);

0 commit comments

Comments
 (0)