-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: new and cleaner icons CLI scripts
- Loading branch information
Showing
17 changed files
with
423 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,91 @@ | ||
import { cp, readdir, writeFile } from 'node:fs/promises' | ||
import { basename, join } from 'node:path' | ||
import { exit } from 'node:process' | ||
import { flavorEntries } from '@catppuccin/palette' | ||
import { build } from 'tsup' | ||
import { rimraf } from 'rimraf' | ||
import { consola } from 'consola' | ||
import { compileTheme } from '~/utils/themes' | ||
|
||
const DIST = 'dist' | ||
const flavors = flavorEntries.map(([f]) => f) | ||
|
||
// cleanup | ||
await rimraf(DIST) | ||
|
||
// copy icons to dist | ||
await Promise.all(flavors.map(async (f) => { | ||
await cp(join('icons', f), join(DIST, f, 'icons'), { recursive: true }) | ||
})) | ||
|
||
// copy css-vars/unflavored icons to dist | ||
await cp(join('icons', 'css-variables'), join(DIST, 'unflavored'), { recursive: true }) | ||
|
||
// generate iconDefinitions.json file and save to dist | ||
const icons = await readdir(join(DIST, flavors[0], 'icons')) | ||
const iconDefinitions = icons.reduce((d, i) => ({ | ||
...d, | ||
[basename(i, '.svg')]: { iconPath: `./icons/${i}` }, | ||
}), {} as Record<string, { iconPath: string }>) | ||
await writeFile( | ||
join(DIST, 'iconDefinitions.json'), | ||
JSON.stringify(iconDefinitions, null, 2), | ||
) | ||
|
||
// compile theme.json and write to dist | ||
const theme = compileTheme({}, iconDefinitions) | ||
await Promise.all(flavors.map(async (f) => { | ||
try { | ||
consola.info('Deleting previous build...') | ||
|
||
// cleanup | ||
await rimraf(DIST) | ||
|
||
consola.success('Deleted previous build.') | ||
} | ||
catch (error) { | ||
consola.error('Failed to delete previous build: ', error) | ||
exit(1) | ||
} | ||
|
||
try { | ||
consola.info('Copying icon SVGs to dist...') | ||
|
||
// copy icons to dist | ||
await Promise.all(flavors.map(async (f) => { | ||
await cp(join('icons', f), join(DIST, f, 'icons'), { recursive: true }) | ||
})) | ||
|
||
// copy css-vars/unflavored icons to dist | ||
await cp(join('icons', 'css-variables'), join(DIST, 'unflavored'), { recursive: true }) | ||
|
||
consola.success('Copied icon SVGs to dist.') | ||
} | ||
catch (error) { | ||
consola.error('Failed to copy icon SVGs: ', error) | ||
exit(1) | ||
} | ||
|
||
try { | ||
consola.info('Building themes and icon definitions...') | ||
|
||
// generate iconDefinitions.json file and save to dist | ||
const icons = await readdir(join(DIST, flavors[0], 'icons')) | ||
const iconDefinitions = icons.reduce((d, i) => ({ | ||
...d, | ||
[basename(i, '.svg')]: { iconPath: `./icons/${i}` }, | ||
}), {} as Record<string, { iconPath: string }>) | ||
await writeFile( | ||
join(DIST, f, 'theme.json'), | ||
JSON.stringify(theme, null, 2), | ||
join(DIST, 'iconDefinitions.json'), | ||
JSON.stringify(iconDefinitions, null, 2), | ||
) | ||
})) | ||
|
||
// build extension runtime | ||
await build({ | ||
entry: ['src/main.ts', 'src/browser.ts'], | ||
format: ['cjs'], | ||
external: ['vscode'], | ||
minify: true, | ||
shims: true, | ||
}) | ||
|
||
// compile theme.json and write to dist | ||
const theme = compileTheme({}, iconDefinitions) | ||
await Promise.all(flavors.map(async (f) => { | ||
await writeFile( | ||
join(DIST, f, 'theme.json'), | ||
JSON.stringify(theme, null, 2), | ||
) | ||
})) | ||
|
||
consola.success('Built themes and icon definitions.') | ||
} | ||
catch (error) { | ||
consola.error('Failed to build themes or icon definitions: ', error) | ||
exit(1) | ||
} | ||
|
||
try { | ||
consola.info('Building VSC extension...') | ||
|
||
// build extension runtime | ||
await build({ | ||
entry: ['src/main.ts', 'src/browser.ts'], | ||
format: ['cjs'], | ||
external: ['vscode'], | ||
minify: true, | ||
shims: true, | ||
}) | ||
|
||
consola.success('Built VSC extension.') | ||
} | ||
catch (error) { | ||
consola.error('Failed to build VSC extension: ', error) | ||
exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.