-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathupdate-styles-json.js
47 lines (38 loc) · 1.36 KB
/
update-styles-json.js
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
45
46
47
const fs = require('fs');
const path = require('path');
const rootDir = path.join(__dirname, 'websites');
const outputFile = path.join(__dirname, 'styles.json');
const excludeFile = 'userChrome.css';
// Check if the output file exists and create it if it doesn't
if (!fs.existsSync(outputFile)) {
fs.writeFileSync(outputFile, JSON.stringify({ website: {} }, null, 2));
}
function updateStylesJson() {
const styles = JSON.parse(fs.readFileSync(outputFile, 'utf-8')) || { website: {} };
fs.readdirSync(rootDir).forEach(file => {
if (file.endsWith('.css') && file !== excludeFile) {
const content = fs.readFileSync(path.join(rootDir, file), 'utf-8');
const parts = content.split(/\/\* (.*?) \*\//);
let isValid = true;
const features = {};
for (let index = 1; index < parts.length; index += 2) {
const feature = parts[index]?.trim();
const cssCode = parts[index + 1]?.trim();
if (feature && cssCode) {
try {
JSON.stringify({ [feature]: cssCode });
features[feature] = cssCode;
} catch (e) {
isValid = false;
break;
}
}
}
if (isValid && Object.keys(features).length > 0) {
styles.website[file] = features;
}
}
});
fs.writeFileSync(outputFile, JSON.stringify(styles, null, 2));
}
updateStylesJson();