@@ -14,21 +14,19 @@ const tokens = [
1414] ;
1515
1616/**
17- *
18- * @param {String } templateFilePath
17+ * Create a solution template for each day.
18+ * @param {String } template
1919 * @param {Number[] } days
2020 * @returns {Array<Promise> }
2121 */
22- const doCreate = async ( templateFilePath , year , days ) => {
23- const template = await readFile ( templateFilePath , { encoding : 'utf-8' } ) ;
24- return days . map ( ( day ) =>
22+ const doCreate = ( template , year , days ) =>
23+ days . map ( ( day ) =>
2524 writeFile (
2625 getSolutionFileName ( day ) ,
2726 replaceTokens ( tokens , { year, day } , template ) ,
2827 'utf-8'
2928 )
3029 ) ;
31- } ;
3230
3331/**
3432 * Creates the solution files in the cwd.
@@ -40,20 +38,19 @@ export const createSolutionFiles = async ({ year } = {}) => {
4038 throw new Error ( 'null or undefined year' ) ;
4139 }
4240
41+ // create solution dir if does not already exist.
4342 await ensureDir ( getConfigValue ( 'paths.solutionsDir' ) ) ;
4443
45- await Promise . all ( [
44+ // load the template files (last day is special and needs a different template than default)
45+ const [ basicTemplate , lastDayTemplate ] = await Promise . all ( [
46+ readFile ( getConfigValue ( 'paths.templates.solutionDefault' ) , 'utf8' ) ,
47+ readFile ( getConfigValue ( 'paths.templates.solutionLastDay' ) , 'utf8' ) ,
48+ ] ) ;
49+
50+ return Promise . all ( [
4651 // all days but the last day share a default solution template.
47- ...doCreate (
48- getConfigValue ( 'paths.templates.solutionDefault' ) ,
49- year ,
50- getConfigValue ( 'aoc.validation.days' ) . slice ( 0 , - 1 )
51- ) ,
52+ ...doCreate ( basicTemplate , year , getConfigValue ( 'aoc.validation.days' ) . slice ( 0 , - 1 ) ) ,
5253 // last day is special and needs a different solution template.
53- ...doCreate (
54- getConfigValue ( 'paths.templates.solutionLastDay' ) ,
55- year ,
56- getConfigValue ( 'aoc.validation.days' ) . slice ( - 1 )
57- ) ,
54+ ...doCreate ( lastDayTemplate , year , getConfigValue ( 'aoc.validation.days' ) . slice ( - 1 ) ) ,
5855 ] ) ;
5956} ;
0 commit comments