diff --git a/dist/palette.toml b/dist/palette.toml index 1f140f3..18c9333 100644 --- a/dist/palette.toml +++ b/dist/palette.toml @@ -1,12 +1,12 @@ -name = verdigris -version = 0.0.1 -license = GPL-3.0-only -sourcecode = https://git.basking.monster/gaiety/verdigris +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 +name = "Gaiety" +email = "ava+verdigris@gaiety.me" +url = "https://gaiety.me" [colors] diff --git a/src/build/toml.ts b/src/build/toml.ts index af2c174..3ea622a 100644 --- a/src/build/toml.ts +++ b/src/build/toml.ts @@ -3,6 +3,7 @@ import appRoot from 'app-root-path' import { rmFile, mkFilePath, appendToFile } from "../helpers/file" import colors from '../palette' import type color from '../helpers/color' +import { toSnakeCase } from '../helpers/string' const file = appRoot + '/dist/palette.toml' const appendToTOML = async (content: string) => await appendToFile(file, content) @@ -28,10 +29,10 @@ export default async function(isVerbose = false): Promise { } function headerTOML(): string { - return `name = ${name} -version = ${version} -license = ${license} -sourcecode = ${url} + return `name = "${name}" +version = "${version}" +license = "${license}" +sourcecode = "${url}" ` } @@ -40,9 +41,9 @@ function authorTOML(): string { return ` [author] -name = ${name} -email = ${email} -url = ${url} +name = "${name}" +email = "${email}" +url = "${url}" ` } function colorHeaderTOML(): string { @@ -54,7 +55,7 @@ function colorHeaderTOML(): string { function colorTOML(color: color): string { const { name, l, c, h } = color return ` -[colors.${name.replaceAll(' ', '_').toLowerCase()}] +[colors.${toSnakeCase(name)}] name = "${name}" l = ${l} c = ${c} diff --git a/src/helpers/string.ts b/src/helpers/string.ts new file mode 100644 index 0000000..0c6a3f2 --- /dev/null +++ b/src/helpers/string.ts @@ -0,0 +1,3 @@ +export function toSnakeCase(str: string): string { + return str.replaceAll(' ', '_').toLowerCase() +} diff --git a/tests/dist/toml.test.ts b/tests/dist/toml.test.ts new file mode 100644 index 0000000..6333801 --- /dev/null +++ b/tests/dist/toml.test.ts @@ -0,0 +1,30 @@ +import { name, version, license, url, author } from '../../package.json' +import { expect, test } from 'bun:test' +import data from '../../dist/palette.toml' +import colors from '../../src/palette' +import { toSnakeCase } from '../../src/helpers/string' + +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 { name, l, c, h } = color + const dataColor = data.colors[toSnakeCase(name)] + + expect(dataColor.name).toBe(name) + expect(dataColor.l).toBe(l) + expect(dataColor.c).toBe(c) + expect(dataColor.h).toBe(h) + expect(dataColor.hex).toBe(color.toHex()) + }) +}) + diff --git a/tests/helpers/string.test.ts b/tests/helpers/string.test.ts new file mode 100644 index 0000000..e476057 --- /dev/null +++ b/tests/helpers/string.test.ts @@ -0,0 +1,9 @@ +import { expect, test } from 'bun:test' +import { toSnakeCase } from '../../src/helpers/string' + +test('can convert a string to snake case', () => { + expect( + toSnakeCase('Very Cool Beans') + ).toBe('very_cool_beans') +}) +