-
Notifications
You must be signed in to change notification settings - Fork 95
/
sync-vscode-icons
executable file
·85 lines (68 loc) · 1.99 KB
/
sync-vscode-icons
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
//
// Patch Catppuccin Latte icons for VS Code with Squirrelsong color palette.
// > More information: <https://github.com/catppuccin/vscode-icons>.
//
// ---
// Based on <https://github.com/sapegin/dotfiles/blob/master/bin/sync-vscode-icons>
//
// Author: Nick Plekhanov, https://nikkhan.com/
// License: MIT
// https://github.com/nicksp/dotfiles
const path = require('node:path')
const fs = require('node:fs')
const { globSync } = require('glob')
const os = require('node:os')
const PALETTE = {
'#04a5e5': '#80a4be',
'#179299': '#5f9b8d',
'#1e66f5': '#80a4be',
'#209fb5': '#5f9b8d',
'#40a02b': '#9bae7e',
'#4c4f69': '#78737d',
'#7287fd': '#ac9bc5',
'#8839ef': '#806f9b',
'#8c8fa1': '#a8a1af',
'#d20f39': '#c06159',
'#dc8a78': '#d67e76',
'#dd7878': '#d67e76',
'#df8e1d': '#de9e59',
'#e64553': '#c06159',
'#ea76cb': '#e87da4',
'#fe640b': '#e4c158',
'#fff': '#fff',
}
const ALL_COLORS = [...Object.keys(PALETTE), ...Object.values(PALETTE)]
const HOME = os.homedir() ?? process.env.HOME
const [extensionRoot] = globSync(
`${HOME}/.vscode/extensions/catppuccin.catppuccin-vsc-icons-*`
)
if (extensionRoot === undefined) {
console.error('Catppuccin is not installed')
process.exit(1)
}
console.log()
console.log('[VSCODE] Updating icons… 👾')
console.log()
const icons = globSync(`${extensionRoot}/dist/latte/icons/*.svg`)
const invalidColors = {}
for (const file of icons) {
console.log('👉🏼', path.basename(file))
const svg = fs.readFileSync(file, 'utf8')
const nextSvg = svg.replaceAll(/(#[0-9a-f]{3,8})/g, (_, color) => {
if (ALL_COLORS.includes(color) === false) {
invalidColors[color] = true
}
return PALETTE[color] ?? color
})
if (nextSvg.includes('undefined')) {
console.error('🪲 Undefined detected', nextSvg)
}
fs.writeFileSync(file, nextSvg)
}
console.log()
for (const color of Object.keys(invalidColors)) {
console.error(`🦜 Unknown color: ${color}`)
}
console.log()
console.log('[VSCODE] Done 🦜')