Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: specificFolders customization option #85

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ We provide some options to further customize your catppuccin experience:

```jsonc
{
// hides arrows next to folders in explorer
"catppuccin-icons.hidesExplorerArrows": false
// set to true to disable folding arrows next to folder icons
"catppuccin-icons.hidesExplorerArrows": false,

// set to false to only use default folder icon
"catppuccin-icons.specificFolders": true
}
```

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"type": "boolean",
"default": false,
"description": "Hides arrows next to folders in the explorer."
},
"catppuccin-icons.specificFolders": {
"type": "boolean",
"default": true,
"description": "Display specific folder icons. Disable to only use default folder icon."
}
}
},
Expand Down
5 changes: 2 additions & 3 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { basename, join } from 'node:path'
import { flavorEntries } from '@catppuccin/palette'
import { build } from 'tsup'
import { rimraf } from 'rimraf'
import { defaults } from '~/defaults'
import { createVscTheme } from '~/hooks/generateTheme'
import { compileTheme } from '~/utils/themes'

const DIST = 'dist'
const flavors = flavorEntries.map(([f]) => f)
Expand All @@ -29,7 +28,7 @@ await writeFile(
)

// CREATE THEME AND INJECT ICON DEFINITIONS
const theme = createVscTheme(defaults, iconDefinitions)
const theme = compileTheme({}, iconDefinitions)

