Skip to content

Commit

Permalink
feat: add --noSandbox flag
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed Jan 21, 2025
1 parent 4ce5110 commit c6b66ac
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 279 deletions.
186 changes: 108 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,108 @@
<h1 align="center">
<br>
<img src="./logo.png" alt="logo" width="200">
<br><br>
SVG Icon Review
<br>
<br>
</h1>

<h4 align="center">Tool to review SVG icons automatically</h4>

## CLI Command

The tool can be executed with this command:

```
bunx svg-icon-review file1.svg file2.svg
```

It also supports glob file patterns to check multiple files matching the pattern like this:

```
bunx svg-icon-review ./images/**/*.svg
```

The output is a preview of how the icons look in either dark or light backgrounds:

<img src="./images/preview.png" alt="logo" >

## Options

Optionally, an additional bigger icon (in size of 32x32px) will be shown in front of the preview. This is useful to see the icon in more detail. This can be done by adding the `--bigIcon` option like this:

```bash
bunx svg-icon-review --bigIcon file1.svg file2.svg
```

The preview will look like this:

<img src="./images/preview-big-icon.png" alt="logo" >

If further help is needed, the `--help` option can be used:

```bash
bunx svg-icon-review --help
```

> Instead of "bunx" you can use "npx" if you prefer Node.js.
## Development

For the development of this tool, Bun.js is used. First you have to install the dependencies:

```bash
bun install
```

Then you can run the tool with:

```bash
bun run start
```

It is going to create a preview image of the logo.svg file in the root directory.

### Formatting and Linting

To format the code, run:

```bash
bun run format
```

To lint the code, run:

```bash
bun run lint
```
<h1 align="center">
<br>
<img src="./logo.png" alt="logo" width="200">
<br><br>
SVG Icon Review
<br>
<br>
</h1>

<h4 align="center">Tool to review SVG icons automatically</h4>

## CLI Command

The tool can be executed with this command:

```
bunx svg-icon-review file1.svg file2.svg
```

It also supports glob file patterns to check multiple files matching the pattern like this:

```
bunx svg-icon-review ./images/**/*.svg
```

The output is a preview of how the icons look in either dark or light backgrounds:

<img src="./images/preview.png" alt="logo" >

## Options

### `--bigIcon`

Optionally, an additional bigger icon (in size of 32x32px) will be shown in front of the preview. This is useful to see the icon in more detail. This can be done by adding the `--bigIcon` option like this:

```bash
bunx svg-icon-review --bigIcon file1.svg file2.svg
```

The preview will look like this:

<img src="./images/preview-big-icon.png" alt="logo" >

### `--silent`

By default, the tool will output a result message to the console. If you want to avoid this output, you can use the `--silent` option:

```bash
bunx svg-icon-review --silent file1.svg file2.svg
```

### `--debug`

If you want to see the debug information, you can use the `--debug` option:

```bash
bunx svg-icon-review --debug file1.svg file2.svg
```

### `--noSandbox`

By default, the tool uses a sandboxed environment to render the SVG icons. If you want to disable this sandbox, you can use the `--noSandbox` option:

```bash
bunx svg-icon-review --noSandbox file1.svg file2.svg
```

Running without a sandbox is strongly discouraged because of security risks. Consider configuring a sandbox instead. If you absolutely trust the content you with this tool, you can launch it with the --noSandbox argument.

### `--help`

If further help is needed, the `--help` option can be used:

```bash
bunx svg-icon-review --help
```

> Instead of "bunx" you can use "npx" if you prefer Node.js.
## Development

For the development of this tool, Bun.js is used. First you have to install the dependencies:

```bash
bun install
```

Then you can run the tool with:

```bash
bun run start
```

It is going to create a preview image of the logo.svg file in the root directory.

### Formatting and Linting

To format the code, run:

```bash
bun run format
```

To lint the code, run:

```bash
bun run lint
```
41 changes: 21 additions & 20 deletions src/cli/commands/printHelp.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const printHelp = () => {
return console.log(
`
Usage
$ npx svg-icon-review mySvgFile.svg anotherSvgFile.svg
Usage with glob pattern
$ npx svg-icon-review ./icons/*.svg
Options
--bigIcons, -b Show big icons in front of the small icons
--debug, -d Show generated HTML
--help, -h Show help
--silent, -s Not showing any output
--version, -v Show version
`
);
};

export { printHelp };
const printHelp = () => {
return console.log(
`
Usage
$ npx svg-icon-review mySvgFile.svg anotherSvgFile.svg
Usage with glob pattern
$ npx svg-icon-review ./icons/*.svg
Options
--bigIcons, -b Show big icons in front of the small icons
--debug, -d Show generated HTML
--help, -h Show help
--silent, -s Not showing any output
--version, -v Show version
--noSandbox, -n Run without using a sandbox
`
);
};

export { printHelp };
63 changes: 36 additions & 27 deletions src/cli/config/flags.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
import minimist from 'minimist';
import { Config } from '../../core';

export type CliFlags = {
version?: boolean;
help?: boolean;
debug?: boolean;
silent?: boolean;
bigIcon?: boolean;
};

const flags: minimist.Opts | undefined = {
boolean: [
'version',
'help',
'debug',
'silent',
'bigIcon',
] satisfies (keyof (CliFlags & Config))[],
alias: { v: 'version', h: 'help', d: 'debug', s: 'silent', b: 'bigIcon' },
unknown: (a) => true,
default: { lang: 'en' },
'--': true,
stopEarly: true,
};

export { flags };
import minimist from 'minimist';
import { Config } from '../../core';

export type CliFlags = {
version?: boolean;
help?: boolean;
debug?: boolean;
silent?: boolean;
bigIcon?: boolean;
noSandbox?: boolean;
};

const flags: minimist.Opts | undefined = {
boolean: [
'version',
'help',
'debug',
'silent',
'bigIcon',
'noSandbox',
] satisfies (keyof (CliFlags & Config))[],
alias: {
v: 'version',
h: 'help',
d: 'debug',
s: 'silent',
b: 'bigIcon',
n: 'noSandbox',
},
unknown: (a) => true,
default: { lang: 'en' },
'--': true,
stopEarly: true,
};

export { flags };
71 changes: 36 additions & 35 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import minimist from 'minimist';
import { Config } from '../core';
import { printHelp } from './commands/printHelp';
import { printResults } from './commands/printResults';
import { printVersion } from './commands/printVersion';
import { CliFlags, flags } from './config/flags';

const run = async () => {
const args = minimist<Partial<CliFlags & Config>>(
process.argv.slice(2),
flags
);

if (args.version) {
printVersion();
return;
}
if (args.help) {
printHelp();
return;
}

await printResults(args._, {
debug: args.debug ?? false,
silent: args.silent ?? false,
bigIcon: args.bigIcon ?? false,
});
};

try {
run();
} catch (error) {
console.log(error);
throw error;
}
import minimist from 'minimist';
import { Config } from '../core';
import { printHelp } from './commands/printHelp';
import { printResults } from './commands/printResults';
import { printVersion } from './commands/printVersion';
import { CliFlags, flags } from './config/flags';

const run = async () => {
const args = minimist<Partial<CliFlags & Config>>(
process.argv.slice(2),
flags
);

if (args.version) {
printVersion();
return;
}
if (args.help) {
printHelp();
return;
}

await printResults(args._, {
debug: args.debug ?? false,
silent: args.silent ?? false,
bigIcon: args.bigIcon ?? false,
noSandbox: args.noSandbox ?? false,
});
};

try {
run();
} catch (error) {
console.log(error);
throw error;
}
Loading

0 comments on commit c6b66ac

Please sign in to comment.