vsc-material-theme/.gulp/tasks/icons-variants.ts
Mattia Astorino 9907cc8c67
Develop (#185)
* chore: Update meta and readme

* chore. Update README

* Refactor/linting - tslint-xo (#178)

* refactor(deps): added tslint, cleanup, and activationEvents modified

* refactor(lint): linting...

* refactor(changelog): changelo method refactor (should be tested)

* refactor(theme-icons):  linting and small refactor

* refactor(accents-setter): linting and small refactor

* chore(travis): added travis file

* fix(Lighter): Fix folders icon association

* chore: Clean test files

* fix(Icons): Add icon to .spec.ts files

* chore: Update git icon

* Update issue templates (#184)
2018-05-07 16:23:17 +02:00

63 lines
2.3 KiB
TypeScript

import * as gulp from 'gulp';
import * as path from 'path';
import * as fs from 'fs';
import {IThemeIconsVariants} from '../interfaces/itheme-icons-variants';
import {CHARSET} from './../../extensions/consts/files';
import PATHS from './../../extensions/consts/paths';
import {getDefaultValues, getVariantIcons, getPackageJSON} from './../../extensions/helpers/fs';
import {IDefaultsThemeVariant} from './../../extensions/interfaces/idefaults';
import {IThemeIconsItem} from './../interfaces/itheme-icons-item';
const PACKAGE_JSON = getPackageJSON();
const variants: IDefaultsThemeVariant = getDefaultValues().themeVariantsColours;
const writeIconVariant = (filepath: string, destpath: string, colour: string): void => {
const regexp = new RegExp('(#4a616c)', 'i');
const finalFilePath = path.join(process.cwd(), PATHS.ICONS, filepath);
const finalDestpath = path.join(process.cwd(), PATHS.ICONS, destpath);
fs.writeFileSync(
finalDestpath,
fs.readFileSync(finalFilePath, CHARSET)
.replace(regexp, ($0, $1) => $0.replace($1, colour)), {encoding: CHARSET}
);
};
export default gulp.task('build:icons.variants', callback => {
try {
Object.keys(variants).forEach(variantName => {
PACKAGE_JSON.contributes.iconThemes.forEach(contribute => {
const regexpCheck: RegExp = new RegExp(Object.keys(variants).join('|'), 'i');
if (regexpCheck.test(contribute.path) || regexpCheck.test(contribute.id)) {
return;
}
const basepath: string = path.join(process.cwd(), contribute.path);
const basetheme: IThemeIconsVariants = require(basepath);
const theme: IThemeIconsVariants = JSON.parse(JSON.stringify(basetheme));
const variant = variants[variantName];
getVariantIcons().forEach(iconName => {
const basethemeIcon: IThemeIconsItem = (basetheme.iconDefinitions as any)[iconName];
const themeIcon: IThemeIconsItem = (theme.iconDefinitions as any)[iconName];
if (themeIcon !== undefined) {
themeIcon.iconPath = themeIcon.iconPath.replace('.svg', `${ variantName }.svg`);
}
if (basethemeIcon !== undefined && themeIcon !== undefined) {
writeIconVariant(basethemeIcon.iconPath, themeIcon.iconPath, variant);
}
});
});
});
} catch (error) {
callback(error);
return;
}
callback();
});