Skip to content

Commit 33a2f43

Browse files
authored
fix(ci): vercel (lowlighter#1125)
1 parent 1713f5e commit 33a2f43

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

.github/scripts/preview.mjs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ fs.copyFile(paths.join(__web, "style.vars.css"), paths.join(__preview_css, "styl
5656
fs.copyFile(paths.join(__node_modules, "prismjs/themes/prism-tomorrow.css"), paths.join(__preview_css, "style.prism.css"))
5757
//Scripts
5858
fs.writeFile(paths.join(__preview_js, "app.js"), `${await fs.readFile(paths.join(__web, "app.js"))}`)
59-
fs.writeFile(paths.join(__preview_js, "app.placeholder.js"), `${await fs.readFile(paths.join(__web, "app.placeholder.js"))}`)
6059
fs.copyFile(paths.join(__node_modules, "ejs/ejs.min.js"), paths.join(__preview_js, "ejs.min.js"))
6160
fs.writeFile(paths.join(__preview_js, "faker.min.js"), "import {faker} from '/.js/faker/index.mjs';globalThis.faker=faker;globalThis.placeholder.init(globalThis)")
6261
for (const path of [[], ["locale"]]) {
@@ -76,15 +75,31 @@ fs.copyFile(paths.join(__node_modules, "prismjs/components/prism-yaml.min.js"),
7675
fs.copyFile(paths.join(__node_modules, "prismjs/components/prism-markdown.min.js"), paths.join(__preview_js, "prism.markdown.min.js"))
7776
fs.copyFile(paths.join(__node_modules, "clipboard/dist/clipboard.min.js"), paths.join(__preview_js, "clipboard.min.js"))
7877
//Meta
78+
fs.writeFile(paths.join(__preview, ".modes"), JSON.stringify(["embed", "insights"]))
7979
fs.writeFile(paths.join(__preview, ".version"), JSON.stringify(`${conf.package.version}-preview`))
8080
fs.writeFile(paths.join(__preview, ".hosted"), JSON.stringify({by: "metrics", link: "https://github.com/lowlighter/metrics"}))
81+
//Embed
82+
{
83+
const __web_embed = paths.join(paths.join(__web, "embed"))
84+
const __web_embed_placeholders = paths.join(__web_embed, "placeholders")
85+
const __preview_embed = paths.join(__preview, "embed")
86+
const __preview_embed_placeholders = paths.join(__preview, ".placeholders")
87+
const __preview_embed_js = paths.join(__preview_js, "embed")
88+
await fs.mkdir(__preview_embed, {recursive: true})
89+
await fs.mkdir(__preview_embed_placeholders, {recursive: true})
90+
await fs.mkdir(__preview_embed_js, {recursive: true})
91+
fs.writeFile(paths.join(__preview_embed, "index.html"), `${await fs.readFile(paths.join(__web_embed, "index.html"))}`)
92+
fs.writeFile(paths.join(__preview_embed_js, "app.js"), `${await fs.readFile(paths.join(__web_embed, "app.js"))}`)
93+
fs.writeFile(paths.join(__preview_embed_js, "app.placeholder.js"), `${await fs.readFile(paths.join(__web_embed, "app.placeholder.js"))}`)
94+
for (const file of await fs.readdir(__web_embed_placeholders))
95+
fs.copyFile(paths.join(__web_embed_placeholders, file), paths.join(__preview_embed_placeholders, file))
96+
}
8197
//Insights
82-
for (const insight of ["insights", "about"]) {
83-
const __web_insights = paths.join(paths.join(__web, insight))
84-
const __preview_insights = paths.join(__preview, `${insight}/.statics`)
98+
for (const insights of ["insights", "about"]) {
99+
const __web_insights = paths.join(paths.join(__web, "insights"))
100+
const __preview_insights = paths.join(__preview, `${insights}/.statics`)
85101
await fs.mkdir(__preview_insights, {recursive: true})
86-
87-
fs.copyFile(paths.join(__web, insight, "index.html"), paths.join(__preview, insight, "index.html"))
102+
fs.copyFile(paths.join(__web_insights, "index.html"), paths.join(__preview, insights, "index.html"))
88103
for (const file of await fs.readdir(__web_insights)) {
89104
if (file !== ".statics")
90105
fs.copyFile(paths.join(__web_insights, file), paths.join(__preview_insights, file))

source/app/metrics/metadata.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
224224
console.debug(`metrics/extras > ${name} > ${key} > require [${required}]`)
225225

226226
//Legacy handling
227-
const enabled = extras?.features ?? extras?.default ?? false
227+
const enabled = extras?.features ?? extras?.default ?? (typeof extras === "boolean" ? extras : false)
228228
if (typeof enabled === "boolean") {
229229
console.debug(`metrics/extras > ${name} > ${key} > extras features is set to ${enabled}`)
230230
if (!enabled)

source/app/web/statics/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h2>
6565
<div class="search">
6666
<div class="about">
6767
<small class="warning mb1" v-if="preview">
68-
Metrics insights are rendered by <a href="https://metrics.lecoq.io/">metrics.lecoq.io</a> in preview mode.<br>
68+
Metrics are rendered by <a href="https://metrics.lecoq.io/">metrics.lecoq.io</a> in preview mode.<br>
6969
Any backend editions won't be reflected but client-side rendering can still be tested.
7070
</small>
7171
<div class="warning mb1" v-if="(!requests.rest.remaining)||(!requests.graphql.remaining)">

source/plugins/core/index.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ export default async function({login, q}, {conf, data, rest, graphql, plugins, q
5353
data.animated = animations
5454
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)
5555

56+
//Extras features
57+
const extras = conf.settings?.extras?.features ?? conf.settings?.extras?.default ?? false
58+
console.debug(`metrics/compute/${login} > extras > ${JSON.stringify(extras)}`)
59+
5660
//Plugins
5761
for (const name of Object.keys(imports.plugins)) {
5862
if ((!plugins[name]?.enabled) || (!q[name]))
5963
continue
6064
pending.push((async () => {
6165
try {
6266
console.debug(`metrics/compute/${login}/plugins > ${name} > started`)
63-
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]})
67+
data.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql, queries, account}, {extras, sandbox: conf.settings?.sandbox ?? false, ...plugins[name]})
6468
console.debug(`metrics/compute/${login}/plugins > ${name} > completed`)
6569
}
6670
catch (error) {

tests/metrics.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ web.start = async () =>
4040
web.stop = async () => await web.instance.kill("SIGKILL")
4141

4242
//Web instance placeholder
43-
require("./../source/app/web/statics/app.placeholder.js")
43+
require("./../source/app/web/statics/embed/app.placeholder.js")
4444
const placeholder = globalThis.placeholder
4545
delete globalThis.placeholder
4646
placeholder.init({
@@ -119,7 +119,7 @@ describe("GitHub Action", () =>
119119
if ((skip.includes(template)) || ((modes.length) && (!modes.includes("action"))))
120120
test.skip(name, () => null)
121121
else
122-
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)
122+
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)
123123
}
124124
}))
125125

vercel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
{"source": "/:login([-\\w]+)/:repository([-\\w]+)", "destination": "https://metrics.lecoq.io/:login/:repository"},
77
{"source": "/about/query/:login", "destination": "https://metrics.lecoq.io/about/query/:login"},
88
{"source": "/about/query/:login/:plugin", "destination": "https://metrics.lecoq.io/about/query/:login/:plugin"},
9-
{"source": "/insights/query/:login", "destination": "https://metrics.lecoq.io/insights/query/:login"},
10-
{"source": "/insights/query/:login/:plugin", "destination": "https://metrics.lecoq.io/insights/query/:login/:plugin"},
9+
{"source": "/insights/query/:login", "destination": "https://metrics.lecoq.io/about/query/:login"},
10+
{"source": "/insights/query/:login/:plugin", "destination": "https://metrics.lecoq.io/about/query/:login/:plugin"},
1111
{"source": "/.uncache", "destination": "https://metrics.lecoq.io/.uncache"},
1212
{"source": "/.requests", "destination": "https://metrics.lecoq.io/.requests"}
1313
],

0 commit comments

Comments
 (0)