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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -18,6 +19,7 @@ jobs:
- run: npx biome check .

test:
name: Node ${{ matrix.node-version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -28,4 +30,4 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: node --test test/*.test.js
- run: node --test test/cli.test.js test/scaffold.test.js
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node --test test/*.test.js
- run: node --test test/cli.test.js test/scaffold.test.js

release:
needs: test
Expand Down
52 changes: 35 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { execSync } from "node:child_process";
import { execFileSync } from "node:child_process";
import { existsSync, readFileSync, rmSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
Expand All @@ -12,22 +12,22 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const pkg = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"));

const HELP = `
${bold("create-claude-plugin")} Scaffold a Claude Code plugin
${bold("create-claude-plugin")} ${dim("—")} ${dim("Scaffold a Claude Code plugin")}

${bold("Usage")}
$ create-claude-plugin <plugin-name> [options]
$ npx create-claude-plugin <plugin-name> [options]
${dim("$")} ${cyan("create-claude-plugin")} ${green("<plugin-name>")} ${dim("[options]")}
${dim("$")} ${cyan("npx create-claude-plugin")} ${green("<plugin-name>")} ${dim("[options]")}

${bold("Options")}
-y, --yes Skip prompts and use defaults
--no-git Skip git init
-v, --version Show version number
-h, --help Show this help message
${cyan("-y")}, ${cyan("--yes")} Skip prompts and use defaults
${cyan("--no-git")} Skip git init
${cyan("-v")}, ${cyan("--version")} Show version number
${cyan("-h")}, ${cyan("--help")} Show this help message

${bold("Examples")}
$ npx create-claude-plugin my-plugin
$ npx create-claude-plugin my-plugin --yes
$ npx create-claude-plugin my-plugin --yes --no-git
${dim("$")} ${cyan("npx create-claude-plugin")} ${green("my-plugin")}
${dim("$")} ${cyan("npx create-claude-plugin")} ${green("my-plugin")} ${cyan("--yes")}
${dim("$")} ${cyan("npx create-claude-plugin")} ${green("my-plugin")} ${cyan("--yes --no-git")}
`;

const NAME_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
Expand Down Expand Up @@ -81,14 +81,32 @@ function checkNodeVersion() {
}
}

function hasGitUser() {
try {
execFileSync("git", ["config", "user.name"], { stdio: "ignore" });
return true;
} catch {
return false;
}
}

function gitInit(dir) {
const opts = { cwd: dir, stdio: "ignore" };
try {
execSync("git init", { cwd: dir, stdio: "ignore" });
execSync("git add -A", { cwd: dir, stdio: "ignore" });
execSync('git commit -m "Initial commit from create-claude-plugin"', {
cwd: dir,
stdio: "ignore",
});
execFileSync("git", ["init"], opts);
execFileSync("git", ["add", "-A"], opts);
const commitArgs = hasGitUser()
? ["commit", "-m", "Initial commit from create-claude-plugin"]
: [
"-c",
"user.name=create-claude-plugin",
"-c",
"user.email=noreply",
"commit",
"-m",
"Initial commit from create-claude-plugin",
];
execFileSync("git", commitArgs, opts);
return true;
} catch {
return false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"lib/"
],
"scripts": {
"test": "node --test test/*.test.js",
"test": "node --test test/cli.test.js test/scaffold.test.js",
"lint": "biome check .",
"lint:fix": "biome check --write .",
"release": "semantic-release"
Expand Down
6 changes: 4 additions & 2 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { existsSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { dirname, join } from "node:path";
import { afterEach, describe, it } from "node:test";
import { fileURLToPath } from "node:url";

const CLI = join(import.meta.dirname, "..", "index.js");
const __dirname = dirname(fileURLToPath(import.meta.url));
const CLI = join(__dirname, "..", "index.js");
let tempDir;

function run(args, opts = {}) {
Expand Down
19 changes: 13 additions & 6 deletions test/scaffold.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import assert from "node:assert/strict";
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { join, posix, sep } from "node:path";
import { afterEach, beforeEach, describe, it } from "node:test";
import { scaffold } from "../lib/scaffold.js";

function toPosix(filePath) {
return filePath.split(sep).join(posix.sep);
}

describe("scaffold", () => {
let tempDir;

Expand Down Expand Up @@ -243,9 +247,10 @@ describe("scaffold", () => {
components: ["Skills"],
});

const normalized = files.map(toPosix);
assert.ok(Array.isArray(files));
assert.ok(files.includes(".claude-plugin/plugin.json"));
assert.ok(files.includes("skills/hello/SKILL.md"));
assert.ok(normalized.includes(".claude-plugin/plugin.json"));
assert.ok(normalized.includes("skills/hello/SKILL.md"));
assert.ok(!files.some((f) => f.startsWith("/")));
});

Expand All @@ -267,8 +272,10 @@ describe("scaffold", () => {
components: ["Skills", "Agents"],
});

assert.ok(files1.length < files2.length);
assert.ok(!files1.includes("agents/example.md"));
assert.ok(files2.includes("agents/example.md"));
const norm1 = files1.map(toPosix);
const norm2 = files2.map(toPosix);
assert.ok(norm1.length < norm2.length);
assert.ok(!norm1.includes("agents/example.md"));
assert.ok(norm2.includes("agents/example.md"));
});
});
Loading