From 5be67baba29f52ab5f7423b8ace6b082dbc27260 Mon Sep 17 00:00:00 2001 From: PKief Date: Sun, 6 Sep 2020 12:57:14 +0200 Subject: [PATCH] Fix #827 --- src/icons/generator/jsonGenerator.ts | 47 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/icons/generator/jsonGenerator.ts b/src/icons/generator/jsonGenerator.ts index 12ebe57079..885f82c274 100644 --- a/src/icons/generator/jsonGenerator.ts +++ b/src/icons/generator/jsonGenerator.ts @@ -1,7 +1,8 @@ import * as fs from 'fs'; import * as merge from 'lodash.merge'; import * as path from 'path'; -import { getFileConfigString } from '../../helpers/fileConfig'; +import { getCustomIconPaths } from '../../helpers/customIcons'; +import { getFileConfigHash } from '../../helpers/fileConfig'; import { IconConfiguration, IconJsonOptions } from '../../models/index'; import { fileIcons } from '../fileIcons'; import { folderIcons } from '../folderIcons'; @@ -43,6 +44,11 @@ export const createIconFile = (updatedConfigs?: IconJsonOptions, updatedJSONConf } try { + let iconJsonPath = __dirname; + // if executed via script + if (path.basename(__dirname) !== 'dist') { + iconJsonPath = path.join(__dirname, '..', '..', '..', 'dist'); + } if (!updatedConfigs || (updatedConfigs.folders || {}).color) { // if updatedConfigs do not exist (because of initial setup) // or new config value was detected by the change detection @@ -55,11 +61,6 @@ export const createIconFile = (updatedConfigs?: IconJsonOptions, updatedJSONConf if (!updatedConfigs || updatedConfigs.saturation !== undefined) { setIconSaturation(options.saturation); } - let iconJsonPath = __dirname; - // if executed via script - if (path.basename(__dirname) !== 'dist') { - iconJsonPath = path.join(__dirname, '..', '..', '..', 'dist'); - } renameIconFiles(iconJsonPath, options); } catch (error) { throw Error(error); @@ -102,20 +103,26 @@ export const getDefaultIconOptions = (): IconJsonOptions => ({ * @param options Icon Json Options */ const renameIconFiles = (iconJsonPath: string, options: IconJsonOptions) => { - fs.readdirSync(path.join(iconJsonPath, '..', 'icons')) - .filter(f => f.match(/\.svg/gi)) - .forEach(f => { - const filePath = path.join(iconJsonPath, '..', 'icons', f); - const fileConfig = getFileConfigString(options); + const customPaths = getCustomIconPaths(options); + const defaultIconPath = path.join(iconJsonPath, '..', 'icons'); + const iconPaths = [defaultIconPath, ...customPaths]; + + iconPaths.forEach(iconPath => { + fs.readdirSync(iconPath) + .filter(f => f.match(/\.svg/gi)) + .forEach(f => { + const filePath = path.join(iconPath, f); + const fileConfigHash = getFileConfigHash(options); - // append file config to file name - const newFilePath = path.join(iconJsonPath, '..', 'icons', f.replace(/(^[^\.~]+)(.*)\.svg/, `$1${fileConfig}.svg`)); + // append file config to file name + const newFilePath = path.join(iconPath, f.replace(/(^[^\.~]+)(.*)\.svg/, `$1${fileConfigHash}.svg`)); - // if generated files are already in place, do not overwrite them - if (filePath !== newFilePath && fs.existsSync(newFilePath)) { - fs.unlinkSync(filePath); - } else { - fs.renameSync(filePath, newFilePath); - } - }); + // if generated files are already in place, do not overwrite them + if (filePath !== newFilePath && fs.existsSync(newFilePath)) { + fs.unlinkSync(filePath); + } else { + fs.renameSync(filePath, newFilePath); + } + }); + }); };