-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathextract-css.sh
More file actions
executable file
·43 lines (31 loc) · 1.03 KB
/
Copy pathextract-css.sh
File metadata and controls
executable file
·43 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
node - <<'EOF'
const fs = require('fs');
const vm = require('vm');
const OUTPUT_PREFIX="rect"
const filePath = "rect.js";
let content = fs.readFileSync(filePath, "utf-8");
// Remove the ES module `export` so we can evaluate as CommonJS
content = content.replace(/export\s+const\s+RECT/, 'const RECT');
const sandbox = {};
try {
// Evaluate the JS code in a safe, isolated context
vm.runInNewContext(content, sandbox);
if (!Array.isArray(sandbox.RECT)) {
console.error("❌ RECT is not defined as an array.");
console.log("🔍 Sandbox keys:", Object.keys(sandbox));
process.exit(1);
}
sandbox.RECT.forEach((item, index) => {
const css = item.css?.trim();
if (!css) return;
const nameNumber = index + 1 > 9 ? index + 1 : `0${index + 1}`;
const fileName = `${OUTPUT_PREFIX}${nameNumber}.module.css`;
fs.writeFileSync(fileName, css + "\n");
console.log(`✅ Generated: ${fileName}`);
});
} catch (err) {
console.error("❌ JS Evaluation Error:", err.message);
process.exit(1);
}
EOF