chore: Makes variant icons build/command dynamic.
This commit is contained in:
parent
89aba2be0c
commit
c42f1962c9
5 changed files with 47 additions and 16 deletions
|
@ -42,7 +42,7 @@ function replaceNameWithAccent(name: string, accentName: string): string {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function replaceSVGColour(filecontent: string, colour: string): 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('#', '');
|
colour = colour.replace('#', '');
|
||||||
|
|
||||||
|
@ -74,6 +74,8 @@ function writeSVGIcon(fromFile: string, toFile: string, accent: string): void {
|
||||||
let content: string = replaceSVGColour(fileContent, DEFAULTS.accents[accent]);
|
let content: string = replaceSVGColour(fileContent, DEFAULTS.accents[accent]);
|
||||||
toFile = normalizeIconPath(toFile);
|
toFile = normalizeIconPath(toFile);
|
||||||
|
|
||||||
|
gutil.log(gutil.colors.gray(`Accented icon ${toFile} created with colour ${ accent } (${ DEFAULTS.accents[accent] })`));
|
||||||
|
|
||||||
fs.writeFileSync(toFile, content);
|
fs.writeFileSync(toFile, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
import {getAccentableIcons} from '../../helpers/fs';
|
import {getAccentableIcons} from '../../helpers/fs';
|
||||||
import * as fs from '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 { getCurrentThemeIconsID } from "../../helpers/vscode";
|
||||||
import { getCustomSettings, isAccent, isMaterialThemeIcons } from "../../helpers/settings";
|
import { getCustomSettings, isAccent, isMaterialThemeIcons } from "../../helpers/settings";
|
||||||
|
|
||||||
import { CHARSET } from "../../consts/files";
|
import { CHARSET } from "../../consts/files";
|
||||||
import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
|
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.
|
* Replaces icon path with the accented one.
|
||||||
|
@ -40,33 +45,42 @@ export const THEME_ICONS = () => {
|
||||||
let _accentName = accentName.replace(/\s+/, '-');
|
let _accentName = accentName.replace(/\s+/, '-');
|
||||||
|
|
||||||
getAccentableIcons().forEach(iconname => {
|
getAccentableIcons().forEach(iconname => {
|
||||||
let distIcon = (theme.iconDefinitions as any)[iconname];
|
let distIcon = getIconDefinition(theme.iconDefinitions, iconname);
|
||||||
let outIcon = (defaults.icons.theme.iconDefinitions as any)[iconname];
|
let outIcon = getIconDefinition(defaults.icons.theme.iconDefinitions, iconname);
|
||||||
|
|
||||||
if (typeof distIcon === 'object' && typeof outIcon === 'object') {
|
if (typeof distIcon === 'object' && typeof outIcon === 'object') {
|
||||||
distIcon.iconPath = replaceIconPathWithAccent(outIcon.iconPath, _accentName)
|
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.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_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath.replace('.svg', `.accent.${ _accentName }.svg`);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
getAccentableIcons().forEach(iconname => {
|
getAccentableIcons().forEach(iconname => {
|
||||||
let distIcon = (theme.iconDefinitions as any)[iconname];
|
let distIcon = getIconDefinition(theme.iconDefinitions, iconname);
|
||||||
let outIcon = (defaults.icons.theme.iconDefinitions as any)[iconname];
|
let outIcon = getIconDefinition(defaults.icons.theme.iconDefinitions, iconname);
|
||||||
|
|
||||||
distIcon.iconPath = outIcon.iconPath;
|
distIcon.iconPath = outIcon.iconPath;
|
||||||
});
|
});
|
||||||
theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.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_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`);
|
getVariantIcons().forEach(iconname => {
|
||||||
theme.iconDefinitions._folder_dark_build.iconPath = defaults.icons.theme.iconDefinitions._folder_dark_build.iconPath.replace('.svg', `${ variantName }.svg`);
|
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`);
|
if (!!distIcon && !!outIcon) {
|
||||||
theme.iconDefinitions["_folder_light_build"].iconPath = defaults.icons.theme.iconDefinitions["_folder_light_build"].iconPath.replace('.svg', `${ variantName }.svg`);
|
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) => {
|
fs.writeFile(themepath, JSON.stringify(theme), { encoding: CHARSET }, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -90,5 +90,12 @@
|
||||||
"Light High Contrast": "vs",
|
"Light High Contrast": "vs",
|
||||||
"Palenight": "vs-dark",
|
"Palenight": "vs-dark",
|
||||||
"Palenight High Contrast": "vs-dark"
|
"Palenight High Contrast": "vs-dark"
|
||||||
}
|
},
|
||||||
|
"variantsIcons": [
|
||||||
|
"_folder_dark_build",
|
||||||
|
"_folder_dark",
|
||||||
|
"_folder_light_build",
|
||||||
|
"_folder_light",
|
||||||
|
"_folder_vscode"
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -52,6 +52,13 @@ export function getAccentableIcons(): string[] {
|
||||||
return getDefaultValues().accentableIcons;
|
return getDefaultValues().accentableIcons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @export
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
export function getVariantIcons(): string[] {
|
||||||
|
return getDefaultValues().variantsIcons;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a theme content by a given contribute ID
|
* Gets a theme content by a given contribute ID
|
||||||
|
|
|
@ -6,6 +6,7 @@ export interface IDefaults {
|
||||||
themeVariants: IDefaultsThemeVariant;
|
themeVariants: IDefaultsThemeVariant;
|
||||||
themeVariantsColours: IDefaultsThemeVariantColours;
|
themeVariantsColours: IDefaultsThemeVariantColours;
|
||||||
themeVariantsUITheme: IDefaultsThemeVariantUITheme;
|
themeVariantsUITheme: IDefaultsThemeVariantUITheme;
|
||||||
|
variantsIcons: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAccents {
|
export interface IAccents {
|
||||||
|
|
Loading…
Reference in a new issue