Skip to content

Commit

Permalink
feat: ✨ integrate icon cloning with the the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-labs committed Apr 25, 2024
1 parent 7df7eb9 commit bc6abd7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ icons/folder.svg
icons/folder-open.svg
icons/folder-root.svg
icons/folder-root-open.svg
icons/clones

src/scripts/preview/*.html
src/scripts/contributors/*.html
4 changes: 3 additions & 1 deletion src/helpers/fileConfig.ts
Expand Up @@ -13,7 +13,9 @@ export const getFileConfigHash = (options: IconJsonOptions): string => {
options.saturation !== defaults.saturation ||
options.opacity !== defaults.opacity ||
options.folders?.color !== defaults.folders.color ||
options.files?.color !== defaults.files.color
options.files?.color !== defaults.files.color ||
(options.files?.customClones?.length ?? 0) > 0 ||
(options.folders?.customClones?.length ?? 0) > 0
) {
fileConfigString += `~${getHash(JSON.stringify(options))}`;
}
Expand Down
5 changes: 4 additions & 1 deletion src/icons/generator/iconOpacity.ts
@@ -1,4 +1,4 @@
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { lstatSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import { basename, join } from 'path';
import { getCustomIconPaths } from '../../helpers/customIcons';
import { IconJsonOptions } from '../../models';
Expand Down Expand Up @@ -89,6 +89,9 @@ const adjustOpacity = (
): ((value: string, index: number, array: string[]) => void) => {
return (iconFileName) => {
const svgFilePath = join(iconPath, iconFileName);
if (!lstatSync(svgFilePath).isFile()) {
return;
}

// Read SVG file
const svg = readFileSync(svgFilePath, 'utf-8');
Expand Down
5 changes: 4 additions & 1 deletion src/icons/generator/iconSaturation.ts
@@ -1,4 +1,4 @@
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { lstatSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import { basename, join } from 'path';
import { getCustomIconPaths } from '../../helpers/customIcons';
import { IconJsonOptions } from '../../models';
Expand Down Expand Up @@ -111,6 +111,9 @@ const adjustSaturation = (
): ((value: string, index: number, array: string[]) => void) => {
return (iconFileName) => {
const svgFilePath = join(iconsPath, iconFileName);
if (!lstatSync(svgFilePath).isFile()) {
return;
}

// Read SVG file
const svg = readFileSync(svgFilePath, 'utf-8');
Expand Down
7 changes: 6 additions & 1 deletion src/icons/generator/jsonGenerator.ts
Expand Up @@ -26,6 +26,7 @@ import {
validateOpacityValue,
validateSaturationValue,
} from './index';
import { customClonesIcons } from './clones/clonesGenerator';

/**
* Generate the complete icon configuration object that can be written as JSON file.
Expand Down Expand Up @@ -73,7 +74,7 @@ export const createIconFile = (
getDefaultIconOptions(),
updatedJSONConfig
);
const json = generateIconConfigurationObject(options);
let json = generateIconConfigurationObject(options);

// make sure that the folder color, opacity and saturation values are entered correctly
if (
Expand Down Expand Up @@ -131,6 +132,10 @@ export const createIconFile = (
setIconSaturation(options);
}
renameIconFiles(iconJsonPath, options);

// generate custom cloned icons after opacity and saturation have
// been set so that those changes are also applied to the clones
json = merge({}, json, customClonesIcons(json, options));
} catch (error) {
throw new Error('Failed to update icons: ' + error);
}
Expand Down

0 comments on commit bc6abd7

Please sign in to comment.