Repository navigation
Expand file tree
/
Copy pathcontextHelper.js
More file actions
108 lines (94 loc) · 3.37 KB
/
Copy pathcontextHelper.js
File metadata and controls
108 lines (94 loc) · 3.37 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
import fs from 'fs';
import FaviconsWebpackPlugin from 'favicons-webpack-plugin';
import { getNamedConfiguration } from '../../server/configs/config.js';
// Configs that only serve as a runtime `BASE_CONFIG` merge base, never a deployable `CONFIG` value.
const BASE_ONLY_CONFIGS = ['waltti'];
function getAllConfigs() {
if (process.env.CONFIG && process.env.CONFIG !== '') {
return [getNamedConfiguration(process.env.CONFIG)];
}
const srcDirectory = './server/configs';
return fs
.readdirSync(srcDirectory)
.filter(file => /^config\.\w+\.js$/.test(file))
.map(file => file.replace('config.', '').replace('.js', ''))
.filter(theme => !BASE_ONLY_CONFIGS.includes(theme))
.map(theme => getNamedConfiguration(theme));
}
export function themePath(theme) {
const themeCss = `./styles/themes/${theme}/theme.scss`;
return fs.existsSync(themeCss)
? themeCss
: './styles/themes/default/theme.scss';
}
function getEntries(theme, sprites = null) {
return {
[`${theme}_theme`]: themePath(theme),
...(sprites !== null
? {
// Generated by buildSprites.js (see `prebuild`), which runs first.
[sprites]: `./_static/${sprites}`,
}
: {}),
};
}
function getAllThemeEntries() {
if (process.env.CONFIG && process.env.CONFIG !== '') {
const config = getNamedConfiguration(process.env.CONFIG);
return {
...getEntries('default'),
...getEntries(process.env.CONFIG, config.sprites),
};
}
return getAllConfigs().reduce(
(prev, config) => ({
...prev,
...getEntries(config.CONFIG, config.sprites),
}),
{},
);
}
function faviconPluginFromConfig(config) {
let logo =
config.favicon ||
`./app/assets/images/${config.CONFIG}/${config.CONFIG}-favicon.png`;
if (!fs.existsSync(logo)) {
logo = './app/assets/images/default/default-favicon.png';
}
return new FaviconsWebpackPlugin({
// Your source logo
logo,
// The prefix for all image files (might be a folder or a name)
prefix: `assets/icons-${config.CONFIG}-[contenthash]/`,
// Emit all stats of the generated icons
emitStats: true,
// The name of the json containing all favicon information
statsFilename: `assets/iconstats-${config.CONFIG}.json`,
inject: false,
// Options for the `favicons` package itself. The plugin only reads them
// from here; at the top level they're silently ignored.
favicons: {
// Matches the `favicons` package default (and what actually took
// effect pre-fix, since these options were previously silently
// ignored at the top level).
background: '#fff',
theme_color: config.colors ? config.colors.primary : '#fff',
// favicon app title (see https://github.com/haydenbleasel/favicons#usage)
appName: config.title,
appDescription: config.meta.description,
// Merged over the package's defaults, which enable every platform.
// Nothing references Apple startup images (~35 MB per config) or
// Windows tiles, so only those are skipped.
icons: {
appleStartup: false,
windows: false,
},
},
});
}
function getAllFaviconPlugins() {
return getAllConfigs().map(faviconPluginFromConfig);
}
export const themeEntries = getAllThemeEntries();
export const faviconPlugins = getAllFaviconPlugins();