Skip to content

Commit fd961f7

Browse files
committed
PR Feedback
1 parent 7a82e1a commit fd961f7

File tree

6 files changed

+69
-48
lines changed

6 files changed

+69
-48
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44
[*]
55
charset = utf-8
66
indent_style = space
7-
indent_size = 4
7+
indent_size = 2
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,21 @@ Here is the string `Lives down BY the River` with each of the converters:
212212
// If you typed in 'Lives down BY the River' for the a Replacer Slot named '__replacerSlot__' and
213213
// used one of the optional Case Converters you would get the following:
214214

215-
__replacerSlot__(noCase) // Lives down BY the River
216-
__replacerSlot__(camelCase) // livesDownByTheRiver
217-
__replacerSlot__(constantCase) // LIVES_DOWN_BY_THE_RIVER
218-
__replacerSlot__(dotCase) // lives.down.by.the.river
219-
__replacerSlot__(kebabCase) // lives-down-by-the-river
220-
__replacerSlot__(lowerCase) // livesdownbytheriver
221-
__replacerSlot__(pascalCase) // LivesDownByTheRiver
222-
__replacerSlot__(pathCase) // lives/down/by/the/river
223-
__replacerSlot__(sentenceCase) // Lives down by the river
224-
__replacerSlot__(snakeCase) // lives_down_by_the_river
225-
__replacerSlot__(titleCase) // Lives Down By The River
215+
__replacerSlot__(noCase); // Lives down BY the River
216+
__replacerSlot__(camelCase); // livesDownByTheRiver
217+
__replacerSlot__(constantCase); // LIVES_DOWN_BY_THE_RIVER
218+
__replacerSlot__(dotCase); // lives.down.by.the.river
219+
__replacerSlot__(kebabCase); // lives-down-by-the-river
220+
__replacerSlot__(lowerCase); // livesdownbytheriver
221+
__replacerSlot__(pascalCase); // LivesDownByTheRiver
222+
__replacerSlot__(pathCase); // lives/down/by/the/river
223+
__replacerSlot__(sentenceCase); // Lives down by the river
224+
__replacerSlot__(snakeCase); // lives_down_by_the_river
225+
__replacerSlot__(titleCase); // Lives Down By The River
226226

227227
// Note: you can set a 'defaultCase' converter in IConfigItem so all
228228
// Replacer Slots without a Case Converter will be transformed the same way.
229-
__replacerSlot__ // LivesDownByTheRiver
229+
__replacerSlot__; // LivesDownByTheRiver
230230
```
231231

232232
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.
@@ -240,15 +240,15 @@ You can use `generate-template-files` to generate your template files programmat
240240

241241
The following example will generate the component, unit tests, and the SCSS module in one do.
242242

243-
```ts
244-
// generateTemplateFile.ts
245-
import { generateTemplateFilesCommandLine, CaseConverterEnum } from 'generate-template-files');
243+
```js
244+
// generateTemplateFile.js
245+
const { generateTemplateFilesBatch } = require('generate-template-files');
246246

247-
export const componentWithInterface = async (componentName: string, componentScope: string = "common"): Promise<void> => {
248-
await generateTemplateFilesBatch([
247+
const componentWithInterface = (componentName, componentScope = 'common') => {
248+
generateTemplateFilesBatch([
249249
{
250250
option: 'Component',
251-
defaultCase: CaseConverterEnum.PascalCase,
251+
defaultCase: '(pascalCase)',
252252
entry: {
253253
folderPath: './tools/templates/react/component',
254254
},
@@ -258,12 +258,12 @@ export const componentWithInterface = async (componentName: string, componentSco
258258
],
259259
output: {
260260
path: `./src/component/__scope__(camelCase)`,
261-
pathAndFileNameDefaultCase: CaseConverterEnum.PascalCase,
261+
pathAndFileNameDefaultCase: '(pascalCase)',
262262
},
263263
},
264264
{
265265
option: 'Component Interface',
266-
defaultCase: CaseConverterEnum.PascalCase,
266+
defaultCase: '(pascalCase)',
267267
entry: {
268268
folderPath: './tools/templates/react/I__interface__.ts',
269269
},
@@ -273,10 +273,12 @@ export const componentWithInterface = async (componentName: string, componentSco
273273
],
274274
output: {
275275
path: `./src/component/__scope__(camelCase)/I__interface__.ts`,
276-
pathAndFileNameDefaultCase: CaseConverterEnum.PascalCase,
276+
pathAndFileNameDefaultCase: '(pascalCase)',
277277
},
278278
},
279-
]);
279+
]).catch(() => {
280+
console.log('Build Error');
281+
});
280282
};
281283
```
282284

examples/tools/batchGenerate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// generateTemplateFile.js
22
const {generateTemplateFilesBatch, CaseConverterEnum} = require('../../dist/generate-template-files.cjs');
33
// Note: In your file it will be like this:
4-
// const {generateTemplateFilesBatch} = require('generate-template-files');
4+
// const {generateTemplateFilesBatch, CaseConverterEnum} = require('generate-template-files');
55

66
const componentName = "Example"
77
const componentScope = "common"

