silverstripe-webpack/webpack.configuration.js

39 lines
950 B
JavaScript
Raw Normal View History

2018-02-22 14:39:58 +01:00
/*
2018-06-23 12:27:06 +02:00
* Load webpack configuration from app/_config/webpack.yml
2018-02-22 14:39:58 +01:00
*/
const YML_PATH = '/app/_config/webpack.yml';
2021-03-14 21:45:35 +01:00
const CONF_VAR = 'App\\Templates\\WebpackTemplateProvider';
2018-04-21 06:29:32 +02:00
const path = require('path');
2019-05-23 13:02:32 +02:00
const filesystem = require('fs');
2018-04-21 06:29:32 +02:00
const fs = require('fs');
const yaml = require('js-yaml');
2019-05-23 13:02:32 +02:00
const conf = yaml.safeLoad(
2021-03-14 21:45:35 +01:00
fs.readFileSync(path.join(__dirname, YML_PATH), 'utf8'),
);
2018-02-05 12:11:01 +01:00
2019-05-23 13:02:32 +02:00
let themes = [];
// add themes
2021-03-14 21:45:35 +01:00
if (conf[CONF_VAR].THEMESDIR) {
const themeDir = conf[CONF_VAR].THEMESDIR;
const dir = path.resolve(__dirname, themeDir);
2019-05-23 13:02:32 +02:00
2021-03-14 21:45:35 +01:00
if (filesystem.existsSync(dir)) {
filesystem.readdirSync(dir).forEach((file) => {
filePath = path.join(themeDir, file);
const stat = filesystem.statSync(filePath);
2019-05-23 13:02:32 +02:00
2021-03-14 21:45:35 +01:00
if (stat && stat.isDirectory()) {
themes.push(filePath);
}
});
}
2019-05-23 13:02:32 +02:00
}
module.exports = {
2021-03-14 21:45:35 +01:00
configuration: conf[CONF_VAR],
themes: themes,
2019-05-23 13:02:32 +02:00
};