@panomc/theme-core 1.0.0-dev.42 → 1.0.0-dev.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sync.js +64 -0
- package/package.json +1 -1
package/bin/sync.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, statSync, rmSync } from "node:fs";
|
|
17
17
|
import { join, dirname } from "node:path";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { createRequire } from "node:module";
|
|
19
20
|
|
|
20
21
|
const EJECT_MARKER = "@theme-core-eject";
|
|
21
22
|
const HEADER_JS = "// AUTO-GENERATED by theme-core sync — do not edit.\n// To take ownership of this file, add an eject comment (see theme-core docs).\n";
|
|
@@ -266,9 +267,71 @@ function syncLang() {
|
|
|
266
267
|
);
|
|
267
268
|
merged++;
|
|
268
269
|
}
|
|
270
|
+
|
|
271
|
+
// Extra locales: an override file with no matching core base (e.g. de.json)
|
|
272
|
+
// becomes a NEW language. Its base is core en-US, so untranslated keys fall
|
|
273
|
+
// back to English instead of rendering as raw keys. The locale only shows up
|
|
274
|
+
// on the site if an admin has defined a locale with the same code in the
|
|
275
|
+
// panel — the theme file alone doesn't add it to the language picker.
|
|
276
|
+
if (existsSync(overrideDir)) {
|
|
277
|
+
const enBase = JSON.parse(readFileSync(join(coreLangDir, "en-US.json"), "utf-8"));
|
|
278
|
+
for (const file of readdirSync(overrideDir)) {
|
|
279
|
+
if (!file.endsWith(".json") || existsSync(join(coreLangDir, file))) continue;
|
|
280
|
+
const overlay = JSON.parse(readFileSync(join(overrideDir, file), "utf-8"));
|
|
281
|
+
writeFileSync(
|
|
282
|
+
join(outDir, file),
|
|
283
|
+
JSON.stringify(deepMerge(enBase, overlay), null, 2) + "\n",
|
|
284
|
+
);
|
|
285
|
+
merged++;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
269
288
|
return merged;
|
|
270
289
|
}
|
|
271
290
|
|
|
291
|
+
/**
|
|
292
|
+
* tokens.scss backfill: `new` scaffolds before dependencies exist, so its
|
|
293
|
+
* commented token menu can't be generated then (the file carries a placeholder
|
|
294
|
+
* marker instead). Once @panomc/sdk is installed, fill the menu in. Only the
|
|
295
|
+
* placeholder is ever replaced — a tokens.scss the author touched is theirs.
|
|
296
|
+
*/
|
|
297
|
+
function backfillTokens() {
|
|
298
|
+
const TOKENS_PLACEHOLDER = "(token list unavailable at scaffold time";
|
|
299
|
+
const tokensPath = join(process.cwd(), "src", "styles", "tokens.scss");
|
|
300
|
+
if (!existsSync(tokensPath)) return;
|
|
301
|
+
const current = readFileSync(tokensPath, "utf-8");
|
|
302
|
+
if (!current.includes(TOKENS_PLACEHOLDER)) return;
|
|
303
|
+
let sdkDir;
|
|
304
|
+
try {
|
|
305
|
+
sdkDir = dirname(createRequire(join(process.cwd(), "package.json")).resolve("@panomc/sdk/package.json"));
|
|
306
|
+
} catch {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const lines = [];
|
|
310
|
+
for (const [file, label] of [
|
|
311
|
+
["core/scss/custom-bootstrap.scss", "Colors, radius, typography (Bootstrap layer)"],
|
|
312
|
+
["core/scss/themes.scss", "Named dark themes"],
|
|
313
|
+
]) {
|
|
314
|
+
const src = readFileSync(join(sdkDir, file), "utf-8");
|
|
315
|
+
const vars = [...src.matchAll(/^\$([\w-]+)\s*:\s*([^;]*?)\s*!default;/gm)]
|
|
316
|
+
.filter(([, , value]) => !value.includes("\n"));
|
|
317
|
+
if (vars.length) {
|
|
318
|
+
lines.push(`// ── ${label} ${"─".repeat(Math.max(3, 46 - label.length))}`);
|
|
319
|
+
for (const [, varName, value] of vars) lines.push(`// $${varName}: ${value};`);
|
|
320
|
+
lines.push("");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (!lines.length) return;
|
|
324
|
+
const start = current.indexOf("// " + TOKENS_PLACEHOLDER);
|
|
325
|
+
const endMarker = "for every variable)";
|
|
326
|
+
const end = current.indexOf(endMarker, start);
|
|
327
|
+
if (start === -1 || end === -1) return;
|
|
328
|
+
writeFileSync(
|
|
329
|
+
tokensPath,
|
|
330
|
+
current.slice(0, start) + lines.join("\n") + current.slice(end + endMarker.length + 1),
|
|
331
|
+
);
|
|
332
|
+
console.log("theme-core sync: filled in the token menu in src/styles/tokens.scss");
|
|
333
|
+
}
|
|
334
|
+
|
|
272
335
|
const routesDir = join(process.cwd(), "src", "routes");
|
|
273
336
|
let written = 0;
|
|
274
337
|
let ejected = 0;
|
|
@@ -320,6 +383,7 @@ function sweep(dir) {
|
|
|
320
383
|
sweep(routesDir);
|
|
321
384
|
|
|
322
385
|
const langMerged = syncLang();
|
|
386
|
+
backfillTokens();
|
|
323
387
|
|
|
324
388
|
console.log(
|
|
325
389
|
`theme-core sync: ${written} shims written, ${ejected} ejected (kept), ${removed} stale removed, ${langMerged} lang files merged`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panomc/theme-core",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.44",
|
|
4
4
|
"description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
|
|
5
5
|
"author": "PanoMC",
|
|
6
6
|
"license": "MIT",
|