src/GenerateTemplateFiles.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,14 @@ export default class GenerateTemplateFiles {
9696
public async batchGenerate(options: Omit<IConfigItem, 'stringReplacers'>[]) {
9797
this._isBatch = true;
9898

99-
try {
100-
throwErrorIfNoConfigItems(options);
101-
throwErrorIfStringReplacersExistOrNoDynamicReplacers(options);
99+
throwErrorIfNoConfigItems(options);
100+
throwErrorIfStringReplacersExistOrNoDynamicReplacers(options);
102101

103-
for (const selectedConfigItem of options) {
104-
const answeredReplacers: IReplacer[] = await this._getDynamicReplacerSlotValues(
105-
selectedConfigItem
106-
);
107-
await this._outputFiles(selectedConfigItem, answeredReplacers);
108-
}
109-
} catch (error) {
110-
displayError(error.message);
102+
for (const selectedConfigItem of options) {
103+
const answeredReplacers: IReplacer[] = await this._getDynamicReplacerSlotValues(
104+
selectedConfigItem
105+
);
106+
await this._outputFiles(selectedConfigItem, answeredReplacers);
111107
}
112108
}
113109

src/utilities/GenerateTemplateFiles.batch.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import GenerateTemplateFiles from '../GenerateTemplateFiles';
22
import { IConfigItem } from '../index';
33
import CaseConverterEnum from '../constants/CaseConverterEnum';
44

5-
describe.skip('GenerateTemplateFiles - Batch', () => {
5+
describe('GenerateTemplateFiles - Batch', () => {
66
test('should throw an error if no IConfigItem items', () => {
77
const items: IConfigItem[] = [];
88
const gtf = new GenerateTemplateFiles();
@@ -12,7 +12,7 @@ describe.skip('GenerateTemplateFiles - Batch', () => {
1212
);
1313
});
1414

15-
test('should throw an error if no stringReplacers or dynamicReplacers', () => {
15+
test('should throw an error if no stringReplacers or dynamicReplacers', async () => {
1616
const items: IConfigItem[] = [
1717
{
1818
option: 'some-template',
@@ -27,12 +27,12 @@ describe.skip('GenerateTemplateFiles - Batch', () => {
2727
];
2828
const gtf = new GenerateTemplateFiles();
2929

30-
expect(() => gtf.commandLine(items)).rejects.toThrowError(
31-
'IConfigItem needs to have a stringReplacers or dynamicReplacers.'
30+
await expect(() => gtf.batchGenerate(items)).rejects.toThrowError(
31+
'IConfigItem for batchGenerate does not support stringReplacers, and must have dynamicReplacers'
3232
);
3333
});
3434

35-
test('should throw an error if batch IConfigItem is not found for option name', () => {
35+
test('should throw an error if batch IConfigItem is not found for option name', async () => {
3636
const items: IConfigItem[] = [
3737
{
3838
option: 'some-template',
@@ -48,7 +48,7 @@ describe.skip('GenerateTemplateFiles - Batch', () => {
4848
];
4949
const gtf = new GenerateTemplateFiles();
5050

51-
expect(() => gtf.batchGenerate(items)).rejects.toThrowError(
51+
await expect(() => gtf.batchGenerate(items)).rejects.toThrowError(
5252
`IConfigItem for batchGenerate does not support stringReplacers, and must have dynamicReplacers.`
5353
);
5454
});

src/utilities/GenerateTemplateFiles.commandline.test.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ import GenerateTemplateFiles from '../GenerateTemplateFiles';
22
import { IConfigItem } from '../index';
33
import CaseConverterEnum from '../constants/CaseConverterEnum';
44
import yargs from 'yargs';
5+
import colors from 'colors';
6+
7+
let consoleInfoSpy: jest.SpyInstance;
8+
describe('GenerateTemplateFiles - Command Line', () => {
9+
beforeEach(() => {
10+
consoleInfoSpy = jest.spyOn(global.console, 'info').mockImplementation(() => null);
11+
});
12+
13+
afterEach(() => {
14+
consoleInfoSpy.mockRestore();
15+
});
516

6-
describe.skip('GenerateTemplateFiles - Command Line', () => {
717
test('should throw an error if no IConfigItem items', () => {
818
const items: IConfigItem[] = [];
919
const gtf = new GenerateTemplateFiles();
1020

11-
expect(() => gtf.commandLine(items)).rejects.toThrowError(
12-
'There was no IConfigItem items found.'
21+
gtf.commandLine(items);
22+
expect(consoleInfoSpy).toBeCalledWith(
23+
colors.bold.red(
24+
`[Error in generate-template-files]: ${colors.red('There was no IConfigItem items found.')}`
25+
)
1326
);
1427
});
1528

@@ -33,8 +46,13 @@ describe.skip('GenerateTemplateFiles - Command Line', () => {
3346
];
3447
const gtf = new GenerateTemplateFiles();
3548

36-
expect(() => gtf.commandLine(items)).rejects.toThrowError(
37-
`No IConfigItem found for ${notFoundOptionName}`
49+
gtf.commandLine(items);
50+
expect(consoleInfoSpy).toBeCalledWith(
51+
colors.bold.red(
52+
`[Error in generate-template-files]: ${colors.red(
53+
`No IConfigItem found for ${notFoundOptionName}`
54+
)}`
55+
)
3856
);
3957
});
4058

@@ -53,8 +71,13 @@ describe.skip('GenerateTemplateFiles - Command Line', () => {
5371
];
5472
const gtf = new GenerateTemplateFiles();
5573

56-
expect(() => gtf.commandLine(items)).rejects.toThrowError(
57-
'IConfigItem needs to have a stringReplacers or dynamicReplacers.'
74+
gtf.commandLine(items);
75+
expect(consoleInfoSpy).toBeCalledWith(
76+
colors.bold.red(
77+
`[Error in generate-template-files]: ${colors.red(
78+
'IConfigItem needs to have a stringReplacers or dynamicReplacers.'
79+
)}`
80+
)
5881
);
5982
});
6083
});

0 commit comments

Comments
 (0)