Skip to content

Commit 92a2e3f

Browse files
authored
feat: add IntelliJ auto-complete support for Lumo theme (#4935)
1 parent 59dab62 commit 92a2e3f

4 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ packages/icons/test/visual/screenshots/failed
1818
# Generated web-types JSON files
1919
web-types.json
2020
web-types.lit.json
21+
22+
# Generated auto-complete CSS file for Lumo theme
23+
packages/vaadin-lumo-styles/auto-complete.css

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"author": "Vaadin Ltd",
55
"scripts": {
6-
"analyze": "polymer analyze packages/**/vaadin-*.js > analysis.json && node scripts/prepareDocs.js && node scripts/buildWebtypes.js",
6+
"analyze": "polymer analyze packages/**/vaadin-*.js > analysis.json && node scripts/prepareDocs.js && node scripts/buildWebtypes.js && node scripts/generateLumoAutoCompleteCss.js",
77
"debug": "web-test-runner --watch",
88
"debug:it": "web-test-runner --watch --config web-test-runner-it.config.js",
99
"dist": "rimraf dist && yarn analyze && rollup -c rollup.config.js && cp analysis.json dist",

‎packages/vaadin-lumo-styles/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"files": [
2626
"*.d.ts",
2727
"*.js",
28+
"auto-complete.css",
2829
"mixins/*.d.ts",
2930
"mixins/*.js",
3031
"presets/*.js",
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const PACKAGE_BASE = 'packages/vaadin-lumo-styles';
5+
6+
const styleModules = ['color', 'sizing', 'spacing', 'style', 'typography', 'user-colors'];
7+
8+
function getCustomProperties() {
9+
const result = [];
10+
const uniqueProperties = [];
11+
12+
styleModules.forEach((module) => {
13+
const content = fs.readFileSync(path.join(PACKAGE_BASE, `${module}.js`), 'utf8');
14+
const customPropertyDeclarationRegex = /--[\w\d-]+:.*;/g;
15+
const propertyDeclarations = content.match(customPropertyDeclarationRegex);
16+
propertyDeclarations.forEach((propertyDeclaration) => {
17+
// Avoid duplicate property declarations from dark theme
18+
const propertyName = propertyDeclaration.split(':')[0];
19+
if (!uniqueProperties.includes(propertyName)) {
20+
result.push(propertyDeclaration);
21+
uniqueProperties.push(propertyName);
22+
}
23+
});
24+
});
25+
26+
return result;
27+
}
28+
29+
function getUtilityClasses() {
30+
const result = [];
31+
32+
const modules = fs.readdirSync(path.join(PACKAGE_BASE, 'utilities'));
33+
modules
34+
.filter((module) => module.endsWith('.js'))
35+
.forEach((module) => {
36+
const content = fs.readFileSync(path.join(PACKAGE_BASE, 'utilities', module), 'utf8');
37+
const cssSectionRegex = /css`((.|\s)*?)`/gm;
38+
let match;
39+
40+
while ((match = cssSectionRegex.exec(content))) {
41+
let section = match[1];
42+
// Remove escape backslash
43+
section = section.replace(/\\\\/g, '\\');
44+
// Unindent
45+
section = section.replace(/\n\s{2}/g, '\n');
46+
result.push(section);
47+
}
48+
});
49+
50+
return result;
51+
}
52+
53+
const customProperties = getCustomProperties();
54+
const utilityClasses = getUtilityClasses();
55+
56+
let result = `/* This file contains declarations for CSS custom properties and utility
57+
* classes of the Lumo theme in order to provide auto-complete support
58+
* for IDEs.
59+
*
60+
* NOTE: This file is only intended to provide auto-complete support,
61+
* do not include it into an HTML page!
62+
*/
63+
64+
`;
65+
result += '/* Custom CSS properties */\n';
66+
result += ':host {\n';
67+
customProperties.forEach((customProperty) => {
68+
result += ` ${customProperty}\n`;
69+
});
70+
result += '}\n\n';
71+
72+
result += '/* Utility classes */\n';
73+
result += utilityClasses.join('');
74+
75+
fs.writeFileSync(path.join(PACKAGE_BASE, 'auto-complete.css'), result, 'utf8');

0 commit comments

Comments
 (0)