Skip to content

Commit

Permalink
feat: ✨ allow loose folder and file icons
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-labs committed Apr 7, 2024
1 parent 99eee86 commit 91f2eef
Showing 11 changed files with 1,262 additions and 1,220 deletions.
1 change: 1 addition & 0 deletions icons-lc/misc/folder-calendar-open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions icons-lc/misc/folder-calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,390 changes: 1,193 additions & 1,197 deletions icons-lc/misc/~misc.ai

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/icons/generator/folderGenerator.ts
Original file line number Diff line number Diff line change
@@ -223,7 +223,7 @@ export const setFolderNames = (
folderNames: {},
folderNamesExpanded: {},
};
folderNames.forEach((name) => {
folderNames?.forEach((name) => {
if (obj.folderNames) {
obj.folderNames[name as keyof IconConfiguration] = iconName + appendix;
}
10 changes: 5 additions & 5 deletions src/lucodear/dups/fileGenerator.ts
Original file line number Diff line number Diff line change
@@ -50,15 +50,15 @@ export const loadLucodearFileIconDefinitions = (
config = merge(
{},
config,
mapSpecificFileIcons(icon, FileMappingType.FileExtensions)
mapSpecificFileIcons(icon as FileIcon, FileMappingType.FileExtensions)
);
}
if (icon.fileNames) {
config = merge(
{},
config,
mapSpecificFileIcons(
icon,
icon as FileIcon,
FileMappingType.FileNames,
options.files?.associations
)
@@ -132,7 +132,7 @@ export const loadLucodearFileIconDefinitions = (
const disableIconsByPack = (
fileIcons: LucodearFileIcons,
activatedIconPack: string
): FileIcon[] => {
): LucodearFileIcon[] => {
return fileIcons.icons.filter((icon) => {
return !icon.enabledFor
? true
@@ -169,8 +169,8 @@ export const setFileIconDefinition = (
typeof icon === 'string'
? ''
: icon.theme === undefined
? ''
: `${icon.theme}/`;
? ''
: `${icon.theme}/`;

const obj: Partial<IconConfiguration> = { iconDefinitions: {} };
if (config.options) {
2 changes: 1 addition & 1 deletion src/lucodear/dups/folderGenerator.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ export const loadLucodearFolderIconDefinitions = (
config = merge({}, config);
config.hidesExplorerArrows = options.hidesExplorerArrows;
const activeTheme = getEnabledFolderTheme(
folderThemes,
folderThemes as FolderTheme[],
options.folders?.theme
);
if (!activeTheme) {
25 changes: 24 additions & 1 deletion src/lucodear/icons/misc/folders.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,25 @@ export const folders = lucodear('misc', [
name: 'bin',
folderNames: ['bin', 'binary', 'binaries', 'bins'],
},
{
name: 'calendar',
folderNames: [
'calendar',
'calendars',
'agenda',
'schedule',
'schedules',
'sched',
],
},
{
name: 'binance',
looseFolderIcon: true,
},
{
name: 'cocos-cap',
looseFolderIcon: true,
},
{
name: 'controller',
folderNames: ['controller', 'controllers', 'ctrl'],
@@ -189,4 +208,8 @@ export const folders = lucodear('misc', [
name: 'workflow',
folderNames: ['workflow', 'workflows', 'flow', 'flows'],
},
] as LucodearFolderIcon[]);
{
name: 'yahoo',
looseFolderIcon: true,
},
] satisfies LucodearFolderIcon[]);
16 changes: 11 additions & 5 deletions src/lucodear/icons/utils.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,11 @@ const isIconPackArray = (p: any): p is IconPack[] => {
};

const isFolderIcon = (i: any): i is LucodearFolderIcon => {
return i.folderNames !== undefined;
return (
i !== undefined &&
i !== null &&
(i.folderNames !== undefined || i.looseFolderIcon === true)
);
};

export function lucodear<T extends LucodearIconConfig>(
@@ -57,10 +61,12 @@ function addPrefixes<T extends LucodearIconConfig>(
return icons.map((icon) => {
if (isFolderIcon(icon)) {
// add prefixes to folder names (@folder, ~folder, =folder)
icon.folderNames.forEach((folderName) => {
icon.folderNames = icon.folderNames.concat(
prefixes.map((prefix) => `${prefix}${folderName}`)
);
icon.folderNames?.forEach((folderName) => {
if (icon.folderNames) {
icon.folderNames = icon.folderNames.concat(
prefixes.map((prefix) => `${prefix}${folderName}`)
);
}
});

// check if the icon starts with folder- and if not, add it
30 changes: 22 additions & 8 deletions src/lucodear/model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RequireAtLeastOne } from '../helpers/types';
import {
DefaultIcon,
FileIcon,
BasicFileIcon,
FolderIcon,
FolderTheme,
IconAssociations,
@@ -22,19 +23,32 @@ export interface ExtendedOptions extends IconJsonOptions {
lucodear: LucodearOptions;
}

export type LucodearFileIcon = FileIcon & {
theme?: string;
};
export type LucodearFileIcon = RequireAtLeastOne<
BasicFileIcon & {
looseFileIcon?: true;
theme?: string;
},
'fileExtensions' | 'fileNames' | 'looseFileIcon'
>;

export interface LucodearFileIcons {
defaultIcon?: DefaultIcon;
icons: LucodearFileIcon[];
}

export interface LucodearFolderIcon extends FolderIcon {
theme?: string;
}
export type LucodearFolderIcon = RequireAtLeastOne<
Omit<FolderIcon, 'folderNames'> & {
theme?: string;
looseFolderIcon?: true;
/**
* Define the folder names that should apply the icon.
* E.g. ['src', 'source']
*/
folderNames?: string[];
},
'looseFolderIcon' | 'folderNames'
>;

export interface LucodearFolderTheme extends FolderTheme {
export interface LucodearFolderTheme extends Omit<FolderTheme, 'icons'> {
icons: LucodearFolderIcon[];
}
2 changes: 1 addition & 1 deletion src/models/icons/files/fileIcon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RequireAtLeastOne } from '../../../helpers/types';
import { IconPack } from '../index';

interface BasicFileIcon {
export interface BasicFileIcon {
/**
* Name of the icon, e.g. 'javascript'
*/
3 changes: 2 additions & 1 deletion src/scripts/icons/checks/checkIconUsage.ts
Original file line number Diff line number Diff line change
@@ -117,9 +117,10 @@ const getAllUsedFileIcons = (): string[] => {

const getAllUsedFolderIcons = (): string[] => {
const icons = folderIcons
.concat(lucodearFolderIcons)
.concat(lucodearFolderIcons as FolderTheme)
.map((theme) => (theme.name === 'none' ? [] : getAllFolderIcons(theme)))
.reduce((a, b) => a.concat(b));

return icons
.map((icon) => {
return [

0 comments on commit 91f2eef

Please sign in to comment.