-
Notifications
You must be signed in to change notification settings - Fork 43
/
css-property-order-fix.js
56 lines (43 loc) · 1.49 KB
/
css-property-order-fix.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
48
49
50
51
52
53
54
55
const fs = require('fs');
const path = require('path');
function parseCSS(cssContent) {
// Implement your CSS parsing logic here
// You can use regular expressions, string manipulation, or a CSS parsing library
// Example: Simple parsing using regular expressions to extract CSS rules
const cssRules = [];
const ruleRegex = /(.+?)\s*{\s*(.*?)\s*}/gs;
let match;
while ((match = ruleRegex.exec(cssContent)) !== null) {
const selector = match[1].trim();
const declarations = match[2].split(';').map((declaration) => {
const parts = declaration.split(':').map((part) => part.trim());
return {
property: parts[0],
value: parts[1],
};
});
cssRules.push({
selector,
declarations: declarations
.sort((a, b) => a.property.localeCompare(b.property))
.filter((declaration) => declaration.property !== ''),
});
}
return cssRules;
}
const cssFile = fs.readFileSync(
path.join('.', 'static', 'styles', 'clean-jsdoc-theme-light.css')
);
const parsed = parseCSS(cssFile);
let output = '';
for (const parse of parsed) {
output += `${parse.selector} {\n`;
for (const declaration of parse.declarations) {
output += `\t${declaration.property}: ${declaration.value};\n`;
}
output += '\n}\n\n';
}
fs.writeFileSync(
path.join('.', 'static', 'styles', 'clean-jsdoc-theme-list.update.css'),
output
);