-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy paththeme-builder.js
More file actions
73 lines (60 loc) · 1.8 KB
/
theme-builder.js
File metadata and controls
73 lines (60 loc) · 1.8 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// theme-builder.js
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
const THEMES_DIR = path.resolve(__dirname, 'src/styles/themes');
const DIST_THEMES_DIR = path.resolve(__dirname, 'dist/themes');
const THEME_ENV_KEY = 'AWESOME_THEME';
function isThemeDirectory(name) {
return /^theme-/i.test(name);
}
function ensureDir(dirPath) {
shell.mkdir('-p', dirPath);
}
function runWebpack(themeName, format) {
const command = 'webpack --config webpack.themes.config.js';
const result = shell.exec(command, {
env: {
...process.env,
[THEME_ENV_KEY]: themeName,
AWESOME_THEME_FORMAT: format, // 'esm' | 'cjs'
},
silent: false,
});
if (result.code !== 0) {
throw new Error(
`[theme-builder] Failed building theme "${themeName}" (${format}) (exit code ${result.code})`
);
}
}
function buildTheme(themeName) {
runWebpack(themeName, 'esm'); // dist/themes/<theme>.mjs
runWebpack(themeName, 'cjs'); // dist/themes/<theme>.js
}
fs.readdir(THEMES_DIR, { withFileTypes: true }, (err, entries) => {
if (err) {
console.error('[theme-builder] Failed to read themes directory:', err);
process.exitCode = 1;
return;
}
ensureDir(DIST_THEMES_DIR);
const themeNames = entries
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.filter(isThemeDirectory)
.sort();
if (themeNames.length === 0) {
console.warn('[theme-builder] No theme-* directories found.');
return;
}
try {
themeNames.forEach((themeName) => {
console.log(`[theme-builder] Building ${themeName}...`);
buildTheme(themeName);
});
console.log(`[theme-builder] Done. Built ${themeNames.length} theme(s).`);
} catch (buildError) {
console.error(buildError);
process.exitCode = 1;
}
});