diff --git a/bun.lockb b/bun.lockb index 42b0b02..c285ecb 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index a9cc13f..94fc6f7 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ }, "devDependencies": { "@biomejs/biome": "^1.8.3", + "@types/bun": "^1.1.6", "@types/glob": "^8.1.0", "@types/is-glob": "^4.0.4", "@types/minimist": "^1.2.5", diff --git a/src/cli/commands/printHelp.ts b/src/cli/commands/printHelp.ts index 217e80e..2d7392a 100644 --- a/src/cli/commands/printHelp.ts +++ b/src/cli/commands/printHelp.ts @@ -13,6 +13,7 @@ const printHelp = () => { --help, -h Show help --silent, -s Not showing any output --version, -v Show version + --previewFile, -p Specify a custom name for the output file. If not provided, no file will be generated. ` ); }; diff --git a/src/cli/config/flags.ts b/src/cli/config/flags.ts index f7faac0..db4896b 100644 --- a/src/cli/config/flags.ts +++ b/src/cli/config/flags.ts @@ -7,6 +7,7 @@ export type CliFlags = { debug?: boolean; silent?: boolean; bigIcon?: boolean; + previewFile?: string; // Allows specifying a custom name for the output file using a --preview-file flag }; const flags: minimist.Opts | undefined = { @@ -17,7 +18,15 @@ const flags: minimist.Opts | undefined = { 'silent', 'bigIcon', ] satisfies (keyof (CliFlags & Config))[], - alias: { v: 'version', h: 'help', d: 'debug', s: 'silent', b: 'bigIcon' }, + string: ['previewFile'], + alias: { + v: 'version', + h: 'help', + d: 'debug', + s: 'silent', + b: 'bigIcon', + p: 'previewFile', + }, unknown: (a) => true, default: { lang: 'en' }, '--': true, diff --git a/src/cli/index.ts b/src/cli/index.ts index bce38f7..d322919 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -24,6 +24,7 @@ const run = async () => { debug: args.debug ?? false, silent: args.silent ?? false, bigIcon: args.bigIcon ?? false, + previewFile: args.previewFile, }); }; diff --git a/src/core/generate-preview.ts b/src/core/generate-preview.ts index 9e3263d..9ab43b8 100644 --- a/src/core/generate-preview.ts +++ b/src/core/generate-preview.ts @@ -9,8 +9,16 @@ import { createScreenshot } from './utils/screenshot'; * Generates a preview of dark and light theme of SVG icons. * * @param fileNames List of SVG file names + * @param config Configuration including custom name for the output file. If not provided, no file will be generated. */ export const generatePreview = async (fileNames: string[], config: Config) => { + if (!config.previewFile) { + console.log( + red('No output file name provided. Skipping preview generation.') + ); + return; + } + const darkTheme = createTheme( 'dark', fileNames.filter((f) => !f.includes('_light')), @@ -34,7 +42,7 @@ export const generatePreview = async (fileNames: string[], config: Config) => { writeFileSync(previewHtmlPath, previewTemplate); try { - await createScreenshot(previewHtmlPath, 'preview'); + await createScreenshot(previewHtmlPath, config.previewFile); if (config.silent) return; if (config.debug) { @@ -46,7 +54,7 @@ export const generatePreview = async (fileNames: string[], config: Config) => { green(`Successfully created preview image!`) ); } catch (error) { - throw Error(red(`Error while creating preview image`)); + throw Error(red(`Error while creating preview image`)); } }; diff --git a/src/core/models/config.ts b/src/core/models/config.ts index 0c5dd97..609be7d 100644 --- a/src/core/models/config.ts +++ b/src/core/models/config.ts @@ -2,4 +2,5 @@ export type Config = { debug?: boolean; silent?: boolean; bigIcon?: boolean; + previewFile?: string; };