Added a badge to display the monthly ramp

This commit is contained in:
2026-09-23 23:24:31 -03:00
parent 3ef0d2aafd
commit b92d75f558
11 changed files with 229 additions and 21 deletions

View File

@@ -1,7 +1,8 @@
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { mkdir, readFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import composition from "./compose.cjs";
import output from "./write-output.cjs";
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const distDir = path.join(rootDir, "dist");
@@ -61,10 +62,6 @@ const targets = [
}
];
if (!checkOnly) {
await rm(distDir, { recursive: true, force: true });
}
for (const target of targets) {
const manifestJson = `${JSON.stringify(target.manifest, null, 2)}\n`;
JSON.parse(manifestJson);
@@ -80,9 +77,9 @@ for (const target of targets) {
const outputDir = path.join(distDir, target.name);
await mkdir(outputDir, { recursive: true });
await writeFile(path.join(outputDir, "manifest.json"), manifestJson);
await writeFile(path.join(outputDir, "content.js"), contentScript);
await writeFile(path.join(outputDir, "background.js"), backgroundScript);
await output.writeOutput(path.join(outputDir, "content.js"), contentScript);
await output.writeOutput(path.join(outputDir, "background.js"), backgroundScript);
await output.writeOutput(path.join(outputDir, "manifest.json"), manifestJson);
}
if (!checkOnly) {

20
scripts/write-output.cjs Normal file
View File

@@ -0,0 +1,20 @@
const fs = require("node:fs/promises");
const { randomUUID } = require("node:crypto");
async function writeOutput(file, contents, io = fs) {
try {
if (await io.readFile(file, "utf8") === contents) return;
} catch (error) {
if (error.code !== "ENOENT") throw error;
}
// Replace a complete file; never remove or truncate a script the browser may load.
const temporary = `${file}.${randomUUID()}.tmp`;
try {
await io.writeFile(temporary, contents, { encoding: "utf8", flag: "wx" });
await io.rename(temporary, file);
} finally {
await io.rm(temporary, { force: true });
}
}
module.exports = { writeOutput };