From 223fc6c2d05d8b37dba3ff3c3586bacab67dab9d Mon Sep 17 00:00:00 2001 From: "D. Moonfire" Date: Thu, 9 May 2024 23:42:38 -0500 Subject: [PATCH] feat: added some better logging --- README.md | 13 +++++++++++++ package-lock.json | 26 ++++++++++++++++++++++++-- package.json | 1 + src/cmds/css/variables.mjs | 6 ++++++ src/cmds/palette.mjs | 8 ++++++++ src/output.mjs | 8 ++++++-- 6 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..9fe1cad --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Priduck Theme CLI + +_A CLI for generating a tri-color theme based on a single hue and an even rotation around the color wheel._ + +Priduck (name is nonscense) is a color theme originally designed for [Fedran](https://fedran.com) where the base color is a hue (in degrees, 0-360) with with nine colors based on an even distribution around the wheel with nine-levels of brightness ranging from a near-black to a near-white. + +## Debugging + +The CLI uses [debug](https://github.com/debug-js/debug) for logging and (relatively) minor output. The CLI will produce no output unless the `DEBUG` environment variable is set, such as: + +```shell +export DEBUG="*" +``` diff --git a/package-lock.json b/package-lock.json index b133ff8..7b8ce41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { - "name": "@priduck-color-theme/base", + "name": "@priduck-color-theme/priduck-cli", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@priduck-color-theme/base", + "name": "@priduck-color-theme/priduck-cli", "version": "0.1.0", "license": "MIT", "dependencies": { "@priduck-color-theme/cli": "^0.0.1", "colorjs.io": "^0.5.0", + "debug": "^4.3.4", "yargs": "^17.7.2" }, "devDependencies": { @@ -85,6 +86,22 @@ "resolved": "https://registry.npmjs.org/colorjs.io/-/colorjs.io-0.5.0.tgz", "integrity": "sha512-qekjTiBLM3F/sXKks/ih5aWaHIGu+Ftel0yKEvmpbKvmxpNOhojKgha5uiWEUOqEpRjC1Tq3nJRT7WgdBOxIGg==" }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -129,6 +146,11 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", diff --git a/package.json b/package.json index a8f16e8..484b4ac 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "@priduck-color-theme/cli": "^0.0.1", "colorjs.io": "^0.5.0", + "debug": "^4.3.4", "yargs": "^17.7.2" } } diff --git a/src/cmds/css/variables.mjs b/src/cmds/css/variables.mjs index 96af425..af021c9 100644 --- a/src/cmds/css/variables.mjs +++ b/src/cmds/css/variables.mjs @@ -1,5 +1,9 @@ import * as colors from "../../colors.mjs"; import { write } from "../../output.mjs"; +import debug from "debug"; + +/** @type {object} */ +const log = debug("css").extend("variables"); export const command = "variables [path.css]"; export const desc = "Generate a CSS file that uses variables to generate"; @@ -16,6 +20,8 @@ export async function handler(argv) { // Start with the basic CSS header. let lines = [":root {"]; + log("generating CSS using variables"); + // We have ten colors, with 0 being the base hue and the others being evenly // rotated around the color wheel. for (const color of colors.colorList) { diff --git a/src/cmds/palette.mjs b/src/cmds/palette.mjs index 0ff8c7e..49d4ffb 100644 --- a/src/cmds/palette.mjs +++ b/src/cmds/palette.mjs @@ -1,5 +1,9 @@ import * as colors from "../colors.mjs"; import { write } from "../output.mjs"; +import debug from "debug"; + +/** @type {object} */ +const log = debug("palette"); export const command = "palette [path.gpl]"; export const desc = "Generate a GNU Imp/Inkscape palette"; @@ -43,6 +47,10 @@ export async function handler(argv) { // Start with the header. let lines = ["GIMP Palette", `Name: ${argv.name}`, "Columns: 30", ""]; + log("generating GPL palette named", argv.name); + log("using base hue", argv.hue, "as color 0"); + log("using secondary", argv.secondary, "tertiary", argv.tertiary); + // Loop through the three primary colors, then the brightness for each one. const colorList = [0, argv.secondary, argv.tertiary]; diff --git a/src/output.mjs b/src/output.mjs index 130190a..446e4c6 100644 --- a/src/output.mjs +++ b/src/output.mjs @@ -1,6 +1,10 @@ import { mkdirp } from "mkdirp"; import path from "path"; import fs from "node:fs/promises"; +import debug from "debug"; + +/** @type {object} */ +const log = debug("output"); /** * Writes the output to either the console if there is no output or it is @@ -24,12 +28,12 @@ export async function write(argv, input) { const file = argv.output; const dir = path.dirname(file); - console.log("writing", file); + log("writing", file); await mkdirp(dir); // Now, write out the file. await fs.writeFile(file, Buffer.from(text)); - console.log("wrote", file); + log("wrote", file); }