2017-11-06 09:32:52 +01:00
|
|
|
import {getVariantIcons} from '../../extensions/helpers/fs';
|
2017-06-16 20:44:10 +02:00
|
|
|
import * as gulp from 'gulp';
|
|
|
|
import * as path from 'path';
|
2017-11-06 09:32:52 +01:00
|
|
|
import * as fs from 'fs';
|
2017-06-16 20:44:10 +02:00
|
|
|
|
2017-06-17 16:52:27 +02:00
|
|
|
import { CHARSET } from "../../extensions/consts/files";
|
|
|
|
import { IPackageJSON } from "../../extensions/interfaces/ipackage.json";
|
2017-06-16 20:44:10 +02:00
|
|
|
import { IThemeIconsVariants } from "../interfaces/itheme-icons-variants";
|
|
|
|
import PATHS from '../../extensions/consts/paths'
|
2017-07-21 20:20:17 +02:00
|
|
|
import { getDefaultValues } from "../../extensions/helpers/fs";
|
|
|
|
import { IDefaultsThemeVariantColours } from "../../extensions/interfaces/idefaults";
|
2017-11-06 09:32:52 +01:00
|
|
|
import { IThemeIconsItem } from '../interfaces/itheme-icons-item';
|
2017-06-16 20:44:10 +02:00
|
|
|
|
|
|
|
const PACKAGE_JSON: IPackageJSON = require(path.join(process.cwd(), './package.json'));
|
|
|
|
|
2017-07-21 20:20:17 +02:00
|
|
|
let variants: IDefaultsThemeVariantColours = getDefaultValues().themeVariantsColours;
|
2017-06-16 20:44:10 +02:00
|
|
|
|
|
|
|
function writeIconVariant(filepath: string, destpath: string, colour: string): void {
|
2017-11-04 23:15:37 +01:00
|
|
|
let regexp = new RegExp('(#[a-zA-Z0-9]{3,6})')
|
2017-06-16 20:44:10 +02:00
|
|
|
|
|
|
|
filepath = path.join(process.cwd(), PATHS.ICONS, filepath);
|
|
|
|
destpath = path.join(process.cwd(), PATHS.ICONS, destpath);
|
2017-07-18 14:27:08 +02:00
|
|
|
fs.writeFileSync(destpath, fs.readFileSync(filepath, CHARSET).replace(regexp, ($0, $1) => $0.replace($1, colour)), { encoding: CHARSET }) ;
|
2017-06-16 20:44:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default gulp.task('build:icons.variants', callback => {
|
|
|
|
try {
|
|
|
|
Object.keys(variants).forEach(variantName => {
|
|
|
|
PACKAGE_JSON.contributes.iconThemes.forEach(contribute => {
|
|
|
|
let regexpCheck: RegExp = new RegExp(Object.keys(variants).join('|'), 'i');
|
|
|
|
|
|
|
|
if (regexpCheck.test(contribute.path) || regexpCheck.test(contribute.id)) return;
|
|
|
|
|
|
|
|
let basepath: string = path.join(process.cwd(), contribute.path);
|
|
|
|
let basetheme: IThemeIconsVariants = require(basepath);
|
|
|
|
let theme: IThemeIconsVariants = JSON.parse(JSON.stringify(basetheme));
|
2017-07-21 20:20:17 +02:00
|
|
|
let variant = variants[variantName];
|
2017-06-16 20:44:10 +02:00
|
|
|
|
2017-11-06 09:32:52 +01:00
|
|
|
getVariantIcons().forEach(_iconName => {
|
|
|
|
let basethemeIcon: IThemeIconsItem = (basetheme.iconDefinitions as any)[_iconName];
|
|
|
|
let themeIcon: IThemeIconsItem = (theme.iconDefinitions as any)[_iconName];
|
|
|
|
|
|
|
|
if (themeIcon !== undefined) {
|
|
|
|
themeIcon.iconPath = themeIcon.iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
}
|
2017-06-16 20:44:10 +02:00
|
|
|
|
2017-11-06 09:32:52 +01:00
|
|
|
if (basethemeIcon !== undefined && themeIcon !== undefined) {
|
|
|
|
writeIconVariant(basethemeIcon.iconPath, themeIcon.iconPath, variant);
|
|
|
|
}
|
|
|
|
});
|
2017-06-16 20:44:10 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
callback(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|