Update icons to work against Mustache

This commit is contained in:
Sundeep Malladi 2017-04-07 15:58:57 -05:00
parent ab279faa7b
commit c4b84db66d
7 changed files with 68 additions and 2101 deletions

View file

@ -1,56 +1,47 @@
'use strict';
/* /*
* > Build Icons * > Build Icons
*/ */
import Gulp from 'gulp'; import fs from 'fs';
import runSequence from 'run-sequence'; import gulp from 'gulp';
import Template from 'gulp-template'; import Mustache from 'mustache';
import Rename from 'gulp-rename'; import gutil from 'gulp-util';
import FileList from 'gulp-filelist';
import Include from 'gulp-include';
import Data from 'gulp-data';
import Paths from '../paths'; import Paths from '../paths';
import iconList from '../../iconlist.json'; 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'
);
});
Gulp.task('build:icons', (cb) => { let contents = Mustache.render(
runSequence( fs.readFileSync(`${Paths.src}/icons/icons-theme.json`, 'utf-8'),
'build:iconslist', { icons },
'build:templateicons', partialData
(error) => {
if (error) {
console.log('\n[Build Icons]'.bold.magenta + ' There was an issue building icons:\n'.bold.red + error.message);
} else {
console.log('\n[Build Icons]'.bold.magenta + ' Finished successfully\n'.bold.green);
}
cb(error);
}
); );
});
try {
contents = JSON.stringify(JSON.parse(contents), null, 2);
Gulp.task('build:iconslist', () => { } catch (err) {
Gulp.src(`${Paths.src}/icons/svgs/*.svg`) gutil.log(
.pipe(FileList('iconlist.json', { gutil.colors.red('There is an error with JSON generated for icons'),
flatten: true, err
removeExtensions: true );
})) cb(err);
.pipe(Gulp.dest('./')); return;
}); }
const path = './.material-theme-icons.tmp';
Gulp.task('build:templateicons', () => { fs.writeFileSync(path, contents, 'utf-8');
Gulp.src(`${Paths.src}/icons/icons-theme.json`) gutil.log('Generated', gutil.colors.green(path));
.pipe(Include())
.on('error', console.log) cb();
.pipe(Data(() => ({ icons: iconList })))
.pipe(Template())
.pipe(Rename({
basename: ".material-theme-icons",
extname: ".tmp"
}))
.pipe(Gulp.dest('./'));
}); });

View file

@ -1,3 +1,7 @@
/*
* > Build Themes
*/
import fs from 'fs'; import fs from 'fs';
import gulp from 'gulp'; import gulp from 'gulp';
import gutil from 'gulp-util'; import gutil from 'gulp-util';

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -69,13 +69,8 @@
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-bump": "^2.7.0", "gulp-bump": "^2.7.0",
"gulp-conventional-changelog": "^1.1.3", "gulp-conventional-changelog": "^1.1.3",
"gulp-data": "^1.2.1",
"gulp-filelist": "^1.0.0",
"gulp-if": "^2.0.2", "gulp-if": "^2.0.2",
"gulp-include": "^2.3.1",
"gulp-rename": "^1.2.2",
"gulp-stats": "^0.0.4", "gulp-stats": "^0.0.4",
"gulp-template": "^4.0.0",
"gulp-util": "^3.0.8", "gulp-util": "^3.0.8",
"gulp-watch": "^4.3.8", "gulp-watch": "^4.3.8",
"json-minify": "^1.0.0", "json-minify": "^1.0.0",

View file

@ -1,9 +1,8 @@
{ {
//=include "partials/iconDefinitions.js" {{> iconDefinitions}}
//=include "partials/fileExtensions.js" {{> fileNames}}
//=include "partials/fileNames.js" {{> fileFolders}}
//=include "partials/fileFolders.js" {{> folderNames}}
//=include "partials/folderNames.js" {{> light}}
//=include "partials/light.js" {{> languageIds}}
//=include "partials/languageIds.js" }
}

View file

@ -1,17 +1,19 @@
"iconDefinitions": {<% for( var i = 0; i < icons.length; i++ ){ %> "iconDefinitions": {
"_folder_dark": { "_folder_dark": {
"iconPath": "./icons/folder.svg" "iconPath": "./icons/folder.svg"
}, },
"_folder_light": { "_folder_light": {
"iconPath": "./icons/folder-light.svg" "iconPath": "./icons/folder-light.svg"
}, },
"_folder_open": { "_folder_open": {
"iconPath": "./icons/folder-outline.svg" "iconPath": "./icons/folder-outline.svg"
}, },
"_file_dark": { "_file_dark": {
"iconPath": "./icons/file.svg" "iconPath": "./icons/file.svg"
}, },
"_file_<%= icons[i] %>": { {{#icons}}
"iconPath": "./icons/<%= icons[i] %>.svg" "_file_{{name}}": {
}<% if( i !== (icons.length - 1)){ %>,<%} %><% } %> "iconPath": "./icons/{{name}}.svg"
}, }{{^last}},{{/last}}
{{/icons}}
},