-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscope-css-variables.js
More file actions
44 lines (34 loc) · 1.33 KB
/
scope-css-variables.js
File metadata and controls
44 lines (34 loc) · 1.33 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
44
#!/usr/bin/env node
/**
* Script to scope CSS selectors to .ledger-wallet-provider
* This prevents CSS variables and global styles from leaking into host applications
*/
import { readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
// Import the scoping function
// Use dynamic import to handle both compiled (dist) and source (src) locations
const __dirname = dirname(fileURLToPath(import.meta.url));
async function loadScopeCssFunction() {
// Import from source TypeScript file (tsx will handle compilation)
const module = await import("./src/utils/scope-css.ts");
return module.scopeCssSelectors;
}
// Get the CSS file path from command line args or use default
const cssFile = process.argv[2] || join(__dirname, "dist", "styles.css");
(async () => {
try {
// Load the scoping function
const scopeCssSelectors = await loadScopeCssFunction();
// Read the CSS file
const css = readFileSync(cssFile, "utf8");
// Scope all CSS selectors
const scopedCss = scopeCssSelectors(css);
// Write the modified CSS back
writeFileSync(cssFile, scopedCss, "utf8");
console.log(`✓ Scoped CSS variables and global styles in ${cssFile}`);
} catch (error) {
console.error(`Error processing CSS file: ${error.message}`);
process.exit(1);
}
})();