Skip to content

Commit

Permalink
Restructure methods
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed Apr 5, 2023
1 parent 37da25c commit 637f3b1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
24 changes: 24 additions & 0 deletions src/helpers/svg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { writeFileSync } from 'fs';
import { basename, join } from 'path';

export const getPath = (d: string, color: string) =>
`<path d="${d}" fill="${color}" />`;

export const getSvg = (path: string) =>
`<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">${path}</svg>`;

export const writeSvgFiles = (iconName: string, svg: string) => {
let iconsPath;
if (basename(__dirname) === 'dist') {
iconsPath = join(__dirname, '..', 'icons');
} else {
// executed via script
iconsPath = join(__dirname, '..', '..', '..', 'icons');
}
const iconsFolderPath = join(iconsPath, `${iconName}.svg`);
try {
writeFileSync(iconsFolderPath, svg);
} catch (error) {
console.error(error);
}
};
10 changes: 3 additions & 7 deletions src/icons/generator/fileGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import merge from 'lodash.merge';
import { getFileConfigHash } from '../../helpers/fileConfig';
import { getPath, getSvg, writeSvgFiles } from '../../helpers/svg';
import {
FileIcon,
FileIcons,
Expand All @@ -13,12 +14,7 @@ import {
lightColorFileEnding,
wildcardPattern,
} from './constants';
import {
validateHEXColorCode,
writeSVGFiles,
getSVG,
getPath,
} from './folderGenerator';
import { validateHEXColorCode } from './folderGenerator';

/**
* Get all file icons that can be used in this theme.
Expand Down Expand Up @@ -207,7 +203,7 @@ export const generateFileIcons = (color: string | undefined) => {
const fileIcon =
'M13 9h5.5L13 3.5V9M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4c0-1.11.89-2 2-2m5 2H6v16h12v-9h-7V4z';

writeSVGFiles('file', getSVG(getPath(fileIcon, color)));
writeSvgFiles('file', getSvg(getPath(fileIcon, color)));
};

const getCustomIcons = (fileAssociations: IconAssociations | undefined) => {
Expand Down
32 changes: 5 additions & 27 deletions src/icons/generator/folderGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { writeFileSync } from 'fs';
import merge from 'lodash.merge';
import { basename, join } from 'path';
import { getFileConfigHash } from '../../helpers/fileConfig';
import { getPath, getSvg, writeSvgFiles } from '../../helpers/svg';
import {
DefaultIcon,
FolderIcon,
Expand Down Expand Up @@ -303,31 +302,10 @@ export const generateFolderIcons = (color: string | undefined) => {
const rootFolderIconOpen =
'M12 20a8 8 0 0 1-8-8 8 8 0 0 1 8-8 8 8 0 0 1 8 8 8 8 0 0 1-8 8m0-18A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2z';

writeSVGFiles('folder', getSVG(getPath(folderIcon, color)));
writeSVGFiles('folder-open', getSVG(getPath(folderIconOpen, color)));
writeSVGFiles('folder-root', getSVG(getPath(rootFolderIcon, color)));
writeSVGFiles('folder-root-open', getSVG(getPath(rootFolderIconOpen, color)));
};

export const getPath = (d: string, color: string) =>
`<path d="${d}" fill="${color}" />`;
export const getSVG = (path: string) =>
`<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">${path}</svg>`;

export const writeSVGFiles = (iconName: string, svg: string) => {
let iconsPath;
if (basename(__dirname) === 'dist') {
iconsPath = join(__dirname, '..', 'icons');
} else {
// executed via script
iconsPath = join(__dirname, '..', '..', '..', 'icons');
}
const iconsFolderPath = join(iconsPath, `${iconName}.svg`);
try {
writeFileSync(iconsFolderPath, svg);
} catch (error) {
console.error(error);
}
writeSvgFiles('folder', getSvg(getPath(folderIcon, color)));
writeSvgFiles('folder-open', getSvg(getPath(folderIconOpen, color)));
writeSvgFiles('folder-root', getSvg(getPath(rootFolderIcon, color)));
writeSvgFiles('folder-root-open', getSvg(getPath(rootFolderIconOpen, color)));
};

/**
Expand Down

0 comments on commit 637f3b1

Please sign in to comment.