Skip to content

Commit daf75ee

Browse files
committed
prettier
1 parent 61298f4 commit daf75ee

File tree

5 files changed

+77
-36
lines changed

5 files changed

+77
-36
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"arrowParens": "always",
33
"jsxSingleQuote": false,
4-
"printWidth": 120,
4+
"printWidth": 100,
55
"semi": true,
66
"singleQuote": true,
77
"tabWidth": 2,

src/GenerateTemplateFiles.ts

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export default class GenerateTemplateFiles {
5151
);
5252
});
5353

54-
errorIfOptionNameIsNotFound(selectedConfigItem, StringUtility.toCase(templateName, CaseConverterEnum.KebabCase));
54+
errorIfOptionNameIsNotFound(
55+
selectedConfigItem,
56+
StringUtility.toCase(templateName, CaseConverterEnum.KebabCase)
57+
);
5558

5659
const commandLineStringReplacers: IReplacer[] = replacers.map((str: string) => {
5760
const [slot, slotValue] = str.split('=');
@@ -66,10 +69,16 @@ export default class GenerateTemplateFiles {
6669

6770
const dynamicReplacers: IReplacer[] = selectedConfigItem?.dynamicReplacers || [];
6871

69-
await this._outputFiles(selectedConfigItem!, [...commandLineStringReplacers, ...dynamicReplacers]);
72+
await this._outputFiles(selectedConfigItem!, [
73+
...commandLineStringReplacers,
74+
...dynamicReplacers,
75+
]);
7076
}
7177

72-
private async _outputFiles(selectedConfigItem: IConfigItem, replacers: IReplacer[]): Promise<void> {
78+
private async _outputFiles(
79+
selectedConfigItem: IConfigItem,
80+
replacers: IReplacer[]
81+
): Promise<void> {
7382
const { contentCase, outputPathCase } = this._getDefaultCaseConverters(selectedConfigItem);
7483
const contentReplacers: IReplacer[] = this._getReplacers(replacers, contentCase);
7584
const outputPathReplacers: IReplacer[] = this._getReplacers(replacers, outputPathCase);
@@ -114,13 +123,16 @@ export default class GenerateTemplateFiles {
114123
};
115124
const templateAnswers: { optionChoice: string } = await enquirer.prompt(templateQuestions);
116125

117-
return options.find((item: IConfigItem) => item.option === templateAnswers.optionChoice) as IConfigItem;
126+
return options.find(
127+
(item: IConfigItem) => item.option === templateAnswers.optionChoice
128+
) as IConfigItem;
118129
}
119130

120131
/**
121132
*/
122133
private _getDefaultCaseConverters(selectedConfigItem: IConfigItem): IDefaultCaseConverter {
123-
const defaultContentCase: CaseConverterEnum = selectedConfigItem?.defaultCase ?? CaseConverterEnum.None;
134+
const defaultContentCase: CaseConverterEnum =
135+
selectedConfigItem?.defaultCase ?? CaseConverterEnum.None;
124136
const defaultOutputPath: CaseConverterEnum =
125137
selectedConfigItem.output?.pathAndFileNameDefaultCase ?? defaultContentCase;
126138

@@ -134,7 +146,8 @@ export default class GenerateTemplateFiles {
134146
* New question asking what should text should be used to replace the template text.
135147
*/
136148
private async _getReplacerSlotValues(selectedConfigItem: IConfigItem): Promise<IReplacer[]> {
137-
const stringReplacers: (string | IReplacerSlotQuestion)[] = selectedConfigItem.stringReplacers ?? [];
149+
const stringReplacers: (string | IReplacerSlotQuestion)[] =
150+
selectedConfigItem.stringReplacers ?? [];
138151
const replacerQuestions: any[] = stringReplacers.map((item: string | IReplacerSlotQuestion) => {
139152
return {
140153
type: 'input',
@@ -169,34 +182,43 @@ export default class GenerateTemplateFiles {
169182
private _getReplacers(replacers: IReplacer[], defaultCase: CaseConverterEnum): IReplacer[] {
170183
const caseTypes: string[] = Object.values(CaseConverterEnum);
171184

172-
return replacers.reduce((previousReplacers: IReplacer[], answeredReplacer: IReplacer): IReplacer[] => {
173-
const { slot, slotValue } = answeredReplacer;
174-
175-
return [
176-
...previousReplacers,
177-
...caseTypes.map(
178-
(caseType: string): IReplacer => {
179-
return {
180-
slot: `${slot}${caseType}`,
181-
slotValue: StringUtility.toCase(slotValue, caseType as CaseConverterEnum),
182-
};
183-
}
184-
),
185-
{
186-
slot,
187-
slotValue: StringUtility.toCase(slotValue, defaultCase),
188-
},
189-
];
190-
}, []);
185+
return replacers.reduce(
186+
(previousReplacers: IReplacer[], answeredReplacer: IReplacer): IReplacer[] => {
187+
const { slot, slotValue } = answeredReplacer;
188+
189+
return [
190+
...previousReplacers,
191+
...caseTypes.map(
192+
(caseType: string): IReplacer => {
193+
return {
194+
slot: `${slot}${caseType}`,
195+
slotValue: StringUtility.toCase(slotValue, caseType as CaseConverterEnum),
196+
};
197+
}
198+
),
199+
{
200+
slot,
201+
slotValue: StringUtility.toCase(slotValue, defaultCase),
202+
},
203+
];
204+
},
205+
[]
206+
);
191207
}
192208

193209
/**
194210
*/
195-
private async _getOutputPath(outputPathReplacers: IReplacer[], selectedConfigItem: IConfigItem): Promise<string> {
211+
private async _getOutputPath(
212+
outputPathReplacers: IReplacer[],
213+
selectedConfigItem: IConfigItem
214+
): Promise<string> {
196215
// Create the output path replacing any template keys.
197-
const outputPathFormatted: string = outputPathReplacers.reduce((outputPath: string, replacer: IReplacer) => {
198-
return replaceString(outputPath, replacer.slot, replacer.slotValue);
199-
}, selectedConfigItem.output.path);
216+
const outputPathFormatted: string = outputPathReplacers.reduce(
217+
(outputPath: string, replacer: IReplacer) => {
218+
return replaceString(outputPath, replacer.slot, replacer.slotValue);
219+
},
220+
selectedConfigItem.output.path
221+
);
200222

201223
if (this._isCommandLine) {
202224
const outputPath = yargs.argv.outputpath as string | undefined;
@@ -216,7 +238,10 @@ export default class GenerateTemplateFiles {
216238

217239
/**
218240
*/
219-
private async _shouldWriteFiles(outputPath: string, selectedConfigItem: IConfigItem): Promise<boolean> {
241+
private async _shouldWriteFiles(
242+
outputPath: string,
243+
selectedConfigItem: IConfigItem
244+
): Promise<boolean> {
220245
const doesPathExist: boolean = await pathExists(outputPath);
221246

222247
if (!doesPathExist) {

src/utilities/CheckUtility.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export const errorIfNoConfigItems = (options: IConfigItem[]) => {
4444
errorMessageAndExit(!hasAtLeastOneItem, 'There was no IConfigItem items found.');
4545
};
4646

47-
export const errorIfOptionNameIsNotFound = (item: IConfigItem | undefined, templateName: string) => {
47+
export const errorIfOptionNameIsNotFound = (
48+
item: IConfigItem | undefined,
49+
templateName: string
50+
) => {
4851
errorMessageAndExit(!item, `No IConfigItem found for ${templateName}`);
4952
};
5053

@@ -83,5 +86,8 @@ export const errorIfNoStringOrDynamicReplacers = (options: IConfigItem[]) => {
8386
return Boolean(item?.stringReplacers?.length) || Boolean(item?.dynamicReplacers?.length);
8487
}) && options.length > 0;
8588

86-
errorMessageAndExit(!hasStringOrDynamicReplacers, 'IConfigItem needs to have a stringReplacers or dynamicReplacers.');
89+
errorMessageAndExit(
90+
!hasStringOrDynamicReplacers,
91+
'IConfigItem needs to have a stringReplacers or dynamicReplacers.'
92+
);
8793
};

src/utilities/GenerateTemplateFiles.commandline.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ describe('GenerateTemplateFiles - Command Line', () => {
88
const items: IConfigItem[] = [];
99
const gtf = new GenerateTemplateFiles();
1010

11-
expect(() => gtf.commandLine(items)).rejects.toThrowError('There was no IConfigItem items found.');
11+
expect(() => gtf.commandLine(items)).rejects.toThrowError(
12+
'There was no IConfigItem items found.'
13+
);
1214
});
1315

1416
test('should throw an error if IConfigItem is not found for option name', () => {
@@ -31,7 +33,9 @@ describe('GenerateTemplateFiles - Command Line', () => {
3133
];
3234
const gtf = new GenerateTemplateFiles();
3335

34-
expect(() => gtf.commandLine(items)).rejects.toThrowError(`No IConfigItem found for ${notFoundOptionName}`);
36+
expect(() => gtf.commandLine(items)).rejects.toThrowError(
37+
`No IConfigItem found for ${notFoundOptionName}`
38+
);
3539
});
3640

3741
test('should throw an error if no stringReplacers or dynamicReplacers', () => {

tslint.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
],
5252
"triple-equals": [true, "allow-null-check"],
5353
"typedef": [true, "parameter", "property-declaration"],
54-
"variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case", "allow-leading-underscore"]
54+
"variable-name": [
55+
true,
56+
"ban-keywords",
57+
"check-format",
58+
"allow-pascal-case",
59+
"allow-leading-underscore"
60+
]
5561
}
5662
}

0 commit comments

Comments
 (0)