@panomc/theme-core 1.0.0-dev.43 → 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 +46 -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";
|
|
@@ -287,6 +288,50 @@ function syncLang() {
|
|
|
287
288
|
return merged;
|
|
288
289
|
}
|
|
289
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
|
+
|
|
290
335
|
const routesDir = join(process.cwd(), "src", "routes");
|
|
291
336
|
let written = 0;
|
|
292
337
|
let ejected = 0;
|
|
@@ -338,6 +383,7 @@ function sweep(dir) {
|
|
|
338
383
|
sweep(routesDir);
|
|
339
384
|
|
|
340
385
|
const langMerged = syncLang();
|
|
386
|
+
backfillTokens();
|
|
341
387
|
|
|
342
388
|
console.log(
|
|
343
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",
|