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-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-05-23 18:44:31 +02:00
|
|
|
|
2017-06-17 16:52:27 +02:00
|
|
|
let commons = require('../../extensions/commands/accents-setter/commons.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
|
|
|
|
*/
|
|
|
|
export default gulp.task('build:themes', () => {
|
|
|
|
gulpUtil.log(gulpUtil.colors.gray(HR));
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-05-24 00:46:34 +02:00
|
|
|
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);
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-05-24 00:46:34 +02:00
|
|
|
fs.writeFileSync(filePath, templateJSONStringified, CHARSET);
|
2017-05-23 18:44:31 +02:00
|
|
|
|
2017-05-24 00:46:34 +02:00
|
|
|
gulpUtil.log(MESSAGE_GENERATED, gulpUtil.colors.green(filePath));
|
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
|
|
|
});
|