chore: code formatting
This commit is contained in:
54
.github/scripts/build.mjs
vendored
54
.github/scripts/build.mjs
vendored
@@ -1,7 +1,7 @@
|
||||
//Imports
|
||||
import fs from "fs/promises"
|
||||
import ejs from "ejs"
|
||||
import fss from "fs"
|
||||
import fs from "fs/promises"
|
||||
import yaml from "js-yaml"
|
||||
import paths from "path"
|
||||
import sgit from "simple-git"
|
||||
@@ -26,13 +26,13 @@ const __test_secrets = paths.join(paths.join(__metrics, "tests/secrets.json"))
|
||||
//Git setup
|
||||
const git = sgit(__metrics)
|
||||
const staged = new Set()
|
||||
const secrets = Object.assign(JSON.parse(`${await fs.readFile(__test_secrets)}`), { $regex: /\$\{\{\s*secrets\.(?<secret>\w+)\s*\}\}/ })
|
||||
const { plugins, templates } = await metadata({ log: false, diff: true })
|
||||
const secrets = Object.assign(JSON.parse(`${await fs.readFile(__test_secrets)}`), {$regex: /\$\{\{\s*secrets\.(?<secret>\w+)\s*\}\}/})
|
||||
const {plugins, templates} = await metadata({log: false, diff: true})
|
||||
const workflow = []
|
||||
|
||||
//Plugins
|
||||
for (const id of Object.keys(plugins)) {
|
||||
const { examples, options, readme, tests, header, community } = await plugin(id)
|
||||
const {examples, options, readme, tests, header, community} = await plugin(id)
|
||||
|
||||
//Readme
|
||||
console.log(`Generating source/plugins/${community ? "community/" : ""}${id}/README.md`)
|
||||
@@ -40,7 +40,7 @@ for (const id of Object.keys(plugins)) {
|
||||
readme.path,
|
||||
readme.content
|
||||
.replace(/(<!--header-->)[\s\S]*(<!--\/header-->)/g, `$1\n${header}\n$2`)
|
||||
.replace(/(<!--examples-->)[\s\S]*(<!--\/examples-->)/g, `$1\n${examples.map(({ test, prod, ...step }) => ["```yaml", yaml.dump(step, { quotingType: '"', noCompatMode: true }), "```"].join("\n")).join("\n")}\n$2`)
|
||||
.replace(/(<!--examples-->)[\s\S]*(<!--\/examples-->)/g, `$1\n${examples.map(({test, prod, ...step}) => ["```yaml", yaml.dump(step, {quotingType: '"', noCompatMode: true}), "```"].join("\n")).join("\n")}\n$2`)
|
||||
.replace(/(<!--options-->)[\s\S]*(<!--\/options-->)/g, `$1\n${options}\n$2`),
|
||||
)
|
||||
staged.add(readme.path)
|
||||
@@ -54,7 +54,7 @@ for (const id of Object.keys(plugins)) {
|
||||
|
||||
//Templates
|
||||
for (const id of Object.keys(templates)) {
|
||||
const { examples, readme, tests, header } = await template(id)
|
||||
const {examples, readme, tests, header} = await template(id)
|
||||
|
||||
//Readme
|
||||
console.log(`Generating source/templates/${id}/README.md`)
|
||||
@@ -62,14 +62,14 @@ for (const id of Object.keys(templates)) {
|
||||
readme.path,
|
||||
readme.content
|
||||
.replace(/(<!--header-->)[\s\S]*(<!--\/header-->)/g, `$1\n${header}\n$2`)
|
||||
.replace(/(<!--examples-->)[\s\S]*(<!--\/examples-->)/g, `$1\n${examples.map(({ test, prod, ...step }) => ["```yaml", yaml.dump(step, { quotingType: '"', noCompatMode: true }), "```"].join("\n")).join("\n")}\n$2`),
|
||||
.replace(/(<!--examples-->)[\s\S]*(<!--\/examples-->)/g, `$1\n${examples.map(({test, prod, ...step}) => ["```yaml", yaml.dump(step, {quotingType: '"', noCompatMode: true}), "```"].join("\n")).join("\n")}\n$2`),
|
||||
)
|
||||
staged.add(readme.path)
|
||||
|
||||
//Tests
|
||||
console.log(`Generating tests/templates/${id}.yml`)
|
||||
workflow.push(...examples.map(example => testcase(templates[id].name, "prod", example)).filter(t => t))
|
||||
await fs.writeFile(tests.path, yaml.dump(examples.map(example => testcase(templates[id].name, "test", example)).filter(t => t), { quotingType: '"', noCompatMode: true }))
|
||||
await fs.writeFile(tests.path, yaml.dump(examples.map(example => testcase(templates[id].name, "test", example)).filter(t => t), {quotingType: '"', noCompatMode: true}))
|
||||
staged.add(tests.path)
|
||||
}
|
||||
|
||||
@@ -77,21 +77,21 @@ for (const id of Object.keys(templates)) {
|
||||
for (const step of ["config", "documentation"]) {
|
||||
switch (step) {
|
||||
case "config":
|
||||
await update({ source: paths.join(__action, "action.yml"), output: "action.yml" })
|
||||
await update({ source: paths.join(__web, "settings.example.json"), output: "settings.example.json" })
|
||||
await update({source: paths.join(__action, "action.yml"), output: "action.yml"})
|
||||
await update({source: paths.join(__web, "settings.example.json"), output: "settings.example.json"})
|
||||
break
|
||||
case "documentation":
|
||||
await update({ source: paths.join(__documentation, "README.md"), output: "README.md", options: { root: __readme } })
|
||||
await update({ source: paths.join(__documentation, "plugins.md"), output: "source/plugins/README.md" })
|
||||
await update({ source: paths.join(__documentation, "plugins.community.md"), output: "source/plugins/community/README.md" })
|
||||
await update({ source: paths.join(__documentation, "templates.md"), output: "source/templates/README.md" })
|
||||
await update({ source: paths.join(__documentation, "compatibility.md"), output: ".github/readme/partials/documentation/compatibility.md" })
|
||||
await update({source: paths.join(__documentation, "README.md"), output: "README.md", options: {root: __readme}})
|
||||
await update({source: paths.join(__documentation, "plugins.md"), output: "source/plugins/README.md"})
|
||||
await update({source: paths.join(__documentation, "plugins.community.md"), output: "source/plugins/community/README.md"})
|
||||
await update({source: paths.join(__documentation, "templates.md"), output: "source/templates/README.md"})
|
||||
await update({source: paths.join(__documentation, "compatibility.md"), output: ".github/readme/partials/documentation/compatibility.md"})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
//Example workflows
|
||||
await update({ source: paths.join(__metrics, ".github/scripts/files/examples.yml"), output: ".github/workflows/examples.yml", context: { steps: yaml.dump(workflow, { quotingType: '"', noCompatMode: true }) } })
|
||||
await update({source: paths.join(__metrics, ".github/scripts/files/examples.yml"), output: ".github/workflows/examples.yml", context: {steps: yaml.dump(workflow, {quotingType: '"', noCompatMode: true})}})
|
||||
|
||||
//Commit and push
|
||||
if (mode === "publish") {
|
||||
@@ -109,10 +109,10 @@ console.log("Success!")
|
||||
//==================================================================================
|
||||
|
||||
//Update generated files
|
||||
async function update({ source, output, context = {}, options = {} }) {
|
||||
async function update({source, output, context = {}, options = {}}) {
|
||||
console.log(`Generating ${output}`)
|
||||
const { plugins, templates, packaged, descriptor } = await metadata({ log: false })
|
||||
const content = await ejs.renderFile(source, { plugins, templates, packaged, descriptor, ...context }, { async: true, ...options })
|
||||
const {plugins, templates, packaged, descriptor} = await metadata({log: false})
|
||||
const content = await ejs.renderFile(source, {plugins, templates, packaged, descriptor, ...context}, {async: true, ...options})
|
||||
const file = paths.join(__metrics, output)
|
||||
await fs.writeFile(file, content)
|
||||
staged.add(file)
|
||||
@@ -160,15 +160,15 @@ async function template(id) {
|
||||
|
||||
//Testcase generator
|
||||
function testcase(name, env, args) {
|
||||
const { prod = {}, test = {}, ...step } = JSON.parse(JSON.stringify(args))
|
||||
const context = { prod, test }[env] ?? {}
|
||||
const { with: overrides } = context
|
||||
const {prod = {}, test = {}, ...step} = JSON.parse(JSON.stringify(args))
|
||||
const context = {prod, test}[env] ?? {}
|
||||
const {with: overrides} = context
|
||||
if (context.skip)
|
||||
return null
|
||||
|
||||
Object.assign(step.with, context.with ?? {})
|
||||
delete context.with
|
||||
const result = { ...step, ...context, name: `${name} - ${step.name ?? "(unnamed)"}` }
|
||||
const result = {...step, ...context, name: `${name} - ${step.name ?? "(unnamed)"}`}
|
||||
for (const [k, v] of Object.entries(result.with)) {
|
||||
if ((env === "test") && (secrets.$regex.test(v)))
|
||||
result.with[k] = v.replace(secrets.$regex, secrets[v.match(secrets.$regex)?.groups?.secret])
|
||||
@@ -177,21 +177,21 @@ function testcase(name, env, args) {
|
||||
if (env === "prod") {
|
||||
result.if = "${{ success() || failure() }}"
|
||||
result.uses = "lowlighter/metrics@master"
|
||||
Object.assign(result.with, { output_action: "none", delay: 120 })
|
||||
Object.assign(result.with, {output_action: "none", delay: 120})
|
||||
|
||||
for (const { property, value } of [{ property: "user", value: "lowlighter" }, { property: "plugins_errors_fatal", value: "yes" }]) {
|
||||
for (const {property, value} of [{property: "user", value: "lowlighter"}, {property: "plugins_errors_fatal", value: "yes"}]) {
|
||||
if (!(property in result.with))
|
||||
result.with[property] = value
|
||||
}
|
||||
if ((overrides?.output_action) && (overrides?.committer_branch === "examples"))
|
||||
Object.assign(result.with, { output_action: overrides.output_action, committer_branch: "examples" })
|
||||
Object.assign(result.with, {output_action: overrides.output_action, committer_branch: "examples"})
|
||||
}
|
||||
|
||||
if (env === "test") {
|
||||
if (!result.with.base)
|
||||
delete result.with.base
|
||||
delete result.with.filename
|
||||
Object.assign(result.with, { use_mocked_data: "yes", verify: "yes" })
|
||||
Object.assign(result.with, {use_mocked_data: "yes", verify: "yes"})
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
8
.github/scripts/markdown_example.mjs
vendored
8
.github/scripts/markdown_example.mjs
vendored
@@ -11,11 +11,11 @@ const browser = await puppeteer.launch({
|
||||
const page = await browser.newPage()
|
||||
|
||||
//Select markdown example and take screenshoot
|
||||
await page.setViewport({ width: 600, height: 600 })
|
||||
await page.setViewport({width: 600, height: 600})
|
||||
await page.goto("https://github.com/lowlighter/metrics/blob/examples/metrics.markdown.md")
|
||||
const clip = await page.evaluate(() => {
|
||||
const { x, y, width, height } = document.querySelector("#readme").getBoundingClientRect()
|
||||
return { x, y, width, height }
|
||||
const {x, y, width, height} = document.querySelector("#readme").getBoundingClientRect()
|
||||
return {x, y, width, height}
|
||||
})
|
||||
await page.screenshot({ type: "png", path: "/tmp/metrics.markdown.png", clip, omitBackground: true })
|
||||
await page.screenshot({type: "png", path: "/tmp/metrics.markdown.png", clip, omitBackground: true})
|
||||
await browser.close()
|
||||
|
||||
10
.github/scripts/presets_examples.mjs
vendored
10
.github/scripts/presets_examples.mjs
vendored
@@ -1,6 +1,6 @@
|
||||
//Imports
|
||||
import fs from "fs/promises"
|
||||
import processes from "child_process"
|
||||
import fs from "fs/promises"
|
||||
import yaml from "js-yaml"
|
||||
import fetch from "node-fetch"
|
||||
import paths from "path"
|
||||
@@ -16,7 +16,7 @@ const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)),
|
||||
const __presets = paths.join(__metrics, ".presets")
|
||||
|
||||
if ((!await fs.access(__presets).then(_ => true).catch(_ => false)) || (!(await fs.lstat(__presets)).isDirectory()))
|
||||
await sgit().clone(`https://github-actions[bot]:${process.env.GITHUB_TOKEN}@github.com/lowlighter/metrics`, __presets, { "--branch": "presets", "--single-branch": true })
|
||||
await sgit().clone(`https://github-actions[bot]:${process.env.GITHUB_TOKEN}@github.com/lowlighter/metrics`, __presets, {"--branch": "presets", "--single-branch": true})
|
||||
const git = sgit(__presets)
|
||||
await git.pull()
|
||||
const staged = new Set()
|
||||
@@ -27,7 +27,7 @@ web.run = async vars => await fetch(`http://localhost:3000/lowlighter?${new url.
|
||||
web.start = async () =>
|
||||
new Promise(solve => {
|
||||
let stdout = ""
|
||||
web.instance = processes.spawn("node", ["source/app/web/index.mjs"], { env: { ...process.env, SANDBOX: true } })
|
||||
web.instance = processes.spawn("node", ["source/app/web/index.mjs"], {env: {...process.env, SANDBOX: true}})
|
||||
web.instance.stdout.on("data", data => (stdout += data, /Server ready !/.test(stdout) ? solve() : null))
|
||||
web.instance.stderr.on("data", data => console.error(`${data}`))
|
||||
})
|
||||
@@ -44,13 +44,13 @@ for (const path of await fs.readdir(__presets)) {
|
||||
|
||||
//Example
|
||||
console.log(`generating: ${preset}/example.svg`)
|
||||
const svg = await web.run({ config_presets: `@${preset}`, plugins_errors_fatal: true })
|
||||
const svg = await web.run({config_presets: `@${preset}`, plugins_errors_fatal: true})
|
||||
await fs.writeFile(paths.join(__presets, path, "example.svg"), svg)
|
||||
staged.add(paths.join(__presets, path, "example.svg"))
|
||||
|
||||
//Readme
|
||||
console.log(`generating: ${preset}/README.svg`)
|
||||
const { name, description } = await yaml.load(await fs.readFile(paths.join(__presets, preset, "preset.yml")))
|
||||
const {name, description} = await yaml.load(await fs.readFile(paths.join(__presets, preset, "preset.yml")))
|
||||
await fs.writeFile(
|
||||
paths.join(__presets, path, "README.md"),
|
||||
`
|
||||
|
||||
24
.github/scripts/preview.mjs
vendored
24
.github/scripts/preview.mjs
vendored
@@ -19,22 +19,22 @@ const __preview_templates_ = paths.join(__preview, ".templates_")
|
||||
const __preview_about = paths.join(__preview, "about/.statics")
|
||||
|
||||
//Extract from web server
|
||||
const { conf, Templates } = await setup({ log: false })
|
||||
const templates = Object.entries(Templates).map(([name]) => ({ name, enabled: true }))
|
||||
const {conf, Templates} = await setup({log: false})
|
||||
const templates = Object.entries(Templates).map(([name]) => ({name, enabled: true}))
|
||||
const metadata = Object.fromEntries(
|
||||
Object.entries(conf.metadata.plugins)
|
||||
.map(([key, value]) => [key, Object.fromEntries(Object.entries(value).filter(([key]) => ["name", "icon", "category", "web", "supports", "scopes"].includes(key)))])
|
||||
.map(([key, value]) => [key, key === "core" ? { ...value, web: Object.fromEntries(Object.entries(value.web).filter(([key]) => /^config[.]/.test(key)).map(([key, value]) => [key.replace(/^config[.]/, ""), value])) } : value]),
|
||||
.map(([key, value]) => [key, key === "core" ? {...value, web: Object.fromEntries(Object.entries(value.web).filter(([key]) => /^config[.]/.test(key)).map(([key, value]) => [key.replace(/^config[.]/, ""), value]))} : value]),
|
||||
)
|
||||
const enabled = Object.entries(metadata).filter(([_name, { category }]) => category !== "core").map(([name]) => ({ name, category: metadata[name]?.category ?? "community", enabled: true }))
|
||||
const enabled = Object.entries(metadata).filter(([_name, {category}]) => category !== "core").map(([name]) => ({name, category: metadata[name]?.category ?? "community", enabled: true}))
|
||||
|
||||
//Directories
|
||||
await fs.mkdir(__preview, { recursive: true })
|
||||
await fs.mkdir(__preview_js, { recursive: true })
|
||||
await fs.mkdir(__preview_css, { recursive: true })
|
||||
await fs.mkdir(__preview_templates, { recursive: true })
|
||||
await fs.mkdir(__preview_templates_, { recursive: true })
|
||||
await fs.mkdir(__preview_about, { recursive: true })
|
||||
await fs.mkdir(__preview, {recursive: true})
|
||||
await fs.mkdir(__preview_js, {recursive: true})
|
||||
await fs.mkdir(__preview_css, {recursive: true})
|
||||
await fs.mkdir(__preview_templates, {recursive: true})
|
||||
await fs.mkdir(__preview_templates_, {recursive: true})
|
||||
await fs.mkdir(__preview_about, {recursive: true})
|
||||
|
||||
//Web
|
||||
fs.copyFile(paths.join(__web, "index.html"), paths.join(__preview, "index.html"))
|
||||
@@ -49,7 +49,7 @@ for (const template in conf.templates) {
|
||||
fs.writeFile(paths.join(__preview_templates_, template), JSON.stringify(conf.templates[template]))
|
||||
const __partials = paths.join(__templates, template, "partials")
|
||||
const __preview_partials = paths.join(__preview_templates, template, "partials")
|
||||
await fs.mkdir(__preview_partials, { recursive: true })
|
||||
await fs.mkdir(__preview_partials, {recursive: true})
|
||||
for (const file of await fs.readdir(__partials))
|
||||
fs.copyFile(paths.join(__partials, file), paths.join(__preview_partials, file))
|
||||
}
|
||||
@@ -73,7 +73,7 @@ fs.copyFile(paths.join(__node_modules, "prismjs/components/prism-markdown.min.js
|
||||
fs.copyFile(paths.join(__node_modules, "clipboard/dist/clipboard.min.js"), paths.join(__preview_js, "clipboard.min.js"))
|
||||
//Meta
|
||||
fs.writeFile(paths.join(__preview, ".version"), JSON.stringify(`${conf.package.version}-preview`))
|
||||
fs.writeFile(paths.join(__preview, ".hosted"), JSON.stringify({ by: "metrics", link: "https://github.com/lowlighter/metrics" }))
|
||||
fs.writeFile(paths.join(__preview, ".hosted"), JSON.stringify({by: "metrics", link: "https://github.com/lowlighter/metrics"}))
|
||||
//About
|
||||
fs.copyFile(paths.join(__web, "about", "index.html"), paths.join(__preview, "about", "index.html"))
|
||||
for (const file of await fs.readdir(__web_about)) {
|
||||
|
||||
8
.github/scripts/release.mjs
vendored
8
.github/scripts/release.mjs
vendored
@@ -26,7 +26,7 @@ if (!version)
|
||||
console.log(`Version: ${version}`)
|
||||
|
||||
//Load related pr
|
||||
const { data: { items: prs } } = await rest.search.issuesAndPullRequests({
|
||||
const {data: {items: prs}} = await rest.search.issuesAndPullRequests({
|
||||
q: `repo:${repository.owner}/${repository.name} is:pr is:merged author:${maintainer} assignee:${maintainer} Release ${version} in:title`,
|
||||
})
|
||||
|
||||
@@ -40,9 +40,9 @@ console.log(`Using pr#${patchnote.number}: ${patchnote.title}`)
|
||||
|
||||
//Check whether release already exists
|
||||
try {
|
||||
const { data: { id } } = await rest.repos.getReleaseByTag({ owner: repository.owner, repo: repository.name, tag: version })
|
||||
const {data: {id}} = await rest.repos.getReleaseByTag({owner: repository.owner, repo: repository.name, tag: version})
|
||||
console.log(`Release ${version} already exists (#${id}), will replace it`)
|
||||
await rest.repos.deleteRelease({ owner: repository.owner, repo: repository.name, release_id: id })
|
||||
await rest.repos.deleteRelease({owner: repository.owner, repo: repository.name, release_id: id})
|
||||
console.log(`Deleting tag ${version}`)
|
||||
await git.push(["--delete", "origin", version])
|
||||
await new Promise(solve => setTimeout(solve, 15 * 1000))
|
||||
@@ -52,5 +52,5 @@ catch {
|
||||
}
|
||||
|
||||
//Publish release
|
||||
await rest.repos.createRelease({ owner: repository.owner, repo: repository.name, tag_name: version, name: `Version ${version.replace(/^v/g, "")}`, body: patchnote.body })
|
||||
await rest.repos.createRelease({owner: repository.owner, repo: repository.name, tag_name: version, name: `Version ${version.replace(/^v/g, "")}`, body: patchnote.body})
|
||||
console.log(`Successfully published`)
|
||||
|
||||
Reference in New Issue
Block a user