Lou·Ka — tous les logements à louer du Québec, un seul endroit.
HTML 98.9%
Python 0.6%
1#!/usr/bin/env node2// -----------------------------------------------------------------------------3// Lou-Ka — kit Figma · build.mjs4// Assemble plugin/code.js = `var REFS = [...]` (captures + photos réduites,5// base64) + plugin/src/code.js. À relancer après shots.mjs ou toute édition6// de plugin/src/code.js.7// -----------------------------------------------------------------------------8import { readFileSync, writeFileSync, readdirSync, mkdirSync, existsSync, statSync } from "node:fs";9import { execSync } from "node:child_process";10import path from "node:path";1112const ROOT = new URL(".", import.meta.url).pathname;13const REF = path.join(ROOT, "references");14const TMP = path.join(ROOT, "plugin", ".embed");15mkdirSync(TMP, { recursive: true });1617function dims(file) {18 const out = execSync(`sips -g pixelWidth -g pixelHeight "${file}"`).toString();19 return { w: +out.match(/pixelWidth: (\d+)/)[1], h: +out.match(/pixelHeight: (\d+)/)[1] };20}21/** Réduit une image (largeur max + qualité JPEG) dans .embed/ et renvoie l'entrée REFS. */22function embed(file, kind, maxW, quality) {23 const out = path.join(TMP, `${kind}-${path.basename(file)}`);24 execSync(`sips -s format jpeg -s formatOptions ${quality} -Z ${maxW} "${file}" --out "${out}" >/dev/null 2>&1`);25 const { w, h } = dims(out);26 return { name: path.basename(file, ".jpg"), kind, w, h, b64: readFileSync(out).toString("base64") };27}2829const refs = [];30const fold = path.join(REF, "fold");31if (existsSync(fold)) for (const f of readdirSync(fold).filter((f) => f.endsWith(".jpg")).sort()) {32 refs.push(embed(path.join(fold, f), "shot", f.startsWith("desktop") ? 1440 : 780, 72));33}34const photos = path.join(REF, "photos");35if (existsSync(photos)) for (const f of readdirSync(photos).filter((f) => /^photo-\d+\.jpg$/.test(f)).sort()) {36 refs.push(embed(path.join(photos, f), "photo", 560, 74));37}3839const src = readFileSync(path.join(ROOT, "plugin/src/code.js"), "utf8");40const header = `// GÉNÉRÉ par build.mjs le ${new Date().toISOString()} — ne pas éditer : modifier plugin/src/code.js\n`;41const out = `${header}var REFS = ${JSON.stringify(refs)};\n${src}`;42writeFileSync(path.join(ROOT, "plugin/code.js"), out);4344const kb = (n) => `${(n / 1024).toFixed(0)} Ko`;45console.log(`plugin/code.js écrit : ${kb(statSync(path.join(ROOT, "plugin/code.js")).size)} — ${refs.filter((r) => r.kind === "shot").length} captures, ${refs.filter((r) => r.kind === "photo").length} photos embarquées`);46for (const r of refs) console.log(` · ${r.kind.padEnd(5)} ${r.name.padEnd(22)} ${r.w}×${r.h} ${kb(r.b64.length * 0.75)}`);47