2017-05-23 18:44:31 +02:00
|
|
|
import * as fs from 'fs';
|
2017-05-24 00:46:34 +02:00
|
|
|
import * as gulp from 'gulp';
|
|
|
|
import * as gulpUtil from 'gulp-util';
|
|
|
|
import * as mustache from 'mustache';
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
import { HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR } from './../consts/log';
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-06-17 16:52:27 +02:00
|
|
|
import { CHARSET } from "../../extensions/consts/files";
|
2017-06-23 13:55:52 +02:00
|
|
|
import { IDefaults } from "../../extensions/interfaces/idefaults";
|
2017-05-24 00:46:34 +02:00
|
|
|
import { IThemeVariant } from './../interfaces/itheme-variant';
|
2017-06-12 20:11:51 +02:00
|
|
|
import paths from '../../extensions/consts/paths';
|
2017-11-01 12:54:09 +01:00
|
|
|
import { ensureDir } from '../../extensions/helpers/fs';
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-06-23 13:55:52 +02:00
|
|
|
let commons: IDefaults = require('../../extensions/defaults.json');
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-05-24 00:46:34 +02:00
|
|
|
let themeTemplateFileContent: string = fs.readFileSync(path.join(paths.SRC, `/themes/theme-template-color-theme.json`), CHARSET);
|
|
|
|
let themeVariants: IThemeVariant[] = [];
|
|
|
|
|
|
|
|
let fileNames: string[] = fs.readdirSync(path.join(paths.SRC, `./themes/settings/specific`));
|
2017-05-23 18:44:31 +02:00
|
|
|
|
|
|
|
// build theme variants for later use in templating
|
2017-05-24 00:46:34 +02:00
|
|
|
fileNames.forEach(fileName => {
|
|
|
|
let filePath: string = path.join(paths.SRC, `./themes/settings/specific`, `./${fileName}`);
|
|
|
|
let contents: string = fs.readFileSync(filePath, CHARSET);
|
2017-05-23 18:44:31 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
themeVariants.push(JSON.parse(contents));
|
2017-05-24 00:46:34 +02:00
|
|
|
} catch (error) {
|
|
|
|
gulpUtil.log(MESSAGE_THEME_VARIANT_PARSE_ERROR, error);
|
2017-05-23 18:44:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-05-24 00:46:34 +02:00
|
|
|
/**
|
|
|
|
* Themes task
|
|
|
|
* Builds Themes
|
|
|
|
*/
|
2017-10-24 00:11:48 +02:00
|
|
|
export default gulp.task('build:themes', cb => {
|
2017-05-24 00:46:34 +02:00
|
|
|
gulpUtil.log(gulpUtil.colors.gray(HR));
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-11-01 12:54:09 +01:00
|
|
|
ensureDir(path.join(paths.THEMES));
|
|
|
|
|
2017-10-24 00:11:48 +02:00
|
|
|
try {
|
|
|
|
themeVariants.forEach(variant => {
|
|
|
|
let filePath = path.join(paths.THEMES, `./${variant.name}.json`);
|
|
|
|
let templateData = { commons, variant };
|
|
|
|
let templateJSON: any = JSON.parse(mustache.render(themeTemplateFileContent, templateData));
|
|
|
|
let templateJSONStringified: string = JSON.stringify(templateJSON, null, 2);
|
|
|
|
|
|
|
|
fs.writeFileSync(filePath, templateJSONStringified, { encoding: CHARSET });
|
|
|
|
|
|
|
|
gulpUtil.log(MESSAGE_GENERATED, gulpUtil.colors.green(filePath));
|
|
|
|
});
|
|
|
|
} catch (exception) {
|
|
|
|
gulpUtil.log(exception);
|
|
|
|
cb(exception);
|
|
|
|
}
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-05-24 00:46:34 +02:00
|
|
|
gulpUtil.log(gulpUtil.colors.gray(HR));
|
2017-05-23 18:44:31 +02:00
|
|
|
});
|