@@ -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 ) {
0 commit comments