diff --git a/.gulp/tasks/icons-accents.ts b/.gulp/tasks/icons-accents.ts index 5810e02..04eef61 100644 --- a/.gulp/tasks/icons-accents.ts +++ b/.gulp/tasks/icons-accents.ts @@ -42,7 +42,7 @@ function replaceNameWithAccent(name: string, accentName: string): string { * @returns {string} */ export function replaceSVGColour(filecontent: string, colour: string): string { - return filecontent.replace(new RegExp('.st0\{fill:#([a-zA-Z0-9]{6})\}|path fill="#([a-zA-Z0-9]{6})"'), ($0, $1, $2) => { + return filecontent.replace(new RegExp('.st0\{fill:\s{0,}#([a-zA-Z0-9]{6})\}|path fill="#([a-zA-Z0-9]{6})"'), ($0, $1, $2) => { colour = colour.replace('#', ''); @@ -74,6 +74,8 @@ function writeSVGIcon(fromFile: string, toFile: string, accent: string): void { let content: string = replaceSVGColour(fileContent, DEFAULTS.accents[accent]); toFile = normalizeIconPath(toFile); + gutil.log(gutil.colors.gray(`Accented icon ${toFile} created with colour ${ accent } (${ DEFAULTS.accents[accent] })`)); + fs.writeFileSync(toFile, content); } diff --git a/extensions/commands/theme-icons/index.ts b/extensions/commands/theme-icons/index.ts index 04bfb43..9beb82c 100644 --- a/extensions/commands/theme-icons/index.ts +++ b/extensions/commands/theme-icons/index.ts @@ -1,13 +1,18 @@ import {getAccentableIcons} from '../../helpers/fs'; import * as fs from 'fs'; -import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute } from "../../helpers/fs"; +import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute, getVariantIcons } from "../../helpers/fs"; import { getCurrentThemeIconsID } from "../../helpers/vscode"; import { getCustomSettings, isAccent, isMaterialThemeIcons } from "../../helpers/settings"; import { CHARSET } from "../../consts/files"; import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json"; -import { IThemeIcons } from "../../interfaces/itheme-icons"; +import {IThemeIconsIconPath, IThemeIcons} from '../../interfaces/itheme-icons'; + + +function getIconDefinition(definitions: any, iconname: string): IThemeIconsIconPath { + return (definitions as any)[iconname]; +} /** * Replaces icon path with the accented one. @@ -40,33 +45,42 @@ export const THEME_ICONS = () => { let _accentName = accentName.replace(/\s+/, '-'); getAccentableIcons().forEach(iconname => { - let distIcon = (theme.iconDefinitions as any)[iconname]; - let outIcon = (defaults.icons.theme.iconDefinitions as any)[iconname]; + let distIcon = getIconDefinition(theme.iconDefinitions, iconname); + let outIcon = getIconDefinition(defaults.icons.theme.iconDefinitions, iconname); if (typeof distIcon === 'object' && typeof outIcon === 'object') { distIcon.iconPath = replaceIconPathWithAccent(outIcon.iconPath, _accentName) } }) - theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath.replace('.svg', `.accent.${ _accentName }.svg`); - theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath.replace('.svg', `.accent.${ _accentName }.svg`); + // theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath.replace('.svg', `.accent.${ _accentName }.svg`); + // theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath.replace('.svg', `.accent.${ _accentName }.svg`); } else { getAccentableIcons().forEach(iconname => { - let distIcon = (theme.iconDefinitions as any)[iconname]; - let outIcon = (defaults.icons.theme.iconDefinitions as any)[iconname]; + let distIcon = getIconDefinition(theme.iconDefinitions, iconname); + let outIcon = getIconDefinition(defaults.icons.theme.iconDefinitions, iconname); distIcon.iconPath = outIcon.iconPath; }); - theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath; - theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath; + // theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath; + // theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath; } - theme.iconDefinitions._folder_dark.iconPath = defaults.icons.theme.iconDefinitions._folder_dark.iconPath.replace('.svg', `${ variantName }.svg`); - theme.iconDefinitions._folder_dark_build.iconPath = defaults.icons.theme.iconDefinitions._folder_dark_build.iconPath.replace('.svg', `${ variantName }.svg`); + getVariantIcons().forEach(iconname => { + let distIcon = getIconDefinition(theme.iconDefinitions, iconname); + let outIcon = getIconDefinition(defaults.icons.theme.iconDefinitions, iconname); - theme.iconDefinitions._folder_light.iconPath = defaults.icons.theme.iconDefinitions._folder_light.iconPath.replace('.svg', `${ variantName }.svg`); - theme.iconDefinitions["_folder_light_build"].iconPath = defaults.icons.theme.iconDefinitions["_folder_light_build"].iconPath.replace('.svg', `${ variantName }.svg`); + if (!!distIcon && !!outIcon) { + distIcon.iconPath = outIcon.iconPath.replace('.svg', `${ variantName }.svg`); + } + }) + + // theme.iconDefinitions._folder_dark.iconPath = defaults.icons.theme.iconDefinitions._folder_dark.iconPath.replace('.svg', `${ variantName }.svg`); + // theme.iconDefinitions._folder_dark_build.iconPath = defaults.icons.theme.iconDefinitions._folder_dark_build.iconPath.replace('.svg', `${ variantName }.svg`); + + // theme.iconDefinitions._folder_light.iconPath = defaults.icons.theme.iconDefinitions._folder_light.iconPath.replace('.svg', `${ variantName }.svg`); + // theme.iconDefinitions["_folder_light_build"].iconPath = defaults.icons.theme.iconDefinitions["_folder_light_build"].iconPath.replace('.svg', `${ variantName }.svg`); fs.writeFile(themepath, JSON.stringify(theme), { encoding: CHARSET }, (error) => { if (error) { diff --git a/extensions/defaults.json b/extensions/defaults.json index 52f163d..56084d1 100644 --- a/extensions/defaults.json +++ b/extensions/defaults.json @@ -90,5 +90,12 @@ "Light High Contrast": "vs", "Palenight": "vs-dark", "Palenight High Contrast": "vs-dark" - } + }, + "variantsIcons": [ + "_folder_dark_build", + "_folder_dark", + "_folder_light_build", + "_folder_light", + "_folder_vscode" + ] } \ No newline at end of file diff --git a/extensions/helpers/fs.ts b/extensions/helpers/fs.ts index 3e84ef6..de5e41f 100644 --- a/extensions/helpers/fs.ts +++ b/extensions/helpers/fs.ts @@ -52,6 +52,13 @@ export function getAccentableIcons(): string[] { return getDefaultValues().accentableIcons; } +/** + * @export + * @returns {string[]} + */ +export function getVariantIcons(): string[] { + return getDefaultValues().variantsIcons; +} /** * Gets a theme content by a given contribute ID diff --git a/extensions/interfaces/idefaults.ts b/extensions/interfaces/idefaults.ts index 649fb61..4e4ee50 100644 --- a/extensions/interfaces/idefaults.ts +++ b/extensions/interfaces/idefaults.ts @@ -6,6 +6,7 @@ export interface IDefaults { themeVariants: IDefaultsThemeVariant; themeVariantsColours: IDefaultsThemeVariantColours; themeVariantsUITheme: IDefaultsThemeVariantUITheme; + variantsIcons: string[]; } export interface IAccents {