diff --git a/.mise.toml b/.mise.toml index a94d1ed..85bea15 100644 --- a/.mise.toml +++ b/.mise.toml @@ -1,2 +1,2 @@ [tools] -bun = "latest" +bun = "1.2.22" diff --git a/bun.lockb b/bun.lockb index 1bcf9f9..e26b0b3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/dist/palette.yml b/dist/palette.yml new file mode 100644 index 0000000..706cc9c --- /dev/null +++ b/dist/palette.yml @@ -0,0 +1,22 @@ +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" + +common: + pit: "#00040B" + depths: "#19323B" + stope: "#4E6872" + text: "#C6E4F0" + orange: "#FF9F6F" + teal: "#23DBC1" + red: "#E8ADA9" + yellow: "#E1B392" + green: "#98CCAC" + blue: "#8CC8E0" + purple: "#BEB6E8" \ No newline at end of file diff --git a/index.ts b/index.ts index 4b52e48..07c6202 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,7 @@ import { timerToSeconds } from './src/helpers/math'; import previewList from './src/preview/cli-list' import previewSnippet from './src/preview/cli-snippet' import buildTOML from './src/build/toml' +import buildYAML from './src/build/yaml' import buildKitty from './ports/kitty/src/build' const program = new Command(); @@ -41,6 +42,7 @@ program if (options.verbose) console.info('Building Direct Exports...') log(options.verbose, await buildTOML(), timer) + log(options.verbose, await buildYAML(), timer) if (options.verbose) console.info('Building Ports...') log(options.verbose, await buildKitty(), timer) diff --git a/package.json b/package.json index cbbd4ef..541c39e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "app-root-path": "^3.1.0", "chalk": "^5.6.2", "color-convert": "^3.1.2", - "commander": "^14.0.1" + "commander": "^14.0.1", + "estilo": "^2.1.3", }, "peerDependencies": { "typescript": "^5.0.0" diff --git a/src/build/toml.ts b/src/build/toml.ts index 3ea622a..2a407ae 100644 --- a/src/build/toml.ts +++ b/src/build/toml.ts @@ -10,7 +10,11 @@ const appendToTOML = async (content: string) => await appendToFile(file, content export default async function(isVerbose = false): Promise { if (isVerbose) console.info('Removing previous build', file) - await rmFile(file) + try { + await rmFile(file) + } catch (error) { + console.info('TOML: Previous build already removed') + } if (isVerbose) console.info('Ensuring path and file exist', file) await mkFilePath(file) if (isVerbose) console.info('Writing header info to file', file) @@ -46,6 +50,7 @@ email = "${email}" url = "${url}" ` } + function colorHeaderTOML(): string { return ` [colors] @@ -63,11 +68,3 @@ h = ${h} hex = "${color.toHex()}" ` } - - -// [colors] -// -// [colors.bg] -// l = 0.2 -// c = 0.02 -// h = diff --git a/src/build/yaml.ts b/src/build/yaml.ts new file mode 100644 index 0000000..be9f441 --- /dev/null +++ b/src/build/yaml.ts @@ -0,0 +1,62 @@ +import { name, version, license, url, author } from '../../package.json' +import appRoot from 'app-root-path' +import { rmFile, mkFilePath, appendToFile } from "../helpers/file" +import { toSnakeCase } from '../helpers/string' +import colors from '../palette' +import type color from '../helpers/color' + +const file = appRoot + '/dist/palette.yml' +const appendToYAML = async (content: string) => await appendToFile(file, content) + +export default async function(isVerbose = false): Promise { + if (isVerbose) console.info('Removing previous build', file) + try { + await rmFile(file) + } catch (error) { + console.info('YAML: Previous build already removed') + } + if (isVerbose) console.info('Ensuring path and file exist', file) + await mkFilePath(file) + if (isVerbose) console.info('Writing header info to file', file) + await appendToYAML(headerYAML()) + if (isVerbose) console.info('Writing author info to file', file) + await appendToYAML(authorYAML()) + if (isVerbose) console.info('Writing color palette to file', file) + await appendToYAML(colorHeaderYAML()) + for (let index = 0; index < colors.length; index++) { + const color = colors[index] + if (isVerbose) console.info(`${color.name}…`, file) + await appendToYAML(colorYAML(color)) + } + + return file +} + +function headerYAML(): string { + return `name: "${name}" +version: "${version}" +license: "${license}" +sourcecode: "${url}" + ` +} + +function authorYAML(): string { + const { name, email, url } = author + + return ` +author: + name: "${name}" + email: "${email}" + url: "${url}" + ` +} + +function colorHeaderYAML(): string { + return ` +common:` +} + +function colorYAML(color: color): string { + return ` + ${toSnakeCase(color.name)}: "${color.toHex()}"` +} diff --git a/tests/dist/yaml.test.ts b/tests/dist/yaml.test.ts new file mode 100644 index 0000000..bb68bca --- /dev/null +++ b/tests/dist/yaml.test.ts @@ -0,0 +1,25 @@ +import { name, version, license, url, author } from '../../package.json' +import { expect, test } from 'bun:test' +import colors from '../../src/palette' +import { toSnakeCase } from '../../src/helpers/string' +import data from '../../dist/palette.yml' + +test('has header info', () => { + expect(data.name).toBe(name) + expect(data.version).toBe(version) + expect(data.license).toBe(license) + expect(data.sourcecode).toBe(url) + + expect(data.author.name).toBe(author.name) + expect(data.author.email).toBe(author.email) + expect(data.author.url).toBe(author.url) +}) + +test('has expected colors', () => { + colors.forEach(color => { + const dataColor = data.common[toSnakeCase(color.name)] + + expect(dataColor).toBe(color.toHex()) + }) +}) +