Skip to content

Commit 4c98629

Browse files
chore: code formatting
1 parent 73cd43c commit 4c98629

File tree

130 files changed

+1838
-1787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1838
-1787
lines changed

.github/scripts/build.mjs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//Imports
2-
import fs from "fs/promises"
32
import ejs from "ejs"
43
import fss from "fs"
4+
import fs from "fs/promises"
55
import yaml from "js-yaml"
66
import paths from "path"
77
import sgit from "simple-git"
@@ -26,21 +26,21 @@ const __test_secrets = paths.join(paths.join(__metrics, "tests/secrets.json"))
2626
//Git setup
2727
const git = sgit(__metrics)
2828
const staged = new Set()
29-
const secrets = Object.assign(JSON.parse(`${await fs.readFile(__test_secrets)}`), { $regex: /\$\{\{\s*secrets\.(?<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*secrets\.(?<secret>\w+)\s*\}\}/})
30+
const {plugins, templates} = await metadata({log: false, diff: true})
3131
const workflow = []
3232

3333
//Plugins
3434
for (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(/(<!--header-->)[\s\S]*(<!--\/header-->)/g, `$1\n${header}\n$2`)
43-
.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`)
43+
.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`)
4444
.replace(/(<!--options-->)[\s\S]*(<!--\/options-->)/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
5656
for (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(/(<!--header-->)[\s\S]*(<!--\/header-->)/g, `$1\n${header}\n$2`)
65-
.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`),
65+
.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`),
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
7777
for (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
9797
if (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
162162
function 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

.github/scripts/markdown_example.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const browser = await puppeteer.launch({
1111
const page = await browser.newPage()
1212

1313
//Select markdown example and take screenshoot
14-
await page.setViewport({ width: 600, height: 600 })
14+
await page.setViewport({width: 600, height: 600})
1515
await page.goto("https://github.com/lowlighter/metrics/blob/examples/metrics.markdown.md")
1616
const clip = await page.evaluate(() => {
17-
const { x, y, width, height } = document.querySelector("#readme").getBoundingClientRect()
18-
return { x, y, width, height }
17+
const {x, y, width, height} = document.querySelector("#readme").getBoundingClientRect()
18+
return {x, y, width, height}
1919
})
20-
await page.screenshot({ type: "png", path: "/tmp/metrics.markdown.png", clip, omitBackground: true })
20+
await page.screenshot({type: "png", path: "/tmp/metrics.markdown.png", clip, omitBackground: true})
2121
await browser.close()

.github/scripts/presets_examples.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//Imports
2-
import fs from "fs/promises"
32
import processes from "child_process"
3+
import fs from "fs/promises"
44
import yaml from "js-yaml"
55
import fetch from "node-fetch"
66
import paths from "path"
@@ -16,7 +16,7 @@ const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)),
1616
const __presets = paths.join(__metrics, ".presets")
1717

1818
if ((!await fs.access(__presets).then(_ => true).catch(_ => false)) || (!(await fs.lstat(__presets)).isDirectory()))
19-
await sgit().clone(`https://github-actions[bot]:${process.env.GITHUB_TOKEN}@github.com/lowlighter/metrics`, __presets, { "--branch": "presets", "--single-branch": true })
19+
await sgit().clone(`https://github-actions[bot]:${process.env.GITHUB_TOKEN}@github.com/lowlighter/metrics`, __presets, {"--branch": "presets", "--single-branch": true})
2020
const git = sgit(__presets)
2121
await git.pull()
2222
const staged = new Set()
@@ -27,7 +27,7 @@ web.run = async vars => await fetch(`http://localhost:3000/lowlighter?${new url.
2727
web.start = async () =>
2828
new Promise(solve => {
2929
let stdout = ""
30-
web.instance = processes.spawn("node", ["source/app/web/index.mjs"], { env: { ...process.env, SANDBOX: true } })
30+
web.instance = processes.spawn("node", ["source/app/web/index.mjs"], {env: {...process.env, SANDBOX: true}})
3131
web.instance.stdout.on("data", data => (stdout += data, /Server ready !/.test(stdout) ? solve() : null))
3232
web.instance.stderr.on("data", data => console.error(`${data}`))
3333
})
@@ -44,13 +44,13 @@ for (const path of await fs.readdir(__presets)) {
4444

4545
//Example
4646
console.log(`generating: ${preset}/example.svg`)
47-
const svg = await web.run({ config_presets: `@${preset}`, plugins_errors_fatal: true })
47+
const svg = await web.run({config_presets: `@${preset}`, plugins_errors_fatal: true})
4848
await fs.writeFile(paths.join(__presets, path, "example.svg"), svg)
4949
staged.add(paths.join(__presets, path, "example.svg"))
5050

5151
//Readme
5252
console.log(`generating: ${preset}/README.svg`)
53-
const { name, description } = await yaml.load(await fs.readFile(paths.join(__presets, preset, "preset.yml")))
53+
const {name, description} = await yaml.load(await fs.readFile(paths.join(__presets, preset, "preset.yml")))
5454
await fs.writeFile(
5555
paths.join(__presets, path, "README.md"),
5656
`

.github/scripts/preview.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ const __preview_templates_ = paths.join(__preview, ".templates_")
1919
const __preview_about = paths.join(__preview, "about/.statics")
2020

2121
//Extract from web server
22-
const { conf, Templates } = await setup({ log: false })
23-
const templates = Object.entries(Templates).map(([name]) => ({ name, enabled: true }))
22+
const {conf, Templates} = await setup({log: false})
23+
const templates = Object.entries(Templates).map(([name]) => ({name, enabled: true}))
2424
const metadata = Object.fromEntries(
2525
Object.entries(conf.metadata.plugins)
2626
.map(([key, value]) => [key, Object.fromEntries(Object.entries(value).filter(([key]) => ["name", "icon", "category", "web", "supports", "scopes"].includes(key)))])
27-
.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]),
27+
.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]),
2828
)
29-
const enabled = Object.entries(metadata).filter(([_name, { category }]) => category !== "core").map(([name]) => ({ name, category: metadata[name]?.category ?? "community", enabled: true }))
29+
const enabled = Object.entries(metadata).filter(([_name, {category}]) => category !== "core").map(([name]) => ({name, category: metadata[name]?.category ?? "community", enabled: true}))
3030

3131
//Directories
32-
await fs.mkdir(__preview, { recursive: true })
33-
await fs.mkdir(__preview_js, { recursive: true })
34-
await fs.mkdir(__preview_css, { recursive: true })
35-
await fs.mkdir(__preview_templates, { recursive: true })
36-
await fs.mkdir(__preview_templates_, { recursive: true })
37-
await fs.mkdir(__preview_about, { recursive: true })
32+
await fs.mkdir(__preview, {recursive: true})
33+
await fs.mkdir(__preview_js, {recursive: true})
34+
await fs.mkdir(__preview_css, {recursive: true})
35+
await fs.mkdir(__preview_templates, {recursive: true})
36+
await fs.mkdir(__preview_templates_, {recursive: true})
37+
await fs.mkdir(__preview_about, {recursive: true})
3838

3939
//Web
4040
fs.copyFile(paths.join(__web, "index.html"), paths.join(__preview, "index.html"))
@@ -49,7 +49,7 @@ for (const template in conf.templates) {
4949
fs.writeFile(paths.join(__preview_templates_, template), JSON.stringify(conf.templates[template]))
5050
const __partials = paths.join(__templates, template, "partials")
5151
const __preview_partials = paths.join(__preview_templates, template, "partials")
52-
await fs.mkdir(__preview_partials, { recursive: true })
52+
await fs.mkdir(__preview_partials, {recursive: true})
5353
for (const file of await fs.readdir(__partials))
5454
fs.copyFile(paths.join(__partials, file), paths.join(__preview_partials, file))
5555
}
@@ -73,7 +73,7 @@ fs.copyFile(paths.join(__node_modules, "prismjs/components/prism-markdown.min.js
7373
fs.copyFile(paths.join(__node_modules, "clipboard/dist/clipboard.min.js"), paths.join(__preview_js, "clipboard.min.js"))
7474
//Meta
7575
fs.writeFile(paths.join(__preview, ".version"), JSON.stringify(`${conf.package.version}-preview`))
76-
fs.writeFile(paths.join(__preview, ".hosted"), JSON.stringify({ by: "metrics", link: "https://github.com/lowlighter/metrics" }))
76+
fs.writeFile(paths.join(__preview, ".hosted"), JSON.stringify({by: "metrics", link: "https://github.com/lowlighter/metrics"}))
7777
//About
7878
fs.copyFile(paths.join(__web, "about", "index.html"), paths.join(__preview, "about", "index.html"))
7979
for (const file of await fs.readdir(__web_about)) {

.github/scripts/release.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (!version)
2626
console.log(`Version: ${version}`)
2727

2828
//Load related pr
29-
const { data: { items: prs } } = await rest.search.issuesAndPullRequests({
29+
const {data: {items: prs}} = await rest.search.issuesAndPullRequests({
3030
q: `repo:${repository.owner}/${repository.name} is:pr is:merged author:${maintainer} assignee:${maintainer} Release ${version} in:title`,
3131
})
3232

@@ -40,9 +40,9 @@ console.log(`Using pr#${patchnote.number}: ${patchnote.title}`)
4040

4141
//Check whether release already exists
4242
try {
43-
const { data: { id } } = await rest.repos.getReleaseByTag({ owner: repository.owner, repo: repository.name, tag: version })
43+
const {data: {id}} = await rest.repos.getReleaseByTag({owner: repository.owner, repo: repository.name, tag: version})
4444
console.log(`Release ${version} already exists (#${id}), will replace it`)
45-
await rest.repos.deleteRelease({ owner: repository.owner, repo: repository.name, release_id: id })
45+
await rest.repos.deleteRelease({owner: repository.owner, repo: repository.name, release_id: id})
4646
console.log(`Deleting tag ${version}`)
4747
await git.push(["--delete", "origin", version])
4848
await new Promise(solve => setTimeout(solve, 15 * 1000))
@@ -52,5 +52,5 @@ catch {
5252
}
5353

5454
//Publish release
55-
await rest.repos.createRelease({ owner: repository.owner, repo: repository.name, tag_name: version, name: `Version ${version.replace(/^v/g, "")}`, body: patchnote.body })
55+
await rest.repos.createRelease({owner: repository.owner, repo: repository.name, tag_name: version, name: `Version ${version.replace(/^v/g, "")}`, body: patchnote.body})
5656
console.log(`Successfully published`)

0 commit comments

Comments
 (0)