diff --git a/CHANGELOG.md b/CHANGELOG.md index c7c5193..244ddc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.2.0 — 2026-10-08 + +- Meeting preparation mode: Generate 1–20 excuses with `excuseBatch(category, { count, seed })`. A batch cycles through the category without repeats until its pool is exhausted. Seeds keep the starting point repeatable. CLI `--json` returns a string or array. +- Add npm and CI badges to the published README. + ## 0.1.1 — 2026-10-08 - Correct npm installation and npx documentation after the initial publication. diff --git a/README.md b/README.md index b60379b..a51eb24 100644 --- a/README.md +++ b/README.md @@ -112,3 +112,17 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). Useful first, funny second. - [doggo-log](https://github.com/DeployAnyway/doggo-log) - [ship-it-meter](https://github.com/DeployAnyway/ship-it-meter) - [bro-say](https://github.com/DeployAnyway/bro-say) + +## Meeting preparation mode + +Generate 1–20 excuses with `excuseBatch(category, { count, seed })`. A batch cycles through the category without repeats until its pool is exhausted. Seeds keep the starting point repeatable. CLI `--json` returns a string or array. + +```sh +npx @deployanyway/excuse-js deployment --count 3 --seed demo +``` + +API (import the named functions from this package): + +```js +excuseBatch("deployment", { count: 3, seed: "demo" }); +``` diff --git a/bin/cli.js b/bin/cli.js index fc0007b..8cef234 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -2,7 +2,7 @@ import { parseArgs } from "node:util"; import { readFileSync } from "node:fs"; import { URL } from "node:url"; -import { excuse, categories } from "../src/index.js"; +import { excuse, categories, excuseBatch } from "../src/index.js"; try { const { values, positionals } = parseArgs({ @@ -12,11 +12,13 @@ try { version: { type: "boolean", short: "v" }, seed: { type: "string" }, list: { type: "boolean" }, + count: { type: "string" }, + json: { type: "boolean" }, }, }); if (values.help) { console.log( - "Usage: excuse-js [category] [--seed text]\n\nDefault category: deployment\n\nOptions:\n --seed text Repeatable selection (always a string seed)\n --list List categories\n -h, --help Show help\n -v, --version Show version\n\nExample: excuse-js deployment --seed demo\nExit codes: 0 success; 2 invalid arguments.", + "Usage: excuse-js [category] [--seed text] [--count 3] [--json]\n\nDefault category: deployment\n\nOptions:\n --seed text Repeatable selection (always a string seed)\n --count 1..20 Prepare a batch for the meeting\n --json Structured string or batch\n --list List categories\n -h, --help Show help\n -v, --version Show version\n\nExample: excuse-js deployment --seed demo\nExit codes: 0 success; 2 invalid arguments.", ); } else if (values.version) { console.log( @@ -25,13 +27,33 @@ try { ).version, ); } else if (values.list) { - if (positionals.length || values.seed !== undefined) + if ( + positionals.length || + values.seed !== undefined || + values.count !== undefined || + values.json + ) throw new TypeError("--list does not accept a category or seed."); console.log(categories().join("\n")); } else { if (positionals.length > 1) throw new TypeError("Provide only one category."); - console.log(excuse(positionals[0], { seed: values.seed })); + if (values.count !== undefined && !/^[0-9]+$/.test(values.count)) + throw new TypeError("count must be an integer."); + const result = + values.count === undefined + ? excuse(positionals[0], { seed: values.seed }) + : excuseBatch(positionals[0], { + seed: values.seed, + count: Number(values.count), + }); + console.log( + values.json + ? JSON.stringify(result) + : Array.isArray(result) + ? result.map((line, i) => `${i + 1}. ${line}`).join("\n") + : result, + ); } } catch (error) { console.error(`excuse-js: ${error.message}\nRun with --help for usage.`); diff --git a/package-lock.json b/package-lock.json index 307fa03..2ead297 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@deployanyway/excuse-js", - "version": "0.1.1", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@deployanyway/excuse-js", - "version": "0.1.1", + "version": "0.2.0", "license": "MIT", "bin": { "excuse-js": "bin/cli.js" diff --git a/package.json b/package.json index 3e1f278..c2b950d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@deployanyway/excuse-js", - "version": "0.1.1", + "version": "0.2.0", "description": "A seeded developer excuse generator for bugs, builds, and deployments. Finally, a dependency that takes the blame.", "type": "module", "exports": "./src/index.js", diff --git a/src/index.js b/src/index.js index 039fdfb..7b18add 100644 --- a/src/index.js +++ b/src/index.js @@ -42,3 +42,19 @@ export function excuse(category = "deployment", options = {}) { } return phrases[key][index]; } + +/** Generate a batch without repeats until the category pool is exhausted. */ +export function excuseBatch(category = "deployment", options = {}) { + if (!options || typeof options !== "object" || Array.isArray(options)) + throw new TypeError("Options must be an object."); + const count = options.count ?? 3; + if (!Number.isSafeInteger(count) || count < 1 || count > 20) + throw new RangeError("count must be an integer between 1 and 20."); + const first = excuse(category, { seed: options.seed }); + const pool = phrases[category.trim().toLowerCase()]; + const start = pool.indexOf(first); + return Array.from( + { length: count }, + (_, i) => pool[(start + i) % pool.length], + ); +} diff --git a/test/capabilities.test.js b/test/capabilities.test.js new file mode 100644 index 0000000..b2abf97 --- /dev/null +++ b/test/capabilities.test.js @@ -0,0 +1,31 @@ +import { URL } from "node:url"; +import test from "node:test"; +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { excuseBatch, excuse, categories } from "../src/index.js"; +test("seeded batches are stable, independent, and cycle only after pool exhaustion", () => { + for (const category of categories()) { + const batch = excuseBatch(category, { count: 6, seed: "demo" }); + assert.equal(new Set(batch.slice(0, 3)).size, 3); + assert.equal(batch[0], batch[3]); + assert.equal(batch[0], excuse(category, { seed: "demo" })); + batch[0] = "changed"; + assert.notEqual(excuseBatch(category, { seed: "demo" })[0], "changed"); + } + const cli = spawnSync( + process.execPath, + ["bin/cli.js", "deployment", "--count", "3", "--seed", "demo", "--json"], + { cwd: new URL("..", import.meta.url), encoding: "utf8" }, + ); + assert.equal(cli.status, 0); + assert.deepEqual( + JSON.parse(cli.stdout), + excuseBatch("deployment", { seed: "demo" }), + ); +}); +test("batch rejects invalid counts, seeds, and categories", () => { + for (const count of [0, 21, 1.5, NaN, "3"]) + assert.throws(() => excuseBatch("deployment", { count }), RangeError); + assert.throws(() => excuseBatch("missing"), RangeError); + assert.throws(() => excuseBatch("deployment", { seed: null }), TypeError); +}); diff --git a/test/index.test.js b/test/index.test.js index 40c4ba5..2d5fb8b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -78,7 +78,7 @@ test("invalid inputs and prototype keys", () => { test("CLI help, version, list, default, and seed agreement", () => { assert.equal(cli("--help").status, 0); assert.ok(cli("--help").stdout.includes("Usage:")); - assert.equal(cli("--version").stdout.trim(), "0.1.1"); + assert.equal(cli("--version").stdout.trim(), "0.2.0"); assert.deepEqual(cli("--list").stdout.trim().split(/\r?\n/), categories()); assert.equal(cli().status, 0); assert.ok(phrases.deployment.includes(cli().stdout.trim()));