preview command with arguments, better snippet

This commit is contained in:
Ava Gaiety W 2025-09-18 19:22:04 -06:00
parent b78c0e926f
commit 4726fe848b
6 changed files with 76 additions and 22 deletions

View file

@ -3,18 +3,18 @@
## Setup
```bash
bun install
bun
```
## To Build
```bash
bun run index.js
bun index.ts
```
## To Live Preview
```bash
while sleep 1 ; do find . -name '*.ts' | entr bun index.ts ; done
bun --watch index.ts preview
```
## To Run Tests

BIN
bun.lockb

Binary file not shown.

View file

@ -1,20 +1,28 @@
import chalk from 'chalk'
import colors, { pit, text, darkTeal, darkOrange, lightOrange, darkPurple } from './src/palette'
import Color from './src/helpers/color'
#!/usr/bin/env node
import { Command } from 'commander'
import previewList from './src/preview/cli-list'
import previewSnippet from './src/preview/cli-snippet'
function log(color: Color) {
console.log(
chalk.hex(color.toHex()).bold('■ T'),
chalk.hex(text.toHex()).bold(color.name)
)
}
const program = new Command();
program
.name('verdigris')
.description('Mining up the very best Color Palette')
.version('0.0.1')
program
.command('preview')
.description('TODO')
.option('-v, --verbose', 'additional Logs')
.option('--no-list', 'do not show colors as a list')
.option('--no-snippet', 'do not a code snippet')
.action((options) => {
if (options.verbose) console.info('Previewing Color Palette')
if (options.verbose) console.info('List:')
if (options.list) previewList()
if (options.verbose) console.info('Code Example:')
if (options.snippet) previewSnippet()
});
program.parse();
colors.forEach(log)
console.log(
chalk
.bgHex(pit.toHex())
.hex(text.toHex())
.visible(
`${chalk.hex(darkTeal.toHex()).visible('const')} ${chalk.hex(darkOrange.toHex()).visible('myFunc')} ${chalk.hex(lightOrange.toHex()).visible('=')} (isAwesome: boolean) => return 'yep'`
)
)

View file

@ -5,7 +5,8 @@
"devDependencies": {
"@types/bun": "latest",
"chalk": "^5.6.2",
"color-convert": "^3.1.2"
"color-convert": "^3.1.2",
"commander": "^14.0.1"
},
"peerDependencies": {
"typescript": "^5.0.0"

12
src/preview/cli-list.ts Normal file
View file

@ -0,0 +1,12 @@
import chalk from 'chalk'
import colors, { text } from '../palette'
import Color from '../helpers/color'
export function log(color: Color) {
console.log(
chalk.hex(color.toHex()).bold('■ T'),
chalk.hex(text.toHex()).bold(color.name)
)
}
export default () => colors.forEach(log)

View file

@ -0,0 +1,33 @@
import chalk from 'chalk'
import { pit, text, darkTeal, darkOrange, lightOrange, darkPurple, lightPurple, darkBlue, darkGreen, stope } from '../palette'
const bg = chalk.bgHex(pit.toHex()).hex(text.toHex())
const chalkDefinition = chalk.hex(darkTeal.toHex())
const chalkVariable = chalk.hex(darkOrange.toHex())
const chalkAssignments = chalk.hex(lightOrange.toHex())
const chalkParenthesis = chalk.hex(darkPurple.toHex())
const chalkParameter = chalk.hex(lightPurple.toHex())
const chalkType = chalk.hex(darkBlue.toHex())
const chalkReturn = chalk.hex(darkGreen.toHex())
const chalkComment = chalk.italic.hex(stope.toHex())
export default () => {
console.log(
bg(`
${chalkDefinition('const')}
${chalkVariable('myFunc')}
${chalkAssignments('=')}
${chalkParenthesis('\(')}
${chalkParameter('isAwesome')}
:
${chalkType('boolean')}
${chalkParenthesis('\)')}
:
${chalkType('string')}
${chalkAssignments('=>')}
${chalkReturn('return')}
'yep!'
${chalkComment('# cool!')}
`).split('\n').join('')
)
}