can output to toml

This commit is contained in:
Ava Gaiety W 2025-09-18 20:29:30 -06:00
parent 4726fe848b
commit ab60e53cac
7 changed files with 258 additions and 51 deletions

49
.gitignore vendored
View file

@ -115,59 +115,10 @@ web_modules/
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# IntelliJ based IDEs
.idea

BIN
bun.lockb

Binary file not shown.

138
dist/palette.toml vendored Normal file
View file

@ -0,0 +1,138 @@
name = verdigris
version = 0.0.1
license = GPL-3.0-only
sourcecode = https://git.basking.monster/gaiety/verdigris
[author]
name = Gaiety
email = ava+verdigris@gaiety.me
url = https://gaiety.me
[colors]
[colors.pit]
name = "Pit"
l = 20
c = 3
h = 350
hex = "#201018"
[colors.depths]
name = "Depths"
l = 27
c = 3
h = 350
hex = "#322028"
[colors.stope]
name = "Stope"
l = 34
c = 3
h = 350
hex = "#44323A"
[colors.text]
name = "Text"
l = 92
c = 3
h = 350
hex = "#F5DDE7"
[colors.dark_red]
name = "Dark Red"
l = 82
c = 12
h = 0
hex = "#FFA3C1"
[colors.light_red]
name = "Light Red"
l = 92
c = 12
h = 0
hex = "#FFC3E1"
[colors.dark_orange]
name = "Dark Orange"
l = 82
c = 12
h = 45
hex = "#FFAB82"
[colors.light_orange]
name = "Light Orange"
l = 92
c = 12
h = 45
hex = "#FFCBA1"
[colors.dark_yellow]
name = "Dark Yellow"
l = 82
c = 12
h = 90
hex = "#E2C162"
[colors.light_yellow]
name = "Light Yellow"
l = 92
c = 12
h = 90
hex = "#FFE183"
[colors.dark_green]
name = "Dark Green"
l = 82
c = 12
h = 135
hex = "#A2D686"
[colors.light_green]
name = "Light Green"
l = 92
c = 12
h = 135
hex = "#C2F7A5"
[colors.dark_teal]
name = "Dark Teal"
l = 82
c = 12
h = 180
hex = "#5ADDC7"
[colors.light_teal]
name = "Light Teal"
l = 92
c = 12
h = 180
hex = "#7EFFE8"
[colors.dark_blue]
name = "Dark Blue"
l = 82
c = 12
h = 270
hex = "#A6C0FF"
[colors.light_blue]
name = "Light Blue"
l = 92
c = 12
h = 270
hex = "#C5E1FF"
[colors.dark_purple]
name = "Dark Purple"
l = 82
c = 12
h = 315
hex = "#E2ACFA"
[colors.light_purple]
name = "Light Purple"
l = 92
c = 12
h = 315
hex = "#FFCCFF"

View file

@ -2,6 +2,7 @@
import { Command } from 'commander'
import previewList from './src/preview/cli-list'
import previewSnippet from './src/preview/cli-snippet'
import buildTOML from './src/build/toml'
const program = new Command();
@ -12,8 +13,8 @@ program
program
.command('preview')
.description('TODO')
.option('-v, --verbose', 'additional Logs')
.description('stdout some examples')
.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) => {
@ -24,5 +25,16 @@ program
if (options.snippet) previewSnippet()
});
program
.command('build')
.description('compile toml and other consumable formats')
.option('-v, --verbose', 'additional logs')
.action(async (options) => {
if (options.verbose) console.info('Building...')
const timer = process.hrtime()
await buildTOML()
console.info(`Built in ${timer[0]} seconds`)
});
program.parse();

View file

@ -2,8 +2,17 @@
"name": "verdigris",
"module": "index.js",
"type": "module",
"license": "GPL-3.0-only",
"version": "0.0.1",
"url": "https://git.basking.monster/gaiety/verdigris",
"author": {
"name": "Gaiety",
"email": "ava+verdigris@gaiety.me",
"url": "https://gaiety.me"
},
"devDependencies": {
"@types/bun": "latest",
"app-root-path": "^3.1.0",
"chalk": "^5.6.2",
"color-convert": "^3.1.2",
"commander": "^14.0.1"

70
src/build/toml.ts Normal file
View file

@ -0,0 +1,70 @@
import { name, version, license, url, author } from '../../package.json'
import appRoot from 'app-root-path'
import { rmFile, mkFilePath, appendToFile } from "../helpers/file"
import colors from '../palette'
import type color from '../helpers/color'
const file = appRoot + '/dist/palette.toml'
const appendToTOML = async (content: string) => await appendToFile(file, content)
export default async function(isVerbose = false) {
if (isVerbose) console.info('Removing previous build', file)
await rmFile(file)
if (isVerbose) console.info('Ensuring path and file exist', file)
await mkFilePath(file)
if (isVerbose) console.info('Writing header info to file', file)
await appendToTOML(headerTOML())
if (isVerbose) console.info('Writing author info to file', file)
await appendToTOML(authorTOML())
if (isVerbose) console.info('Writing color palette to file', file)
await appendToTOML(colorHeaderTOML())
for (let index = 0; index < colors.length; index++) {
const color = colors[index]
if (isVerbose) console.info(`${color.name}`, file)
await appendToTOML(colorTOML(color))
}
}
function headerTOML(): string {
return `name = ${name}
version = ${version}
license = ${license}
sourcecode = ${url}
`
}
function authorTOML(): string {
const { name, email, url } = author
return `
[author]
name = ${name}
email = ${email}
url = ${url}
`
}
function colorHeaderTOML(): string {
return `
[colors]
`
}
function colorTOML(color: color): string {
const { name, l, c, h } = color
return `
[colors.${name.replaceAll(' ', '_').toLowerCase()}]
name = "${name}"
l = ${l}
c = ${c}
h = ${h}
hex = "${color.toHex()}"
`
}
// [colors]
//
// [colors.bg]
// l = 0.2
// c = 0.02
// h =

27
src/helpers/file.ts Normal file
View file

@ -0,0 +1,27 @@
import { appendFile, mkdir, rm } from 'node:fs/promises';
import { dirname } from 'node:path'
export async function mkFilePath(file: string) {
try {
await mkdir(dirname(file), { recursive: true })
} catch (error) {
throw error
}
}
export async function rmFile(file: string) {
try {
await rm(file)
} catch (error) {
throw error
}
}
export async function appendToFile(file: string, content: string) {
try {
await appendFile(file, content)
} catch (error) {
throw error
}
}