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

67 lines
1.8 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(
2017-05-05 17:34:54 +02:00
`${Paths.src}/themes/theme-template-color-theme.json`,
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
}
});
2017-05-08 09:09:19 +02:00
gulp.task('build:themes', cb => {
gutil.log()
})
2017-04-05 23:06:45 +02:00
gulp.task('build:themes', cb => {
2017-05-05 23:12:46 +02:00
gutil.log(
2017-05-08 09:09:19 +02:00
gutil.colors.gray('\n████████████████████████████████████████████████████████\n')
);
2017-04-05 23:06:45 +02:00
themeVariants.forEach(variant => {
const templateData = {
2017-05-05 17:48:22 +02:00
'commons': themeCommons,
2017-05-05 21:44:46 +02:00
variant
2017-04-05 23:06:45 +02:00
};
const templateJson = JSON.parse(
2017-04-05 23:06:45 +02:00
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
2017-05-05 23:12:46 +02:00
gutil.log('Generate', gutil.colors.green(path));
2017-04-05 23:06:45 +02:00
});
2017-05-05 23:12:46 +02:00
gutil.log(
2017-05-08 09:09:19 +02:00
gutil.colors.gray('\n████████████████████████████████████████████████████████\n')
);
2017-04-05 23:06:45 +02:00
});