11//Imports
2- import fs from "fs/promises"
32import ejs from "ejs"
43import fss from "fs"
4+ import fs from "fs/promises"
55import yaml from "js-yaml"
66import paths from "path"
77import sgit from "simple-git"
@@ -26,21 +26,21 @@ const __test_secrets = paths.join(paths.join(__metrics, "tests/secrets.json"))
2626//Git setup
2727const git = sgit ( __metrics )
2828const staged = new Set ( )
29- const secrets = Object . assign ( JSON . parse ( `${ await fs . readFile ( __test_secrets ) } ` ) , { $regex : / \$ \{ \{ \s * s e c r e t s \. (?< secret > \w + ) \s * \} \} / } )
30- const { plugins, templates } = await metadata ( { log : false , diff : true } )
29+ const secrets = Object . assign ( JSON . parse ( `${ await fs . readFile ( __test_secrets ) } ` ) , { $regex : / \$ \{ \{ \s * s e c r e t s \. (?< secret > \w + ) \s * \} \} / } )
30+ const { plugins, templates} = await metadata ( { log : false , diff : true } )
3131const workflow = [ ]
3232
3333//Plugins
3434for ( const id of Object . keys ( plugins ) ) {
35- const { examples, options, readme, tests, header, community } = await plugin ( id )
35+ const { examples, options, readme, tests, header, community} = await plugin ( id )
3636
3737 //Readme
3838 console . log ( `Generating source/plugins/${ community ? "community/" : "" } ${ id } /README.md` )
3939 await fs . writeFile (
4040 readme . path ,
4141 readme . content
4242 . replace ( / ( < ! - - h e a d e r - - > ) [ \s \S ] * ( < ! - - \/ h e a d e r - - > ) / g, `$1\n${ header } \n$2` )
43- . replace ( / ( < ! - - e x a m p l e s - - > ) [ \s \S ] * ( < ! - - \/ e x a m p l e s - - > ) / g, `$1\n${ examples . map ( ( { test, prod, ...step } ) => [ "```yaml" , yaml . dump ( step , { quotingType : '"' , noCompatMode : true } ) , "```" ] . join ( "\n" ) ) . join ( "\n" ) } \n$2` )
43+ . replace ( / ( < ! - - e x a m p l e s - - > ) [ \s \S ] * ( < ! - - \/ e x a m p l e s - - > ) / g, `$1\n${ examples . map ( ( { test, prod, ...step } ) => [ "```yaml" , yaml . dump ( step , { quotingType : '"' , noCompatMode : true } ) , "```" ] . join ( "\n" ) ) . join ( "\n" ) } \n$2` )
4444 . replace ( / ( < ! - - o p t i o n s - - > ) [ \s \S ] * ( < ! - - \/ o p t i o n s - - > ) / g, `$1\n${ options } \n$2` ) ,
4545 )
4646 staged . add ( readme . path )
@@ -54,44 +54,44 @@ for (const id of Object.keys(plugins)) {
5454
5555//Templates
5656for ( const id of Object . keys ( templates ) ) {
57- const { examples, readme, tests, header } = await template ( id )
57+ const { examples, readme, tests, header} = await template ( id )
5858
5959 //Readme
6060 console . log ( `Generating source/templates/${ id } /README.md` )
6161 await fs . writeFile (
6262 readme . path ,
6363 readme . content
6464 . replace ( / ( < ! - - h e a d e r - - > ) [ \s \S ] * ( < ! - - \/ h e a d e r - - > ) / g, `$1\n${ header } \n$2` )
65- . replace ( / ( < ! - - e x a m p l e s - - > ) [ \s \S ] * ( < ! - - \/ e x a m p l e s - - > ) / g, `$1\n${ examples . map ( ( { test, prod, ...step } ) => [ "```yaml" , yaml . dump ( step , { quotingType : '"' , noCompatMode : true } ) , "```" ] . join ( "\n" ) ) . join ( "\n" ) } \n$2` ) ,
65+ . replace ( / ( < ! - - e x a m p l e s - - > ) [ \s \S ] * ( < ! - - \/ e x a m p l e s - - > ) / g, `$1\n${ examples . map ( ( { test, prod, ...step } ) => [ "```yaml" , yaml . dump ( step , { quotingType : '"' , noCompatMode : true } ) , "```" ] . join ( "\n" ) ) . join ( "\n" ) } \n$2` ) ,
6666 )
6767 staged . add ( readme . path )
6868
6969 //Tests
7070 console . log ( `Generating tests/templates/${ id } .yml` )
7171 workflow . push ( ...examples . map ( example => testcase ( templates [ id ] . name , "prod" , example ) ) . filter ( t => t ) )
72- await fs . writeFile ( tests . path , yaml . dump ( examples . map ( example => testcase ( templates [ id ] . name , "test" , example ) ) . filter ( t => t ) , { quotingType : '"' , noCompatMode : true } ) )
72+ await fs . writeFile ( tests . path , yaml . dump ( examples . map ( example => testcase ( templates [ id ] . name , "test" , example ) ) . filter ( t => t ) , { quotingType : '"' , noCompatMode : true } ) )
7373 staged . add ( tests . path )
7474}
7575
7676//Config and general documentation auto-generation
7777for ( const step of [ "config" , "documentation" ] ) {
7878 switch ( step ) {
7979 case "config" :
80- await update ( { source : paths . join ( __action , "action.yml" ) , output : "action.yml" } )
81- await update ( { source : paths . join ( __web , "settings.example.json" ) , output : "settings.example.json" } )
80+ await update ( { source : paths . join ( __action , "action.yml" ) , output : "action.yml" } )
81+ await update ( { source : paths . join ( __web , "settings.example.json" ) , output : "settings.example.json" } )
8282 break
8383 case "documentation" :
84- await update ( { source : paths . join ( __documentation , "README.md" ) , output : "README.md" , options : { root : __readme } } )
85- await update ( { source : paths . join ( __documentation , "plugins.md" ) , output : "source/plugins/README.md" } )
86- await update ( { source : paths . join ( __documentation , "plugins.community.md" ) , output : "source/plugins/community/README.md" } )
87- await update ( { source : paths . join ( __documentation , "templates.md" ) , output : "source/templates/README.md" } )
88- await update ( { source : paths . join ( __documentation , "compatibility.md" ) , output : ".github/readme/partials/documentation/compatibility.md" } )
84+ await update ( { source : paths . join ( __documentation , "README.md" ) , output : "README.md" , options : { root : __readme } } )
85+ await update ( { source : paths . join ( __documentation , "plugins.md" ) , output : "source/plugins/README.md" } )
86+ await update ( { source : paths . join ( __documentation , "plugins.community.md" ) , output : "source/plugins/community/README.md" } )
87+ await update ( { source : paths . join ( __documentation , "templates.md" ) , output : "source/templates/README.md" } )
88+ await update ( { source : paths . join ( __documentation , "compatibility.md" ) , output : ".github/readme/partials/documentation/compatibility.md" } )
8989 break
9090 }
9191}
9292
9393//Example workflows
94- await update ( { source : paths . join ( __metrics , ".github/scripts/files/examples.yml" ) , output : ".github/workflows/examples.yml" , context : { steps : yaml . dump ( workflow , { quotingType : '"' , noCompatMode : true } ) } } )
94+ await update ( { source : paths . join ( __metrics , ".github/scripts/files/examples.yml" ) , output : ".github/workflows/examples.yml" , context : { steps : yaml . dump ( workflow , { quotingType : '"' , noCompatMode : true } ) } } )
9595
9696//Commit and push
9797if ( mode === "publish" ) {
@@ -109,10 +109,10 @@ console.log("Success!")
109109//==================================================================================
110110
111111//Update generated files
112- async function update ( { source, output, context = { } , options = { } } ) {
112+ async function update ( { source, output, context = { } , options = { } } ) {
113113 console . log ( `Generating ${ output } ` )
114- const { plugins, templates, packaged, descriptor } = await metadata ( { log : false } )
115- const content = await ejs . renderFile ( source , { plugins, templates, packaged, descriptor, ...context } , { async : true , ...options } )
114+ const { plugins, templates, packaged, descriptor} = await metadata ( { log : false } )
115+ const content = await ejs . renderFile ( source , { plugins, templates, packaged, descriptor, ...context } , { async : true , ...options } )
116116 const file = paths . join ( __metrics , output )
117117 await fs . writeFile ( file , content )
118118 staged . add ( file )
@@ -160,15 +160,15 @@ async function template(id) {
160160
161161//Testcase generator
162162function testcase ( name , env , args ) {
163- const { prod = { } , test = { } , ...step } = JSON . parse ( JSON . stringify ( args ) )
164- const context = { prod, test } [ env ] ?? { }
165- const { with : overrides } = context
163+ const { prod = { } , test = { } , ...step } = JSON . parse ( JSON . stringify ( args ) )
164+ const context = { prod, test} [ env ] ?? { }
165+ const { with : overrides } = context
166166 if ( context . skip )
167167 return null
168168
169169 Object . assign ( step . with , context . with ?? { } )
170170 delete context . with
171- const result = { ...step , ...context , name : `${ name } - ${ step . name ?? "(unnamed)" } ` }
171+ const result = { ...step , ...context , name : `${ name } - ${ step . name ?? "(unnamed)" } ` }
172172 for ( const [ k , v ] of Object . entries ( result . with ) ) {
173173 if ( ( env === "test" ) && ( secrets . $regex . test ( v ) ) )
174174 result . with [ k ] = v . replace ( secrets . $regex , secrets [ v . match ( secrets . $regex ) ?. groups ?. secret ] )
@@ -177,21 +177,21 @@ function testcase(name, env, args) {
177177 if ( env === "prod" ) {
178178 result . if = "${{ success() || failure() }}"
179179 result . uses = "lowlighter/metrics@master"
180- Object . assign ( result . with , { output_action : "none" , delay : 120 } )
180+ Object . assign ( result . with , { output_action : "none" , delay : 120 } )
181181
182- for ( const { property, value } of [ { property : "user" , value : "lowlighter" } , { property : "plugins_errors_fatal" , value : "yes" } ] ) {
182+ for ( const { property, value} of [ { property : "user" , value : "lowlighter" } , { property : "plugins_errors_fatal" , value : "yes" } ] ) {
183183 if ( ! ( property in result . with ) )
184184 result . with [ property ] = value
185185 }
186186 if ( ( overrides ?. output_action ) && ( overrides ?. committer_branch === "examples" ) )
187- Object . assign ( result . with , { output_action : overrides . output_action , committer_branch : "examples" } )
187+ Object . assign ( result . with , { output_action : overrides . output_action , committer_branch : "examples" } )
188188 }
189189
190190 if ( env === "test" ) {
191191 if ( ! result . with . base )
192192 delete result . with . base
193193 delete result . with . filename
194- Object . assign ( result . with , { use_mocked_data : "yes" , verify : "yes" } )
194+ Object . assign ( result . with , { use_mocked_data : "yes" , verify : "yes" } )
195195 }
196196
197197 return result
0 commit comments