Secondary-dev Next UI with DnD, labels, stopwatch, archive, activity; pads with revisions; README documents pnpm dev:work-api. Co-authored-by: Cursor <cursoragent@cursor.com>
63 lines
2.1 KiB
JavaScript
63 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Flatten Planka CSS-module SCSS for Next/Turbopack:
|
|
* - unwrap `:global(#app) { ... }` → top-level local classes
|
|
* - remove nested `:global { .x }` blocks (third-party hooks → separate global sheet)
|
|
*/
|
|
import { readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
|
|
import { join, dirname } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const vendor = join(
|
|
dirname(fileURLToPath(import.meta.url)),
|
|
"../../../src/modules/work/planka/vendor",
|
|
);
|
|
|
|
function walk(dir, out = []) {
|
|
for (const name of readdirSync(dir)) {
|
|
const p = join(dir, name);
|
|
const st = statSync(p);
|
|
if (st.isDirectory()) walk(p, out);
|
|
else if (name.endsWith(".module.scss")) out.push(p);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function flatten(src) {
|
|
let s = src;
|
|
// Drop nested `:global { ... }` blocks (non-greedy multi-line)
|
|
s = s.replace(/\n\s*:global\s*\{[\s\S]*?\n\s*\}/g, "\n");
|
|
// Unwrap `:global(#app) { ... file ... }` — keep inner content, dedent one level
|
|
if (/:global\(#app\)\s*\{/.test(s)) {
|
|
s = s.replace(/:global\(#app\)\s*\{/, "");
|
|
// remove final closing brace of the wrapper if file ends with it
|
|
const idx = s.lastIndexOf("}");
|
|
if (idx !== -1) {
|
|
const after = s.slice(idx + 1).trim();
|
|
if (!after) s = s.slice(0, idx);
|
|
}
|
|
// crude dedent: lines that start with two spaces lose them once
|
|
s = s
|
|
.split("\n")
|
|
.map((line) => (line.startsWith(" ") ? line.slice(2) : line))
|
|
.join("\n");
|
|
}
|
|
// Top-level bare `:global { #app {` in styles.module.scss — convert to plain #app
|
|
s = s.replace(/^:global\s*\{\s*\n\s*#app\s*\{/m, "#planka-next-root, #app {");
|
|
// If we opened #app block from :global, ensure we don't leave an extra closing from :global
|
|
// (styles.module.scss ends with two closing braces)
|
|
return s;
|
|
}
|
|
|
|
const files = walk(vendor);
|
|
let n = 0;
|
|
for (const f of files) {
|
|
const before = readFileSync(f, "utf8");
|
|
const after = flatten(before);
|
|
if (after !== before) {
|
|
writeFileSync(f, after, "utf8");
|
|
n++;
|
|
}
|
|
}
|
|
console.log(`flattened ${n}/${files.length} module.scss files`);
|