Skip to content

Commit

Permalink
ci: 🔄 add lucodear preview script
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-labs committed Jul 20, 2024
1 parent 7f8219f commit c688ee4
Show file tree
Hide file tree
Showing 7 changed files with 1,759 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"**/**/tests": true
},
"search.exclude": {
"out": true
"out": true,
".git": true
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome",
Expand Down
Binary file added images/lucodear-icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
"generateClones": "bun ./src/scripts/icons/generateClones.ts",
"lint": "bunx @biomejs/biome check --write ./src",
"format": "bunx @biomejs/biome format --write ./src",
"preversion": "bun run contributors && git add images/contributors.png && bun run preview && git add images/fileIcons.png && git add images/folderIcons.png && bun run svgo && git add icons/*.svg",
"preview": "bun ./src/scripts/preview/run.ts",
"preversion": "bun run contributors && bun run preview && git add images/*.png",
"preview": "bun ./src/scripts/preview/run.ts && bun run lc:preview",
"svgo": "svgo -i icons -o icons -q",
"test": "bun test",
"version": "bun run changelog && git add CHANGELOG.md",
"vscode:prepublish": "bun run lint && bun run build",
"verify": "bunx sheriff verify",
"prepublishOnly": "bun run ./src/scripts/module/prepare.ts",
"postpublish": "git checkout package.json && git checkout README.md"
"postpublish": "git checkout package.json && git checkout README.md",
"lc:preview": "bun ./src/@lucodear/scripts/preview"
},
"publisher": "lucaslabs",
"author": {
Expand Down
85 changes: 85 additions & 0 deletions src/@lucodear/scripts/preview/icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import type { FolderTheme } from '../../../core';
import type {
LucodearFolderIcon,
LucodearFolderTheme,
} from '../../core/models';

export type IconDefinition = {
name: string;
label?: string;
theme?: string;
};

export const filterDuplicates = <T extends { name: string }>(icons: T[]) => {
// duplicates have the same name
return icons.filter((icon, index, self) => {
return index === self.findIndex((i) => i.name === icon.name);
});
};

export const getFolders = (
icons: LucodearFolderTheme[] | FolderTheme[]
): IconDefinition[] => {
return filterDuplicates(
icons
.map((theme) => {
const folders = [];
if (theme.icons && theme.icons.length > 0) {
folders.push(
...theme.icons
.filter((i) => i.clone === undefined)
.map((i) => ({
name: i.name,
theme: (i as LucodearFolderIcon).theme,
}))
);
}
return [...folders];
})
.reduce((a, b) => a.concat(b))
).map((i) => ({
name: i.name,
label: i.name.replace('folder-', ''),
theme: i.theme,
}));
};

export const getFiles = (icons: IconDefinition[]): IconDefinition[] => {
return filterDuplicates(icons).map((i) => ({
name: i.name,
label: i.name.replace('file-', ''),
theme: i.theme,
}));
};

export type Theme = {
name: string;
hasFiles: boolean;
hasFolders: boolean;
};

export function getThemes(
folderIcons: { theme?: string }[],
filesIcons: { theme?: string }[]
): Theme[] {
const notUndefined = <T>(i: T | undefined): i is T => i !== undefined;

const folderThemes: string[] = folderIcons
.map((i) => i.theme)
.filter(notUndefined);
const fileThemes: string[] = filesIcons
.map((i) => i.theme)
.filter(notUndefined);

const themes: Theme[] = [...new Set([...folderThemes, ...fileThemes])].map(
(theme) => {
return {
name: theme,
hasFiles: fileThemes.includes(theme),
hasFolders: folderThemes.includes(theme),
};
}
);

return themes;
}
Loading

0 comments on commit c688ee4

Please sign in to comment.