Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Sundrop SVG Sprite Builder - AI Instructions

## Available Scripts

Scan package.json and refer to the `scripts` property. Execute scripts using `bun run`. Relevant scripts for the dev workflow are:

- `format` - runs `prettier` on all source files
- `typecheck` - runs a project-wide static type check
- `lint` - runs eslint

### Unit Test Suite

Run unit test using `bun test`

## Workflow

- Run a static type check after you're done making any TypeScript changes.
- After making changes to any TypeScript or JavaScript file, run unit tests and verify passing status.
- Prior to committing anything to revision control, run the format script.

## Git Conventions

Commit messages should have a short, single-line summary of the changes made as the first line, followed by a blank line, followed by a markdown formatted bulleted list summarizing the most relevant changes made. Each bullet should also be a brief, single-line sentence.

Pull requests should always be submitted to the main upstream repository, `mgreen-simplethread/sundrop`, if you're working from a fork (check the value of `git remote show origin`).
94 changes: 55 additions & 39 deletions bin/sundrop.js → bin/sundrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,79 @@ import { hideBin } from 'yargs/helpers';
import { bundleSprites } from '../index';
import packageJSON from '../package.json';

const options = {
path: {
alias: 'p',
describe: 'Relative path or node module to search for icons',
type: 'array' as const,
},
out: {
alias: 'o',
describe: 'Output file',
type: 'string' as const,
demandOption: true,
},
files: {
alias: 'f',
describe: 'Glob of files to search for icon names',
type: 'string' as const,
default: './**/*.{html,css}',
},
alias: {
alias: 'a',
describe: 'Alias for icon name (alias_name:real_icon_name)',
type: 'array' as const,
coerce: (arg: string[]) =>
arg.reduce((obj: Record<string, string>, val: string) => {
const [alias, icon] = val.split(':');
if (!alias || !icon) return obj;
obj[alias] = icon;
return obj;
}, {}),
},
idPrefix: {
alias: 'i',
describe: 'Prefix string to add to icon symbol IDs',
type: 'string' as const,
default: 'icon-',
},
watch: {
alias: 'w',
describe: 'Watch for changes and rebuild sprite sheet',
type: 'boolean' as const,
},
};

const argv = yargs(hideBin(Bun.argv))
.usage(`$0 --path PATH_TO_ICONS --out OUTPUT_PATH --files GLOB`)
.scriptName('sundrop')
.pkgConf('sundrop')
.config(
'config',
'Path to JSON config file. Values set there are overridden by CLI flags.',
(file) => JSON.parse(readFileSync(file)),
(file) => JSON.parse(readFileSync(file).toString()),
)
.alias('config', 'c')
.alias('p', 'path')
.describe('p', 'Relative path or node module to search for icons')
.array('p')
.alias('o', 'out')
.describe('o', 'Output file')
.string('o')
.alias('f', 'files')
.string('f')
.describe('f', 'Glob of files to search for icon names')
.default('f', './**/*.{html,css}')
.alias('a', 'alias')
.array('a')
.describe('a', 'alias for icon name (alias_name:real_icon_name)')
.coerce('a', (arg) =>
arg.reduce((obj, val) => {
const [alias, icon] = val.split(':');
if (!alias || !icon) return obj;
obj[alias] = icon;
return obj;
}, {}),
)
.string('i')
.alias('i', 'idPrefix')
.describe('i', 'Prefix string to add to icon symbol IDs')
.default('i', 'icon-')
.boolean('w')
.alias('w', 'watch')
.describe('w', 'Watch for changes and rebuild sprite sheet')
.options(options)
.help()
.alias('help', 'h')
.version()
.alias('version', 'v')
.parse();
.parseSync();

const { out, path, alias: aliases = {}, files: searchPattern, idPrefix = '', watch = false } = argv;

const {
out,
path: paths,
alias: aliases = {},
files: searchPattern,
idPrefix = '',
watch = false,
} = argv;
const paths = path as string[] | undefined;

if (!out) {
console.error('Error: --out is required');
process.exit(1);
}

if (watch) {
console.log('Sundrop v%s started - watching project for changes.', packageJSON.version);

let timeout;
let timeout: ReturnType<typeof setTimeout> | null;

const debouncedBundler = () => {
if (timeout) clearTimeout(timeout);
Expand Down
20 changes: 9 additions & 11 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import eslint from '@eslint/js';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import globals from 'globals';

export default defineConfig([
eslint.configs.recommended,
tseslint.configs.recommended,
{
languageOptions: {
globals: {
...globals.bunBuiltin,
...globals.node,
},
},
},
]);

Loading