Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions .github/scripts/preview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ fs.copyFile(paths.join(__web, "style.vars.css"), paths.join(__preview_css, "styl
fs.copyFile(paths.join(__node_modules, "prismjs/themes/prism-tomorrow.css"), paths.join(__preview_css, "style.prism.css"))
//Scripts
fs.writeFile(paths.join(__preview_js, "app.js"), `${await fs.readFile(paths.join(__web, "app.js"))}`)
fs.writeFile(paths.join(__preview_js, "app.placeholder.js"), `${await fs.readFile(paths.join(__web, "app.placeholder.js"))}`)
fs.copyFile(paths.join(__node_modules, "ejs/ejs.min.js"), paths.join(__preview_js, "ejs.min.js"))
fs.writeFile(paths.join(__preview_js, "faker.min.js"), "import {faker} from '/.js/faker/index.mjs';globalThis.faker=faker;globalThis.placeholder.init(globalThis)")
for (const path of [[], ["locale"]]) {
Expand All @@ -76,15 +75,31 @@ fs.copyFile(paths.join(__node_modules, "prismjs/components/prism-yaml.min.js"),
fs.copyFile(paths.join(__node_modules, "prismjs/components/prism-markdown.min.js"), paths.join(__preview_js, "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, ".modes"), JSON.stringify(["embed", "insights"]))
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"}))
//Embed
{
const __web_embed = paths.join(paths.join(__web, "embed"))
const __web_embed_placeholders = paths.join(__web_embed, "placeholders")
const __preview_embed = paths.join(__preview, "embed")
const __preview_embed_placeholders = paths.join(__preview, ".placeholders")
const __preview_embed_js = paths.join(__preview_js, "embed")
await fs.mkdir(__preview_embed, {recursive: true})
await fs.mkdir(__preview_embed_placeholders, {recursive: true})
await fs.mkdir(__preview_embed_js, {recursive: true})
fs.writeFile(paths.join(__preview_embed, "index.html"), `${await fs.readFile(paths.join(__web_embed, "index.html"))}`)
fs.writeFile(paths.join(__preview_embed_js, "app.js"), `${await fs.readFile(paths.join(__web_embed, "app.js"))}`)
fs.writeFile(paths.join(__preview_embed_js, "app.placeholder.js"), `${await fs.readFile(paths.join(__web_embed, "app.placeholder.js"))}`)
for (const file of await fs.readdir(__web_embed_placeholders))
fs.copyFile(paths.join(__web_embed_placeholders, file), paths.join(__preview_embed_placeholders, file))
}
//Insights
for (const insight of ["insights", "about"]) {
const __web_insights = paths.join(paths.join(__web, insight))
const __preview_insights = paths.join(__preview, `${insight}/.statics`)
for (const insights of ["insights", "about"]) {
const __web_insights = paths.join(paths.join(__web, "insights"))
const __preview_insights = paths.join(__preview, `${insights}/.statics`)
await fs.mkdir(__preview_insights, {recursive: true})

fs.copyFile(paths.join(__web, insight, "index.html"), paths.join(__preview, insight, "index.html"))
fs.copyFile(paths.join(__web_insights, "index.html"), paths.join(__preview, insights, "index.html"))
for (const file of await fs.readdir(__web_insights)) {
if (file !== ".statics")
fs.copyFile(paths.join(__web_insights, file), paths.join(__preview_insights, file))
Expand Down
2 changes: 1 addition & 1 deletion source/app/metrics/metadata.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
console.debug(`metrics/extras > ${name} > ${key} > require [${required}]`)

//Legacy handling
const enabled = extras?.features ?? extras?.default ?? false
const enabled = extras?.features ?? extras?.default ?? (typeof extras === "boolean" ? extras : false)
if (typeof enabled === "boolean") {
console.debug(`metrics/extras > ${name} > ${key} > extras features is set to ${enabled}`)
if (!enabled)
Expand Down
2 changes: 1 addition & 1 deletion source/app/web/statics/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h2>
<div class="search">
<div class="about">
<small class="warning mb1" v-if="preview">
Metrics insights are rendered by <a href="https://metrics.lecoq.io/">metrics.lecoq.io</a> in preview mode.<br>
Metrics are rendered by <a href="https://metrics.lecoq.io/">metrics.lecoq.io</a> in preview mode.<br>
Any backend editions won't be reflected but client-side rendering can still be tested.
</small>
<div class="warning mb1" v-if="(!requests.rest.remaining)||(!requests.graphql.remaining)">
Expand Down
6 changes: 5 additions & 1 deletion source/plugins/core/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ export default async function({login, q}, {conf, data, rest, graphql, plugins, q
data.animated = animations
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)

//Extras features
const extras = conf.settings?.extras?.features ?? conf.settings?.extras?.default ?? false
console.debug(`metrics/compute/${login} > extras > ${JSON.stringify(extras)}`)

//Plugins
for (const name of Object.keys(imports.plugins)) {
if ((!plugins[name]?.enabled) || (!q[name]))
continue
pending.push((async () => {
try {
console.debug(`metrics/compute/${login}/plugins > ${name} > started`)
data.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql, queries, account}, {extras: conf.settings?.extras?.features ?? conf.settings?.extras?.default ?? false, sandbox: conf.settings?.sandbox ?? false, ...plugins[name]})
data.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql, queries, account}, {extras, sandbox: conf.settings?.sandbox ?? false, ...plugins[name]})
console.debug(`metrics/compute/${login}/plugins > ${name} > completed`)
}
catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions tests/metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ web.start = async () =>
web.stop = async () => await web.instance.kill("SIGKILL")

//Web instance placeholder
require("./../source/app/web/statics/app.placeholder.js")
require("./../source/app/web/statics/embed/app.placeholder.js")
const placeholder = globalThis.placeholder
delete globalThis.placeholder
placeholder.init({
Expand Down Expand Up @@ -119,7 +119,7 @@ describe("GitHub Action", () =>
if ((skip.includes(template)) || ((modes.length) && (!modes.includes("action"))))
test.skip(name, () => null)
else
test(name, async () => expect(await action.run({template, base: "", query: JSON.stringify(query), plugins_errors_fatal: true, dryrun: true, use_mocked_data: true, verify: true, ...input})).toBe(true), timeout)
test(name, async () => expect(await action.run({template, base: "", query: JSON.stringify(query), plugins_errors_fatal: true, dryrun: true, use_mocked_data: true, verify: true, retries:1, ...input})).toBe(true), timeout)
}
}))

Expand Down
4 changes: 2 additions & 2 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{"source": "/:login([-\\w]+)/:repository([-\\w]+)", "destination": "https://metrics.lecoq.io/:login/:repository"},
{"source": "/about/query/:login", "destination": "https://metrics.lecoq.io/about/query/:login"},
{"source": "/about/query/:login/:plugin", "destination": "https://metrics.lecoq.io/about/query/:login/:plugin"},
{"source": "/insights/query/:login", "destination": "https://metrics.lecoq.io/insights/query/:login"},
{"source": "/insights/query/:login/:plugin", "destination": "https://metrics.lecoq.io/insights/query/:login/:plugin"},
{"source": "/insights/query/:login", "destination": "https://metrics.lecoq.io/about/query/:login"},
{"source": "/insights/query/:login/:plugin", "destination": "https://metrics.lecoq.io/about/query/:login/:plugin"},
{"source": "/.uncache", "destination": "https://metrics.lecoq.io/.uncache"},
{"source": "/.requests", "destination": "https://metrics.lecoq.io/.requests"}
],
Expand Down