chore: code formatting

This commit is contained in:
github-actions[bot]
2022-01-16 01:41:24 +00:00
parent 4fa62aad67
commit d3228a126a
94 changed files with 3875 additions and 3822 deletions

View File

@@ -78,11 +78,11 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
console.debug(`metrics/compute/${login} > json output`)
const cache = new WeakSet()
const rendered = JSON.parse(JSON.stringify(data, (key, value) => {
if ((value instanceof Set)||(Array.isArray(value)))
if ((value instanceof Set) || (Array.isArray(value)))
return [...value]
if (value instanceof Map)
return Object.fromEntries(value)
if ((typeof value === "object")&&(value)) {
if ((typeof value === "object") && (value)) {
if (cache.has(value))
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, cache.has(v) ? "[Circular]" : v]))
cache.add(value)
@@ -227,14 +227,23 @@ metrics.insights = async function({login}, {graphql, rest, conf}, {Plugins, Temp
"habits.days":7,
"habits.facts":false,
"habits.charts":true,
introduction:true
introduction:true,
}
const plugins = {
achievements:{enabled:true},
isocalendar:{enabled:true},
languages:{enabled:true, extras:false},
activity:{enabled:true, markdown:"extended"},
notable:{enabled:true},
followup:{enabled:true},
habits:{enabled:true, extras:false},
introduction:{enabled:true},
}
const plugins = {achievements:{enabled:true}, isocalendar:{enabled:true}, languages:{enabled:true, extras:false}, activity:{enabled:true, markdown:"extended"}, notable:{enabled:true}, followup:{enabled:true}, habits:{enabled:true, extras:false}, introduction:{enabled:true}}
return metrics({login, q}, {graphql, rest, plugins, conf, convert:"json"}, {Plugins, Templates})
}
//Metrics insights static render
metrics.insights.output = async function ({login, imports, conf}, {graphql, rest, Plugins, Templates}) {
metrics.insights.output = async function({login, imports, conf}, {graphql, rest, Plugins, Templates}) {
//Server
console.debug(`metrics/compute/${login} > insights`)
const server = `http://localhost:${conf.settings.port}`
@@ -248,7 +257,7 @@ metrics.insights.output = async function ({login, imports, conf}, {graphql, rest
await page.goto(`${server}/about/${login}?embed=1&localstorage=1`)
await page.evaluate(async json => localStorage.setItem("local.metrics", json), json) //eslint-disable-line no-undef
await page.goto(`${server}/about/${login}?embed=1&localstorage=1`)
await page.waitForSelector(".container .user", {timeout:10*60*1000})
await page.waitForSelector(".container .user", {timeout:10 * 60 * 1000})
//Rendering
console.debug(`metrics/compute/${login} > insights > rendering data`)
@@ -266,4 +275,4 @@ metrics.insights.output = async function ({login, imports, conf}, {graphql, rest
</html>`
await browser.close()
return {mime:"text/html", rendered}
}
}

View File

@@ -1,10 +1,10 @@
//Imports
import fs from "fs"
import yaml from "js-yaml"
import {marked} from "marked"
import fetch from "node-fetch"
import path from "path"
import url from "url"
import fetch from "node-fetch"
import {marked} from "marked"
//Defined categories
const categories = ["core", "github", "social", "community"]
@@ -293,23 +293,25 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
` <td>${Object.entries(compatibility).filter(([_, value]) => value).map(([id]) => `<a href="/source/templates/${id}"><code>${templates[id].name ?? ""}</code></a>`).join(" ")}</td>`,
" </tr>",
" <tr>",
` <td>${[
meta.supports?.includes("user") ? "<code>👤 Users</code>" : "",
meta.supports?.includes("organization") ? "<code>👥 Organizations</code>" : "",
meta.supports?.includes("repository") ? "<code>📓 Repositories</code>" : ""
].filter(v => v).join(" ")}</td>`,
` <td>${
[
meta.supports?.includes("user") ? "<code>👤 Users</code>" : "",
meta.supports?.includes("organization") ? "<code>👥 Organizations</code>" : "",
meta.supports?.includes("repository") ? "<code>📓 Repositories</code>" : "",
].filter(v => v).join(" ")
}</td>`,
" </tr>",
" <tr>",
` <td>${[
...(meta.scopes ?? []).map(scope => `<code>🔑 ${{public_access:"(scopeless)"}[scope] ?? scope}</code>`),
...Object.entries(inputs).filter(([_, {type}]) => type === "token").map(([token]) => `<code>🗝 ${token}</code>`),
...(meta.scopes?.length ? ["read:org", "read:user", "repo"].map(scope => !meta.scopes.includes(scope) ? `<code>${scope} (optional)</code>` : null).filter(v => v) : [])
...(meta.scopes?.length ? ["read:org", "read:user", "repo"].map(scope => !meta.scopes.includes(scope) ? `<code>${scope} (optional)</code>` : null).filter(v => v) : []),
].filter(v => v).join(" ") || "<i>No tokens are required for this plugin</i>"}</td>`,
" </tr>",
" <tr>",
demos({colspan:2, wrap:name === "base", examples:meta.examples}),
" </tr>",
"</table>"
"</table>",
].join("\n")
//Options table
@@ -339,14 +341,14 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
cell.push(`<i>(${Array.isArray(o.format) ? o.format[0] : o.format})</i>`)
if ("min" in o)
cell.push(`<i>(${o.min}`)
if (("min" in o)||("max" in o))
if (("min" in o) || ("max" in o))
cell.push(`${"min" in o ? "" : "<i>("}𝑥${"max" in o ? "" : ")</i>"}`)
if ("max" in o)
cell.push(`${o.max})</i>`)
cell.push("<br>")
if ("zero" in o)
cell.push(`<b>zero behaviour:</b> ${o.zero}</br>`)
if (("default" in o)&&(o.default !== "")) {
if (("default" in o) && (o.default !== "")) {
let text = o.default
if (o.default === ".user.login")
text = "<code>→ User login</code>"
@@ -414,26 +416,30 @@ metadata.template = async function({__templates, name, plugins, logger}) {
` <td>${Object.entries(compatibility).filter(([_, value]) => value).map(([id]) => `<a href="/source/plugins/${id}" title="${plugins[id].name}">${plugins[id].icon}</a>`).join(" ")}${meta.formats?.includes("markdown") ? " <code>✓ embed()</code>" : ""}</td>`,
" </tr>",
" <tr>",
` <td>${[
meta.supports?.includes("user") ? "<code>👤 Users</code>" : "",
meta.supports?.includes("organization") ? "<code>👥 Organizations</code>" : "",
meta.supports?.includes("repository") ? "<code>📓 Repositories</code>" : ""
].filter(v => v).join(" ")}</td>`,
` <td>${
[
meta.supports?.includes("user") ? "<code>👤 Users</code>" : "",
meta.supports?.includes("organization") ? "<code>👥 Organizations</code>" : "",
meta.supports?.includes("repository") ? "<code>📓 Repositories</code>" : "",
].filter(v => v).join(" ")
}</td>`,
" </tr>",
" <tr>",
` <td>${[
meta.formats?.includes("svg") ? "<code>*️⃣ SVG</code>" : "",
meta.formats?.includes("png") ? "<code>*️⃣ PNG</code>" : "",
meta.formats?.includes("jpeg") ? "<code>*️⃣ JPEG</code>" : "",
meta.formats?.includes("json") ? "<code>#️⃣ JSON</code>" : "",
meta.formats?.includes("markdown") ? "<code>🔠 Markdown</code>" : "",
meta.formats?.includes("markdown-pdf") ? "<code>🔠 Markdown (PDF)</code>" : "",
].filter(v => v).join(" ")}</td>`,
` <td>${
[
meta.formats?.includes("svg") ? "<code>*️⃣ SVG</code>" : "",
meta.formats?.includes("png") ? "<code>*️⃣ PNG</code>" : "",
meta.formats?.includes("jpeg") ? "<code>*️⃣ JPEG</code>" : "",
meta.formats?.includes("json") ? "<code>#️⃣ JSON</code>" : "",
meta.formats?.includes("markdown") ? "<code>🔠 Markdown</code>" : "",
meta.formats?.includes("markdown-pdf") ? "<code>🔠 Markdown (PDF)</code>" : "",
].filter(v => v).join(" ")
}</td>`,
" </tr>",
" <tr>",
demos({colspan:2, examples:meta.examples}),
" </tr>",
"</table>"
"</table>",
].join("\n")
//Result
@@ -448,9 +454,9 @@ metadata.template = async function({__templates, name, plugins, logger}) {
compatibility:{
...Object.fromEntries(Object.entries(compatibility).filter(([_, value]) => value)),
...Object.fromEntries(Object.entries(compatibility).filter(([_, value]) => !value).map(([key, value]) => [key, meta.formats?.includes("markdown") ? "embed" : value])),
base:true
base:true,
},
header
header,
},
check({q, account = "bypass", format = null}) {
//Support check
@@ -481,31 +487,33 @@ metadata.to = {
//Demo for main and individual readmes
function demos({colspan = null, wrap = false, examples = {}} = {}) {
if (("default1" in examples)&&("default2" in examples)) {
if (("default1" in examples) && ("default2" in examples)) {
return [
wrap ? '<td colspan="2"><table><tr>' : "",
'<td align="center">',
`<img src="${examples.default1}" alt=""></img>`,
`<img src="${examples.default1}" alt=""></img>`,
"</td>",
'<td align="center">',
`<img src="${examples.default2}" alt=""></img>`,
`<img src="${examples.default2}" alt=""></img>`,
"</td>",
wrap ? "</tr></table></td>" : "",
].filter(v => v).join("\n")
}
return [
` <td ${colspan ? `colspan="${colspan}"` : ""} align="center">`,
`${Object.entries(examples).map(([text, link]) => {
let img = `<img src="${link}" alt=""></img>`
if (text !== "default") {
const open = text.charAt(0) === "+" ? " open" : ""
text = open ? text.substring(1) : text
text = `${text.charAt(0).toLocaleUpperCase()}${text.substring(1)}`
img = `<details${open}><summary>${text}</summary>${img}</details>`
}
return ` ${img}`
}).join("\n")}`,
`${
Object.entries(examples).map(([text, link]) => {
let img = `<img src="${link}" alt=""></img>`
if (text !== "default") {
const open = text.charAt(0) === "+" ? " open" : ""
text = open ? text.substring(1) : text
text = `${text.charAt(0).toLocaleUpperCase()}${text.substring(1)}`
img = `<details${open}><summary>${text}</summary>${img}</details>`
}
return ` ${img}`
}).join("\n")
}`,
' <img width="900" height="1" alt="">',
" </td>"
" </td>",
].filter(v => v).join("\n")
}

View File

@@ -3,38 +3,38 @@ import fs from "fs/promises"
import prism_lang from "prismjs/components/index.js"
import axios from "axios"
import processes from "child_process"
import crypto from "crypto"
import {minify as csso} from "csso"
import emoji from "emoji-name-map"
import fss from "fs"
import GIFEncoder from "gifencoder"
import jimp from "jimp"
import linguist from "linguist-js"
import {marked} from "marked"
import minimatch from "minimatch"
import nodechartist from "node-chartist"
import fetch from "node-fetch"
import opengraph from "open-graph-scraper"
import os from "os"
import paths from "path"
import PNG from "png-js"
import prism from "prismjs"
import _puppeteer from "puppeteer"
import purgecss from "purgecss"
import readline from "readline"
import rss from "rss-parser"
import htmlsanitize from "sanitize-html"
import git from "simple-git"
import SVGO from "svgo"
import twemojis from "twemoji-parser"
import url from "url"
import util from "util"
import fetch from "node-fetch"
import readline from "readline"
import emoji from "emoji-name-map"
import minimatch from "minimatch"
import crypto from "crypto"
import linguist from "linguist-js"
import purgecss from "purgecss"
import {minify as csso} from "csso"
import SVGO from "svgo"
import xmlformat from "xml-formatter"
prism_lang()
//Exports
export {axios, fs, git, jimp, opengraph, os, paths, processes, rss, url, fetch, util, emoji, minimatch}
export {axios, emoji, fetch, fs, git, jimp, minimatch, opengraph, os, paths, processes, rss, url, util}
/**Returns module __dirname */
export function __module(module) {
@@ -81,7 +81,7 @@ export function formatters({timeZone} = {}) {
}
/**Bytes formatter */
format.bytes = function (n) {
format.bytes = function(n) {
for (const {u, v} of [{u:"E", v:10 ** 18}, {u:"P", v:10 ** 15}, {u:"T", v:10 ** 12}, {u:"G", v:10 ** 9}, {u:"M", v:10 ** 6}, {u:"k", v:10 ** 3}]) {
if (n / v >= 1)
return `${(n / v).toFixed(2).substr(0, 4).replace(/[.]0*$/, "")} ${u}B`
@@ -90,7 +90,7 @@ export function formatters({timeZone} = {}) {
}
/**Percentage formatter */
format.percentage = function (n, {rescale = true} = {}) {
format.percentage = function(n, {rescale = true} = {}) {
return `${
(n * (rescale ? 100 : 1)).toFixed(2)
.replace(/(?<=[.])(?<decimal>[1-9]*)0+$/, "$<decimal>")
@@ -166,7 +166,7 @@ export async function chartist() {
}
/**Language analyzer (single file) */
export async function language({filename, patch, prefix = "", timeout = 20*1000}) {
export async function language({filename, patch, prefix = "", timeout = 20 * 1000}) {
const path = paths.join(os.tmpdir(), `${prefix}-${Math.random()}`.replace(/[^\w-]/g, ""))
return new Promise(async (solve, reject) => {
setTimeout(() => {
@@ -222,9 +222,9 @@ export async function run(command, options, {prefixed = true, log = true} = {})
}
/**Spawn command (use this to execute commands and process output on the fly) */
export async function spawn(command, args = [], options = {}, {prefixed = true, timeout = 300*1000, stdout} = {}) { //eslint-disable-line max-params
export async function spawn(command, args = [], options = {}, {prefixed = true, timeout = 300 * 1000, stdout} = {}) { //eslint-disable-line max-params
const prefix = {win32:"wsl"}[process.platform] ?? ""
if ((prefixed)&&(prefix)) {
if ((prefixed) && (prefix)) {
args.unshift(command)
command = prefix
}
@@ -403,7 +403,7 @@ export const svg = {
if (Number.isFinite(Number(absolute)))
padding.absolute[dimension] = Number(absolute)
if (Number.isFinite(Number(relative)))
padding[dimension] = 1 + Number(relative/100)
padding[dimension] = 1 + Number(relative / 100)
}
console.debug(`metrics/svg/resize > padding width*${padding.width}+${padding.absolute.width}, height*${padding.height}+${padding.absolute.height}`)
//Render through browser and resize height
@@ -433,7 +433,7 @@ export const svg = {
console.debug(`bounds after applying padding width=${width} (*${padding.width}+${padding.absolute.width}), height=${height} (*${padding.height}+${padding.absolute.height})`)
//Resize svg
if (document.querySelector("svg").getAttribute("height") === "auto")
console.debug("skipped height resizing because it was set to \"auto\"")
console.debug('skipped height resizing because it was set to "auto"')
else
document.querySelector("svg").setAttribute("height", height)
//Enable animations
@@ -575,8 +575,8 @@ export const svg = {
if (error)
throw new Error(`Could not optimize SVG: \n${error}`)
return optimized
}
}
},
},
}
/**Wait */