Skip to content
Open
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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@ Easily generate color shades for themes

## Usage

You can use the CLI for fast generation or use the programmatic API for more control.

### CLI

```bash
npx theme-colors <color>
```

Example:

```bash
npx theme-colors "#ABABAB" # Be careful and add doubles quotes
```

This will generate the following shades:

```js
{
50: '#FBFBFB',
100: '#F7F7F7',
200: '#EAEAEA',
300: '#DDDDDD',
400: '#C4C4C4',
500: '#ABABAB',
600: '#9A9A9A',
700: '#676767',
800: '#4D4D4D',
900: '#333333',
950: '#222222',
}
```

### Programmatic

Install package:

```sh
Expand Down
3 changes: 3 additions & 0 deletions bin/theme-colors.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { main, runMain } from "../dist/cli/index.mjs"

runMain(main)
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@
"require": "./dist/index.cjs"
}
},
"bin": {
"theme-colors": "./bin/theme-colors.mjs"
},
"main": "dist/index.cjs",
"module": "./dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist",
"bin"
],
"scripts": {
"build": "unbuild",
"build:stub": "unbuild --stub",
"dev": "vitest dev",
"theme-colors": "node bin/theme-colors.mjs",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
"prepack": "pnpm run build",
Expand All @@ -47,5 +53,8 @@
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"vitest": "^0.34.6"
},
"dependencies": {
"citty": "^0.1.4"
}
}
}
15 changes: 9 additions & 6 deletions pnpm-lock.yaml

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

33 changes: 33 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineCommand } from "citty";
import pkg from "../../package.json" assert { type: "json" };
import { getColors } from "..";

const main = defineCommand({
meta: {
name: pkg.name,
version: pkg.version,
description: pkg.description,
},
args: {
color: {
type: "positional",
description: "The color to generate variants for. Use hexadecimals.",
required: true,
},
},
run: ({ args }) => {
const color = args.color;

if (!color.startsWith("#") && color.length !== 7) {
throw new Error("Color must be a hexadecimal value.");
}

const colors = getColors(color);

console.log(colors);
},
});

export { main };

export { runMain } from "citty";
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"module": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"strict": true
"strict": true,
"resolveJsonModule": true,
},
"include": ["src"]
"include": [
"src"
]
}