Repository navigation
Expand file tree
/
Copy pathset_theme.js
More file actions
54 lines (47 loc) · 1.41 KB
/
Copy pathset_theme.js
File metadata and controls
54 lines (47 loc) · 1.41 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
const fs = require("fs");
const path = require("path");
// Bootswatch themes whose CSS names a webfont. These get themes/_bundled_fonts.scss
// so the faces are served locally. The default theme and the system-stack themes
// (brite, cerulean, litera, pulse, quartz, slate) are intentionally absent.
const THEMES_WITH_BUNDLED_FONTS = new Set([
"cosmo",
"cyborg",
"darkly",
"flatly",
"journal",
"lumen",
"lux",
"materia",
"minty",
"morph",
"sandstone",
"simplex",
"sketchy",
"solar",
"spacelab",
"superhero",
"united",
"vapor",
"varpor",
"yeti",
"zephyr",
]);
// Get the theme name from the environment variable, default to "default"
const theme = (process.env.PWP__THEME || "default").toLowerCase();
const themesDir = path.resolve(__dirname, "./app/assets/stylesheets/themes");
const shimPath = path.join(themesDir, "_selected.scss");
const themeFilePath = path.join(themesDir, `${theme}.css`);
if (!fs.existsSync(themeFilePath)) {
console.error(`Error: Theme "${theme}" not found at ${themeFilePath}`);
process.exit(1);
}
const lines = [
"// Auto-generated by set_theme.js — do not edit manually.",
`@use "themes/${theme}";`,
];
if (THEMES_WITH_BUNDLED_FONTS.has(theme)) {
lines.push('@use "themes/bundled_fonts";');
}
const contents = `${lines.join("\n")}\n`;
fs.writeFileSync(shimPath, contents, "utf8");
console.log(`Theme shim written: ${shimPath} (@use themes/${theme})`);