// WRITE THEMES
await Promise.all(flavors.map(async (f) => {
Expand Down
10 changes: 0 additions & 10 deletions src/defaults/baseIcons.ts

This file was deleted.

32 changes: 29 additions & 3 deletions src/defaults/fileIcons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { FileIcons } from '~/types'

export const fileIcons: FileIcons = {
const fileIcons: Record<string, {
languageIds?: Array<string>
fileExtensions?: Array<string>
fileNames?: Array<string>
}> = {
'adobe-ae': {
fileExtensions: ['aep'],
},
Expand Down Expand Up @@ -2528,3 +2530,27 @@ export const fileIcons: FileIcons = {
},

}

const { languageIds, fileExtensions, fileNames } = Object.entries(fileIcons).reduce(
({ languageIds, fileExtensions, fileNames }, [name, icon]) => ({
languageIds: {
...languageIds,
...icon.languageIds?.reduce((a, c) => ({ ...a, [c]: name }), {}),
},
fileExtensions: {
...fileExtensions,
...icon.fileExtensions?.reduce((a, c) => ({ ...a, [c]: name }), {}),
},
fileNames: {
...fileNames,
...icon.fileNames?.reduce((a, c) => ({ ...a, [c]: name }), {}),
},
}),
{
languageIds: {},
fileExtensions: {},
fileNames: {},
},
)

export { languageIds, fileExtensions, fileNames }
20 changes: 17 additions & 3 deletions src/defaults/folderIcons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FolderIcons } from '~/types'

export const folderIcons: FolderIcons = {
const folderIcons: Record<string, {
folderNames?: Array<string>
}> = {
'admin': {
folderNames: [
'admin',
Expand Down Expand Up @@ -608,3 +608,17 @@ export const folderIcons: FolderIcons = {
],
},
}

const { folderNames } = Object.entries(folderIcons).reduce(
({ folderNames }, [name, icon]) => ({
folderNames: {
...folderNames,
...icon.folderNames?.reduce((a, c) => ({ ...a, [c]: `folder_${name}` }), {}),
},
}),
{
folderNames: {},
},
)

export { folderNames }
24 changes: 13 additions & 11 deletions src/defaults/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { baseIcons } from './baseIcons'
import { fileIcons } from './fileIcons'
import { folderIcons } from './folderIcons'
import { options } from './options'
import { fileExtensions, fileNames, languageIds } from './fileIcons'
import { folderNames } from './folderIcons'
import type { Config } from '~/types'

import type { Theme } from '~/types'

export const defaults: Theme = {
...options,
...baseIcons,
fileIcons,
folderIcons,
export const defaultConfig: Config = {
hidesExplorerArrows: false,
specificFolders: true,
associations: {
languageIds,
fileExtensions,
fileNames,
folderNames,
},
monochrome: false,
}
5 changes: 0 additions & 5 deletions src/defaults/options.ts

This file was deleted.

21 changes: 21 additions & 0 deletions src/hooks/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ConfigurationTarget, workspace } from 'vscode'
import type { Config } from '~/types'

export function getConfig(): Partial<Config> {
const config = workspace.getConfiguration('catppuccin-icons')

return {
hidesExplorerArrows: config.get('hidesExplorerArrows'),
specificFolders: config.get('specificFolders'),
associations: config.get('associations'),
monochrome: config.get('monochrome'),
}
}

export async function resetConfig() {
const config = workspace.getConfiguration('catppuccin-icons')
await config.update('hidesExplorerArrows', undefined, ConfigurationTarget.Global)
await config.update('specificFolders', undefined, ConfigurationTarget.Global)
await config.update('associations', undefined, ConfigurationTarget.Global)
await config.update('monochrome', undefined, ConfigurationTarget.Global)
}
54 changes: 0 additions & 54 deletions src/hooks/generateTheme.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/hooks/iconDefinitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Uri, workspace } from 'vscode'
import type { ExtensionContext } from 'vscode'
import type { IconDefinitions } from '~/types'

export async function getIconDefinitions(context: ExtensionContext) {
const path = Uri.joinPath(context.extensionUri, 'dist', 'iconDefinitions.json')
return workspace.fs.readFile(path).then(f => JSON.parse(f.toString()) as IconDefinitions)
}
43 changes: 15 additions & 28 deletions src/utils/vscode.ts → src/hooks/interactions.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,18 @@
/**
* Functions to interact with VSCode window/workspace
*/
import { Buffer } from 'node:buffer'
import type { ExtensionContext, Uri } from 'vscode'
import { commands, window, workspace } from 'vscode'
import { flagPath } from './paths'
import type { Config } from '~/types'

export async function writeFile(uri: Uri, content: unknown) {
return workspace.fs
.writeFile(uri, Buffer.from(JSON.stringify(content, null, 2)))
.then(
() => {},
(error: Error) => {
window.showErrorMessage(error.message)
},
)
}
import { Uri, commands, window, workspace } from 'vscode'
import type { ExtensionContext } from 'vscode'

export async function promptToReload() {
const message = `Catppuccin Icons: Theme changed - Reload required.`
const action = 'Reload window'
await window.showInformationMessage(message, action).then(async (selectedAction) => {
return window.showInformationMessage(message, action).then(async (selectedAction) => {
if (selectedAction === action)
commands.executeCommand('workbench.action.reloadWindow')
})
};

export function getConfiguration(): Config {
const config = workspace.getConfiguration('catppuccin-icons')

return {
hidesExplorerArrows: config.get('hidesExplorerArrows', false),
}
}

export async function isFreshInstall(context: ExtensionContext) {
const flag = flagPath(context)
const flag = Uri.joinPath(context.extensionUri, 'dist', '.flag')
return await workspace.fs.stat(flag).then(
() => false,
() => workspace.fs.writeFile(flag, Buffer.from('')).then(
Expand All @@ -45,3 +21,14 @@ export async function isFreshInstall(context: ExtensionContext) {
),
)
}

export async function writeJsonFile(uri: Uri, content: unknown) {
return workspace.fs
.writeFile(uri, Buffer.from(JSON.stringify(content, null, 2)))
.then(
() => {},
(error: Error) => {
window.showErrorMessage(error.message)
},
)
}
9 changes: 0 additions & 9 deletions src/hooks/mergeTheme.ts

This file was deleted.

34 changes: 34 additions & 0 deletions src/hooks/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Uri } from 'vscode'
import type { ExtensionContext } from 'vscode'
import type { ThemePaths } from '~/types'

function getRootPath(context: ExtensionContext) {
return Uri.joinPath(context.extensionUri, 'dist')
}

export function getFlagPath(context: ExtensionContext) {
const root = getRootPath(context)
return Uri.joinPath(root, '.flag')
}

export function getThemePaths(context: ExtensionContext): ThemePaths {
const root = getRootPath(context)
return {
frappe: {
icons: Uri.joinPath(root, 'latte', 'icons'),
theme: Uri.joinPath(root, 'latte', 'theme.json'),
},
latte: {
icons: Uri.joinPath(root, 'latte', 'icons'),
theme: Uri.joinPath(root, 'latte', 'theme.json'),
},
macchiato: {
icons: Uri.joinPath(root, 'macchiato', 'icons'),
theme: Uri.joinPath(root, 'macchiato', 'theme.json'),
},
mocha: {
icons: Uri.joinPath(root, 'mocha', 'icons'),
theme: Uri.joinPath(root, 'mocha', 'theme.json'),
},
}
}
Loading
Loading