feat: switching from Deno to Node for packaging

This commit is contained in:
D. Moonfire 2024-02-24 11:22:42 -06:00
parent fab981ebbd
commit b12b009b2a
6 changed files with 91 additions and 9 deletions

4
.gitignore vendored
View file

@ -1,4 +1,6 @@
.direnv
.direnv/
dist/
node_modules/
# nixago: ignore-linked-files
/treefmt.toml

15
Justfile Normal file
View file

@ -0,0 +1,15 @@
@default:
just --choose
format:
treefmt
just --fmt --unstable
build: generate-colors generate-theme
generate-colors: format
node src/generate.mjs
generate-theme: format
mkdir -p dist
cp src/theme.css dist/

View file

@ -29,7 +29,8 @@
# Shell
default = pkgs.mkShell {
packages = [
pkgs.deno
pkgs.just
pkgs.nodejs_20
]
++ project-config.packages;

30
package-lock.json generated Normal file
View file

@ -0,0 +1,30 @@
{
"name": "@priduck-color-theme/base",
"version": "0.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@priduck-color-theme/base",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"mkdirp": "^3.0.1"
}
},
"node_modules/mkdirp": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz",
"integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==",
"bin": {
"mkdirp": "dist/cjs/src/bin.js"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
}
}
}

22
package.json Normal file
View file

@ -0,0 +1,22 @@
{
"name": "@priduck-color-theme/base",
"version": "0.0.0",
"description": "A color-theme based on a single hue in the LCH colorspace.",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://src.mfgames.com/priduck-color-theme/priduck-color-theme-base-css.git"
},
"keywords": [
"css",
"color"
],
"author": "D. Moonfire",
"license": "MIT",
"dependencies": {
"mkdirp": "^3.0.1"
}
}

View file

@ -1,8 +1,18 @@
// We need an empty export for top-level await.
export {};
import { mkdirp } from "mkdirp";
import { fileURLToPath } from "url";
import path from "path";
import fs from "node:fs/promises";
// Figure out where we need to write the files.
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const distPath = __dirname + "/../dist";
console.log("writing", distPath);
await mkdirp(distPath);
// Start with the basic CSS header.
let lines: string[] = [":root {"];
let lines = [":root {"];
// We have ten colors, with 0 being the base hue and the others being evenly
// rotated around the color wheel.
@ -14,7 +24,7 @@ for (let color = 0; color < 10; color++) {
// to very light.
for (let brightness = 0; brightness < 10; brightness++) {
// We use a standard code (--color-cXbY) for our codes.
const code = `--color-c${color}b${brightness}`;
const code = `--color-priduck-c${color}b${brightness}`;
// Figure out the ramps we are using for brighteness.
const l = brightness * 11;
@ -24,7 +34,7 @@ for (let color = 0; color < 10; color++) {
lines.push(
` ${code}: lch(${l.toFixed(1)} ${s.toFixed(
1,
)} calc(var(--color-hue) + ${rotation}));`,
)} calc(var(--color-priduck-hue) + ${rotation}));`,
);
}
}
@ -33,6 +43,8 @@ for (let color = 0; color < 10; color++) {
lines.push("}");
// Write out the files.
const text = new TextEncoder().encode(lines.join("\n"));
const colorsPath = path.join(distPath, "colors.css");
await Deno.writeFile("src/colors.css", text, { mode: 0o644 });
await fs.writeFile(colorsPath, Buffer.from(lines.join("\n")));
console.log("wrote", colorsPath);