vsc-material-theme/.gulp/tasks/themes.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-04-07 22:58:57 +02:00
/*
* > Build Themes
*/
2017-04-05 23:06:45 +02:00
import fs from 'fs';
import gulp from 'gulp';
2017-04-06 16:41:46 +02:00
import gutil from 'gulp-util';
2017-04-05 23:06:45 +02:00
import Mustache from 'mustache';
import YAML from 'yamljs';
2017-04-06 16:41:46 +02:00
import Paths from '../paths';
2017-04-10 10:04:49 +02:00
const themeCommons = require('../../src/themes/settings/commons.json');
2017-04-05 23:06:45 +02:00
const themeVariants = [];
const themeTemplateFile = fs.readFileSync(
`${Paths.src}/themes/theme-template.yml`,
2017-04-05 23:06:45 +02:00
'utf-8'
);
const files = fs.readdirSync(`${Paths.src}/themes/settings/specific`);
2017-04-05 23:06:45 +02:00
// build theme variants for later use in templating
files.forEach(file => {
const name = file.split('.')[0];
const filepath = `${Paths.src}/themes/settings/specific/${file}`;
2017-04-05 23:06:45 +02:00
const contents = fs.readFileSync(filepath, 'utf-8');
try {
themeVariants.push(JSON.parse(contents));
} catch (err) {
2017-04-06 16:41:46 +02:00
gutil.log('Error when parsing json for theme variants', err);
2017-04-05 23:06:45 +02:00
}
});
gulp.task('build:themes', cb => {
themeVariants.forEach(variant => {
const templateData = {
commons: themeCommons,
variant,
};
const templateJson = YAML.parse(
Mustache.render(themeTemplateFile, templateData)
);
2017-04-06 16:41:46 +02:00
const path = `${Paths.themes}/${variant.name}.json`;
2017-04-05 23:06:45 +02:00
fs.writeFileSync(
2017-04-06 16:41:46 +02:00
path,
2017-04-05 23:06:45 +02:00
JSON.stringify(templateJson, null, 2),
'utf-8'
);
2017-04-06 16:41:46 +02:00
gutil.log('Generated', gutil.colors.green(path));
2017-04-05 23:06:45 +02:00
});
});