Skip to content

Commit

Permalink
Add --preview-file flag
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed Jul 1, 2024
1 parent b76b878 commit a2fb8d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/cli/commands/printHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
`
);
};
Expand Down
6 changes: 5 additions & 1 deletion src/cli/config/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -17,7 +18,10 @@ 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,
Expand Down
1 change: 1 addition & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const run = async () => {
debug: args.debug ?? false,
silent: args.silent ?? false,
bigIcon: args.bigIcon ?? false,
previewFile: args.previewFile,
});
};

Expand Down
10 changes: 8 additions & 2 deletions src/core/generate-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ 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')),
Expand All @@ -34,7 +40,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) {
Expand All @@ -46,7 +52,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`));
}
};

Expand Down

0 comments on commit a2fb8d7

Please sign in to comment.