2018-04-20 20:07:36 +02:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as gulp from 'gulp';
|
|
|
|
import * as gulpUtil from 'gulp-util';
|
|
|
|
import * as mustache from 'mustache';
|
|
|
|
import * as path from 'path';
|
|
|
|
|
2018-05-07 16:23:17 +02:00
|
|
|
import {HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR} from './../consts/log';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2019-01-31 21:35:51 +01:00
|
|
|
import {CHARSET} from './../../src/consts/files';
|
2018-05-07 16:23:17 +02:00
|
|
|
import {IThemeVariant} from './../interfaces/itheme-variant';
|
2019-01-31 21:35:51 +01:00
|
|
|
import paths from './../../src/consts/paths';
|
|
|
|
import {ensureDir, getDefaultValues} from './../../src/helpers/fs';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-07 16:23:17 +02:00
|
|
|
const commons = getDefaultValues();
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-07 16:23:17 +02:00
|
|
|
const themeTemplateFileContent: string = fs.readFileSync(path.join(paths.SRC, '/themes/theme-template-color-theme.json'), CHARSET);
|
|
|
|
const themeVariants: IThemeVariant[] = [];
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-07 16:23:17 +02:00
|
|
|
const fileNames: string[] = fs.readdirSync(path.join(paths.SRC, './themes/settings/specific'));
|
2018-04-20 20:07:36 +02:00
|
|
|
|
|
|
|
// build theme variants for later use in templating
|
|
|
|
fileNames.forEach(fileName => {
|
2018-05-07 16:23:17 +02:00
|
|
|
const filePath: string = path.join(paths.SRC, './themes/settings/specific', `./${fileName}`);
|
|
|
|
const contents: string = fs.readFileSync(filePath, CHARSET);
|
2018-04-20 20:07:36 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
themeVariants.push(JSON.parse(contents));
|
|
|
|
} catch (error) {
|
|
|
|
gulpUtil.log(MESSAGE_THEME_VARIANT_PARSE_ERROR, error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Themes task
|
|
|
|
* Builds Themes
|
|
|
|
*/
|
|
|
|
export default gulp.task('build:themes', cb => {
|
|
|
|
gulpUtil.log(gulpUtil.colors.gray(HR));
|
|
|
|
|
|
|
|
ensureDir(path.join(paths.THEMES));
|
|
|
|
|
|
|
|
try {
|
|
|
|
themeVariants.forEach(variant => {
|
2018-05-07 16:23:17 +02:00
|
|
|
const filePath = path.join(paths.THEMES, `./${variant.name}.json`);
|
|
|
|
const templateData = {commons, variant};
|
|
|
|
const templateJSON: any = JSON.parse(mustache.render(themeTemplateFileContent, templateData));
|
|
|
|
const templateJSONStringified: string = JSON.stringify(templateJSON, null, 2);
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-07 16:23:17 +02:00
|
|
|
fs.writeFileSync(filePath, templateJSONStringified, {encoding: CHARSET});
|
2018-04-20 20:07:36 +02:00
|
|
|
|
|
|
|
gulpUtil.log(MESSAGE_GENERATED, gulpUtil.colors.green(filePath));
|
|
|
|
});
|
|
|
|
} catch (exception) {
|
|
|
|
gulpUtil.log(exception);
|
|
|
|
cb(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
gulpUtil.log(gulpUtil.colors.gray(HR));
|
|
|
|
});
|