summaryrefslogtreecommitdiff
path: root/.github/scripts
diff options
context:
space:
mode:
authorKenneth Lien <kenneth@anthropic.com>2026-03-20 14:43:23 -0700
committerKenneth Lien <kenneth@anthropic.com>2026-03-20 14:43:23 -0700
commit272de726d6ad952317916e7336335fba60bdc1ae (patch)
tree6ecc40cc0e2042639fc9cb988638d63fa3531dd7 /.github/scripts
parent1c95fc662b7df51e9200ef8c26de2a4e803e9ff4 (diff)
parentd56d7b61f061c719514784919fb29712cbd0999d (diff)
Merge branch 'main' into add-imessage-channel
Diffstat (limited to '.github/scripts')
-rw-r--r--.github/scripts/check-marketplace-sorted.ts42
-rw-r--r--.github/scripts/validate-marketplace.ts77
2 files changed, 119 insertions, 0 deletions
diff --git a/.github/scripts/check-marketplace-sorted.ts b/.github/scripts/check-marketplace-sorted.ts
new file mode 100644
index 00000000..0fcbf3be
--- /dev/null
+++ b/.github/scripts/check-marketplace-sorted.ts
@@ -0,0 +1,42 @@
+#!/usr/bin/env bun
+/**
+ * Checks that marketplace.json plugins are alphabetically sorted by name.
+ *
+ * Usage:
+ * bun check-marketplace-sorted.ts # check, exit 1 if unsorted
+ * bun check-marketplace-sorted.ts --fix # sort in place
+ */
+
+import { readFileSync, writeFileSync } from "fs";
+import { join } from "path";
+
+const MARKETPLACE = join(import.meta.dir, "../../.claude-plugin/marketplace.json");
+
+type Plugin = { name: string; [k: string]: unknown };
+type Marketplace = { plugins: Plugin[]; [k: string]: unknown };
+
+const raw = readFileSync(MARKETPLACE, "utf8");
+const mp: Marketplace = JSON.parse(raw);
+
+const cmp = (a: Plugin, b: Plugin) =>
+ a.name.toLowerCase().localeCompare(b.name.toLowerCase());
+
+if (process.argv.includes("--fix")) {
+ mp.plugins.sort(cmp);
+ writeFileSync(MARKETPLACE, JSON.stringify(mp, null, 2) + "\n");
+ console.log(`sorted ${mp.plugins.length} plugins`);
+ process.exit(0);
+}
+
+for (let i = 1; i < mp.plugins.length; i++) {
+ if (cmp(mp.plugins[i - 1], mp.plugins[i]) > 0) {
+ console.error(
+ `marketplace.json plugins are not sorted: ` +
+ `'${mp.plugins[i - 1].name}' should come after '${mp.plugins[i].name}' (index ${i})`,
+ );
+ console.error(` run: bun .github/scripts/check-marketplace-sorted.ts --fix`);
+ process.exit(1);
+ }
+}
+
+console.log(`ok: ${mp.plugins.length} plugins sorted`);
diff --git a/.github/scripts/validate-marketplace.ts b/.github/scripts/validate-marketplace.ts
new file mode 100644
index 00000000..45f26007
--- /dev/null
+++ b/.github/scripts/validate-marketplace.ts
@@ -0,0 +1,77 @@
+#!/usr/bin/env bun
+/**
+ * Validates marketplace.json: well-formed JSON, plugins array present,
+ * each entry has required fields, and no duplicate plugin names.
+ *
+ * Usage:
+ * bun validate-marketplace.ts <path-to-marketplace.json>
+ */
+
+import { readFile } from "fs/promises";
+
+async function main() {
+ const filePath = process.argv[2];
+ if (!filePath) {
+ console.error("Usage: validate-marketplace.ts <path-to-marketplace.json>");
+ process.exit(2);
+ }
+
+ const content = await readFile(filePath, "utf-8");
+
+ let parsed: unknown;
+ try {
+ parsed = JSON.parse(content);
+ } catch (err) {
+ console.error(
+ `ERROR: ${filePath} is not valid JSON: ${err instanceof Error ? err.message : err}`
+ );
+ process.exit(1);
+ }
+
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
+ console.error(`ERROR: ${filePath} must be a JSON object`);
+ process.exit(1);
+ }
+
+ const marketplace = parsed as Record<string, unknown>;
+ if (!Array.isArray(marketplace.plugins)) {
+ console.error(`ERROR: ${filePath} missing "plugins" array`);
+ process.exit(1);
+ }
+
+ const errors: string[] = [];
+ const seen = new Set<string>();
+ const required = ["name", "description", "source"] as const;
+
+ marketplace.plugins.forEach((p, i) => {
+ if (!p || typeof p !== "object") {
+ errors.push(`plugins[${i}]: must be an object`);
+ return;
+ }
+ const entry = p as Record<string, unknown>;
+ for (const field of required) {
+ if (!entry[field]) {
+ errors.push(`plugins[${i}] (${entry.name ?? "?"}): missing required field "${field}"`);
+ }
+ }
+ if (typeof entry.name === "string") {
+ if (seen.has(entry.name)) {
+ errors.push(`plugins[${i}]: duplicate plugin name "${entry.name}"`);
+ }
+ seen.add(entry.name);
+ }
+ });
+
+ if (errors.length) {
+ console.error(`ERROR: ${filePath} has ${errors.length} validation error(s):`);
+ for (const e of errors) console.error(` - ${e}`);
+ process.exit(1);
+ }
+
+ console.log(`OK: ${marketplace.plugins.length} plugins, no duplicates, all required fields present`);
+}
+
+main().catch((err) => {
+ console.error("Fatal error:", err);
+ process.exit(2);
+});