docs: updated workflows examples and options descriptions (#772) [skip ci]
This commit is contained in:
@@ -3,12 +3,16 @@ import fs from "fs"
|
||||
import yaml from "js-yaml"
|
||||
import path from "path"
|
||||
import url from "url"
|
||||
import fetch from "node-fetch"
|
||||
|
||||
//Defined categories
|
||||
const categories = ["core", "github", "social", "community"]
|
||||
|
||||
//Previous descriptors
|
||||
let previous = null
|
||||
|
||||
/**Metadata descriptor parser */
|
||||
export default async function metadata({log = true} = {}) {
|
||||
export default async function metadata({log = true, diff = false} = {}) {
|
||||
//Paths
|
||||
const __metrics = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "../../..")
|
||||
const __templates = path.join(__metrics, "source/templates")
|
||||
@@ -19,6 +23,16 @@ export default async function metadata({log = true} = {}) {
|
||||
//Init
|
||||
const logger = log ? console.debug : () => null
|
||||
|
||||
//Diff with latest version
|
||||
if (diff) {
|
||||
try {
|
||||
previous = yaml.load(await fetch("https://raw.githubusercontent.com/lowlighter/metrics/latest/action.yml").then(response => response.text()))
|
||||
}
|
||||
catch (error) {
|
||||
logger(error)
|
||||
}
|
||||
}
|
||||
|
||||
//Load plugins metadata
|
||||
let Plugins = {}
|
||||
logger("metrics/metadata > loading plugins metadata")
|
||||
@@ -254,8 +268,47 @@ metadata.plugin = async function({__plugins, name, logger}) {
|
||||
const raw = `${await fs.promises.readFile(path.join(__plugins, name, "README.md"), "utf-8")}`
|
||||
const demo = raw.match(/(?<demo><table>[\s\S]*?<[/]table>)/)?.groups?.demo?.replace(/<[/]?(?:table|tr)>/g, "")?.trim() ?? "<td></td>"
|
||||
|
||||
//Options table
|
||||
const table = [
|
||||
"| Option | Type *(format)* **[default]** *{allowed values}* | Description |",
|
||||
"| ------ | -------------------------------- | ----------- |",
|
||||
Object.entries(inputs).map(([option, {description, type, ...o}]) => {
|
||||
let row = []
|
||||
{
|
||||
const cell = [`${"`"}${option}${"`"}`]
|
||||
if (type === "token")
|
||||
cell.push("🔐")
|
||||
if (!Object.keys(previous?.inputs ?? {}).includes(option))
|
||||
cell.push("✨")
|
||||
row.push(cell.join(" "))
|
||||
}
|
||||
{
|
||||
const cell = [`${"`"}${type}${"`"}`]
|
||||
if ("format" in o)
|
||||
cell.push(`*(${o.format})*`)
|
||||
if ("default" in o)
|
||||
cell.push(`**[${o.default}]**`)
|
||||
if ("values" in o)
|
||||
cell.push(`*{${o.values.map(value => `"${value}"`).join(", ")}}*`)
|
||||
if ("min" in o)
|
||||
cell.push(`*{${o.min} ≤`)
|
||||
if (("min" in o)||("max" in o))
|
||||
cell.push(`${"min" in o ? "" : "*{"}𝑥${"max" in o ? "" : "}*"}`)
|
||||
if ("max" in o)
|
||||
cell.push(`≤ ${o.max}}*`)
|
||||
row.push(cell.join(" "))
|
||||
}
|
||||
row.push(description)
|
||||
return `| ${row.join(" | ")} |`
|
||||
}).join("\n"),
|
||||
"\n",
|
||||
"Legend for option icons:",
|
||||
"* 🔐 Value should be stored in repository secrets",
|
||||
"* ✨ New feature currently in testing on `master`/`main`"
|
||||
].flat(Infinity).filter(s => s).join("\n")
|
||||
|
||||
//Readme descriptor
|
||||
meta.readme = {demo}
|
||||
meta.readme = {demo, table}
|
||||
}
|
||||
|
||||
//Icon
|
||||
|
||||
Reference in New Issue
Block a user