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

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-02-18 19:29:35 +01:00
/*
* > Build Icons
*/
2017-04-07 22:58:57 +02:00
import fs from 'fs';
import gulp from 'gulp';
import Mustache from 'mustache';
import gutil from 'gulp-util';
2017-02-18 19:29:35 +01:00
import Paths from '../paths';
2017-04-07 22:58:57 +02:00
gulp.task('build:icons', cb => {
const partials = fs.readdirSync(`${Paths.src}/icons/partials`);
const partialData = {};
const files = fs.readdirSync(`${Paths.src}/icons/svgs`);
const icons = files.map(file => ({ name: file.split('.')[0], last: false }));
icons[icons.length - 1].last = true;
partials.forEach(partial => {
partialData[partial.split('.')[0]] = fs.readFileSync(
`${Paths.src}/icons/partials/${partial}`,
'utf-8'
);
});
let contents = Mustache.render(
fs.readFileSync(`${Paths.src}/icons/icons-theme.json`, 'utf-8'),
{ icons },
partialData
2017-02-18 19:29:35 +01:00
);
2017-04-07 22:58:57 +02:00
try {
contents = JSON.stringify(JSON.parse(contents), null, 2);
} catch (err) {
gutil.log(
gutil.colors.red('There is an error with JSON generated for icons'),
err
);
cb(err);
return;
}
const path = './themes/.material-theme-icons.tmp';
2017-04-07 22:58:57 +02:00
fs.writeFileSync(path, contents, 'utf-8');
gutil.log('Generated', gutil.colors.green(path));
cb();
2017-04-06 16:41:46 +02:00
});