diff --git a/bun.lockb b/bun.lockb index 0afce47..ce78201 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.ts b/index.ts index 0f7027f..d41a3a9 100644 --- a/index.ts +++ b/index.ts @@ -42,12 +42,12 @@ program const timer = process.hrtime() if (options.verbose) console.info('Building Direct Exports...') - log(options.verbose, await buildTOML(), timer) - log(options.verbose, await buildYAML(), timer) + log(options.verbose, await buildTOML(options.verbose), timer) + log(options.verbose, await buildYAML(options.verbose), timer) if (options.verbose) console.info('Building Ports...') - log(options.verbose, await buildKitty(), timer) - // log(options.verbose, await buildNeovim(), timer) + log(options.verbose, await buildKitty(options.verbose), timer) + log(options.verbose, await buildNeovim(options.verbose), timer) }); program.parse(); diff --git a/ports/kitty/src/data.ts b/ports/kitty/src/data.ts index 7048514..cfefc77 100644 --- a/ports/kitty/src/data.ts +++ b/ports/kitty/src/data.ts @@ -2,7 +2,6 @@ import { name, version } from '../info.toml' import { license, url } from '../../../package.json' import colors from '../../../src/palette' import type { Colors } from '../../../src/palette' -import Color from '../../../src/helpers/color' export default function(): any { return { diff --git a/ports/neovim/dist/verdigris/colors.lua b/ports/neovim/dist/verdigris/colors.lua new file mode 100644 index 0000000..4d10e21 --- /dev/null +++ b/ports/neovim/dist/verdigris/colors.lua @@ -0,0 +1,18 @@ +local M = {} + +M.palette = { + pit = "#00040B" + depths = "#19323B" + stope = "#4E6872" + text = "#C6E4F0" + + orange = "#FF9F6F" + teal = "#23DBC1" + red = "#E8ADA9" + yellow = "#E1B392" + green = "#98CCAC" + blue = "#8CC8E0" + purple = "#BEB6E8" +} + +return M diff --git a/ports/neovim/dist/verdigris/groups.lua b/ports/neovim/dist/verdigris/groups.lua new file mode 100644 index 0000000..90a5a9d --- /dev/null +++ b/ports/neovim/dist/verdigris/groups.lua @@ -0,0 +1,14 @@ +local M = {} + +function M.apply() + local p = require("verdigris.colors").apply() + + vim.cmd("highlight clear") + if vim.fn.exists("syntax_on") then + vim.cmd("syntax reset") + end + vim.o.background = "dark" + vim.g.colors_name = "verdigris" +end + +return M diff --git a/ports/neovim/info.toml b/ports/neovim/info.toml new file mode 100644 index 0000000..0036dd1 --- /dev/null +++ b/ports/neovim/info.toml @@ -0,0 +1,3 @@ +name = "verdigris for neovim" +version = "0.0.1" + diff --git a/ports/neovim/src/build.ts b/ports/neovim/src/build.ts index dec1048..bff5b79 100644 --- a/ports/neovim/src/build.ts +++ b/ports/neovim/src/build.ts @@ -1,38 +1,21 @@ import appRoot from 'app-root-path' -import { rmFile, mkFilePath, appendToFile } from "../../../src/helpers/file" -import { common } from '../../../dist/palette.yml' -import { spawn } from 'bun' +import { copyFiles, renderToFile } from '../../../src/helpers/file' +import getData from './data' -const file = appRoot + '/ports/neovim/estilos/palettes/verdigris.yml' -const appendToEstilosPalette = async (content: string) => await appendToFile(file, content) +const nonTemplateFiles = appRoot + '/ports/neovim/src/templates/**/*.lua' +const templateFile = appRoot + '/ports/neovim/src/templates/palette.lua.hbs' +const outputDir = appRoot + '/ports/neovim/dist/verdigris/' +const outputFile = outputDir + 'colors.lua' export default async function(isVerbose = false) { - if (isVerbose) console.info('Neovim: Removing previous build', file) try { - await rmFile(file) + let results: Array = await copyFiles(nonTemplateFiles, outputDir, isVerbose) + + await renderToFile(templateFile, outputFile, getData(), isVerbose) + results.push(outputFile) + + return results.join('\n') } catch (error) { - console.info('Neovim: Previous build already removed') + throw error } - if (isVerbose) console.info('Neovim: Ensuring path and file exist', file) - await mkFilePath(file) - if (isVerbose) console.info('Neovim: Writing color palette into file', file) - await appendToEstilosPalette(colors()) - if (isVerbose) console.info('Neovim: Running estilo to compile `.vim`', file) - await runEstilo(isVerbose) - - return appRoot + '/ports/neovim/colors/verdigris.vim' -} - -function colors(): string { - return Object - .keys(common) - .reduce((acc, key) => acc += `${key}: "${common[key]}"\n`, '') -} - -async function runEstilo(isVerbose: boolean) { - const proc = spawn(['bun', 'estilo', 'render', appRoot + '/ports/neovim/'], { - cwd: appRoot.toString(), - }); - const output = await proc.stdout.text(); - if (isVerbose) console.info(output) } diff --git a/ports/neovim/src/data.ts b/ports/neovim/src/data.ts new file mode 100644 index 0000000..cfefc77 --- /dev/null +++ b/ports/neovim/src/data.ts @@ -0,0 +1,23 @@ +import { name, version } from '../info.toml' +import { license, url } from '../../../package.json' +import colors from '../../../src/palette' +import type { Colors } from '../../../src/palette' + +export default function(): any { + return { + name, + version, + license, + url, + ...flattenColorsToHex(), + } +} + +function flattenColorsToHex(): Colors { + return colors.reduce((acc, color) => { + return { + [color.nameSnakeCase]: color.toHex(), + ...acc, + } + }, {}) +} diff --git a/ports/neovim/src/templates/groups.lua b/ports/neovim/src/templates/groups.lua new file mode 100644 index 0000000..90a5a9d --- /dev/null +++ b/ports/neovim/src/templates/groups.lua @@ -0,0 +1,14 @@ +local M = {} + +function M.apply() + local p = require("verdigris.colors").apply() + + vim.cmd("highlight clear") + if vim.fn.exists("syntax_on") then + vim.cmd("syntax reset") + end + vim.o.background = "dark" + vim.g.colors_name = "verdigris" +end + +return M diff --git a/ports/neovim/src/templates/palette.lua.hbs b/ports/neovim/src/templates/palette.lua.hbs new file mode 100644 index 0000000..48d4f17 --- /dev/null +++ b/ports/neovim/src/templates/palette.lua.hbs @@ -0,0 +1,18 @@ +local M = {} + +M.palette = { + pit = "{{pit}}" + depths = "{{depths}}" + stope = "{{stope}}" + text = "{{text}}" + + orange = "{{orange}}" + teal = "{{teal}}" + red = "{{red}}" + yellow = "{{yellow}}" + green = "{{green}}" + blue = "{{blue}}" + purple = "{{purple}}" +} + +return M diff --git a/src/build/templates/toml.hbs b/src/build/templates/palette.toml.hbs similarity index 100% rename from src/build/templates/toml.hbs rename to src/build/templates/palette.toml.hbs diff --git a/src/build/templates/yaml.hbs b/src/build/templates/palette.yaml.hbs similarity index 100% rename from src/build/templates/yaml.hbs rename to src/build/templates/palette.yaml.hbs diff --git a/src/build/toml.ts b/src/build/toml.ts index 0103727..79e29ac 100644 --- a/src/build/toml.ts +++ b/src/build/toml.ts @@ -4,7 +4,7 @@ import { renderToFile } from "../helpers/file" import colors from '../palette' import Color from '../helpers/color' -const templateFile = appRoot + '/src/build/templates/toml.hbs' +const templateFile = appRoot + '/src/build/templates/palette.toml.hbs' const outputFile = appRoot + '/dist/palette.toml' export default async function(isVerbose = false): Promise { diff --git a/src/build/yaml.ts b/src/build/yaml.ts index 6a24b2f..ab3e243 100644 --- a/src/build/yaml.ts +++ b/src/build/yaml.ts @@ -4,7 +4,7 @@ import colors from '../palette' import Color from '../helpers/color' import { renderToFile } from '../helpers/file' -const templateFile = appRoot + '/src/build/templates/yaml.hbs' +const templateFile = appRoot + '/src/build/templates/palette.yaml.hbs' const outputFile = appRoot + '/dist/palette.yml' export default async function(isVerbose = false): Promise { diff --git a/src/helpers/file.ts b/src/helpers/file.ts index 392f1ec..1f09bc2 100644 --- a/src/helpers/file.ts +++ b/src/helpers/file.ts @@ -1,6 +1,6 @@ import { compile } from 'handlebars'; -import { appendFile, mkdir, rm, readFile, writeFile } from 'node:fs/promises'; -import { dirname } from 'node:path' +import { mkdir, readFile, writeFile, glob, copyFile } from 'node:fs/promises'; +import { dirname, basename, join } from 'node:path' const log = (isVerbose = true, ...rest: any[]) => { if (isVerbose) console.info(...rest) @@ -36,3 +36,24 @@ export async function renderToFile( } } +export async function copyFiles( + filesGlob: string, destDir: string, isVerbose = false +): Promise { + let results: Array = [] + + try { + log(isVerbose, 'Finding files by glob', filesGlob) + for await (const file of glob(filesGlob)) { + const outputFile = join(destDir, basename(file)) + + results.push(outputFile) + + log(isVerbose, 'Copying', file, 'to', outputFile) + await copyFile(file, outputFile) + } + } catch (error) { + throw error + } + + return results +}