@@ -3,12 +3,16 @@ import fs from "fs"
3
3
import yaml from "js-yaml"
4
4
import path from "path"
5
5
import url from "url"
6
+ import fetch from "node-fetch"
6
7
7
8
//Defined categories
8
9
const categories = [ "core" , "github" , "social" , "community" ]
9
10
11
+ //Previous descriptors
12
+ let previous = null
13
+
10
14
/**Metadata descriptor parser */
11
- export default async function metadata ( { log = true } = { } ) {
15
+ export default async function metadata ( { log = true , diff = false } = { } ) {
12
16
//Paths
13
17
const __metrics = path . join ( path . dirname ( url . fileURLToPath ( import . meta. url ) ) , "../../.." )
14
18
const __templates = path . join ( __metrics , "source/templates" )
@@ -19,6 +23,16 @@ export default async function metadata({log = true} = {}) {
19
23
//Init
20
24
const logger = log ? console . debug : ( ) => null
21
25
26
+ //Diff with latest version
27
+ if ( diff ) {
28
+ try {
29
+ previous = yaml . load ( await fetch ( "https://raw.githubusercontent.com/lowlighter/metrics/latest/action.yml" ) . then ( response => response . text ( ) ) )
30
+ }
31
+ catch ( error ) {
32
+ logger ( error )
33
+ }
34
+ }
35
+
22
36
//Load plugins metadata
23
37
let Plugins = { }
24
38
logger ( "metrics/metadata > loading plugins metadata" )
@@ -254,8 +268,47 @@ metadata.plugin = async function({__plugins, name, logger}) {
254
268
const raw = `${ await fs . promises . readFile ( path . join ( __plugins , name , "README.md" ) , "utf-8" ) } `
255
269
const demo = raw . match ( / (?< demo > < t a b l e > [ \s \S ] * ?< [ / ] t a b l e > ) / ) ?. groups ?. demo ?. replace ( / < [ / ] ? (?: t a b l e | t r ) > / g, "" ) ?. trim ( ) ?? "<td></td>"
256
270
271
+ //Options table
272
+ const table = [
273
+ "| Option | Type *(format)* **[default]** *{allowed values}* | Description |" ,
274
+ "| ------ | -------------------------------- | ----------- |" ,
275
+ Object . entries ( inputs ) . map ( ( [ option , { description, type, ...o } ] ) => {
276
+ let row = [ ]
277
+ {
278
+ const cell = [ `${ "`" } ${ option } ${ "`" } ` ]
279
+ if ( type === "token" )
280
+ cell . push ( "🔐" )
281
+ if ( ! Object . keys ( previous ?. inputs ?? { } ) . includes ( option ) )
282
+ cell . push ( "✨" )
283
+ row . push ( cell . join ( " " ) )
284
+ }
285
+ {
286
+ const cell = [ `${ "`" } ${ type } ${ "`" } ` ]
287
+ if ( "format" in o )
288
+ cell . push ( `*(${ o . format } )*` )
289
+ if ( "default" in o )
290
+ cell . push ( `**[${ o . default } ]**` )
291
+ if ( "values" in o )
292
+ cell . push ( `*{${ o . values . map ( value => `"${ value } "` ) . join ( ", " ) } }*` )
293
+ if ( "min" in o )
294
+ cell . push ( `*{${ o . min } ≤` )
295
+ if ( ( "min" in o ) || ( "max" in o ) )
296
+ cell . push ( `${ "min" in o ? "" : "*{" } 𝑥${ "max" in o ? "" : "}*" } ` )
297
+ if ( "max" in o )
298
+ cell . push ( `≤ ${ o . max } }*` )
299
+ row . push ( cell . join ( " " ) )
300
+ }
301
+ row . push ( description )
302
+ return `| ${ row . join ( " | " ) } |`
303
+ } ) . join ( "\n" ) ,
304
+ "\n" ,
305
+ "Legend for option icons:" ,
306
+ "* 🔐 Value should be stored in repository secrets" ,
307
+ "* ✨ New feature currently in testing on `master`/`main`"
308
+ ] . flat ( Infinity ) . filter ( s => s ) . join ( "\n" )
309
+
257
310
//Readme descriptor
258
- meta . readme = { demo}
311
+ meta . readme = { demo, table }
259
312
}
260
313
261
314
//Icon
0 commit comments