Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
```
30 changes: 26 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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(
Expand All @@ -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.`);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
);
}
31 changes: 31 additions & 0 deletions test/capabilities.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Loading