Perform code optimization and document cleanup #1
@@ -512,7 +512,7 @@ async function clearGeneratedRoot(rootDir) {
|
|||||||
// Remove the directory only if nothing protected remains inside it.
|
// Remove the directory only if nothing protected remains inside it.
|
||||||
const remaining = await readdir(fullPath).catch(() => []);
|
const remaining = await readdir(fullPath).catch(() => []);
|
||||||
if (remaining.length === 0) {
|
if (remaining.length === 0) {
|
||||||
await rm(fullPath, { force: true });
|
await rm(fullPath, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await rm(fullPath, { force: true });
|
await rm(fullPath, { force: true });
|
||||||
|
|||||||
@@ -203,6 +203,15 @@ async function interactiveAnswers({ dryRun = false } = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function readAnswers(source) {
|
||||||
|
if (source === "-") {
|
||||||
|
let content = "";
|
||||||
|
for await (const chunk of input) content += chunk;
|
||||||
|
return JSON.parse(content);
|
||||||
|
}
|
||||||
|
return JSON.parse(await readFile(path.resolve(source), "utf8"));
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const args = parseArgs(process.argv.slice(2));
|
const args = parseArgs(process.argv.slice(2));
|
||||||
if (args.help) {
|
if (args.help) {
|
||||||
@@ -216,7 +225,7 @@ async function main() {
|
|||||||
|
|
||||||
let answers;
|
let answers;
|
||||||
if (args.answers) {
|
if (args.answers) {
|
||||||
answers = JSON.parse(await readFile(path.resolve(args.answers), "utf8"));
|
answers = await readAnswers(args.answers);
|
||||||
} else {
|
} else {
|
||||||
answers = await buildCliSelection(args);
|
answers = await buildCliSelection(args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
|
import { mkdtemp, mkdir, writeFile, rm, readFile } from "node:fs/promises";
|
||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
@@ -25,6 +25,7 @@ const {
|
|||||||
makePackageJsonContent,
|
makePackageJsonContent,
|
||||||
getGeneratedRoots,
|
getGeneratedRoots,
|
||||||
buildManifest,
|
buildManifest,
|
||||||
|
generateSkills,
|
||||||
} = await import(`${SCRIPTS_DIR}/generate-skills.mjs`);
|
} = await import(`${SCRIPTS_DIR}/generate-skills.mjs`);
|
||||||
|
|
||||||
// ── detectFileType ────────────────────────────────────────────────────────
|
// ── detectFileType ────────────────────────────────────────────────────────
|
||||||
@@ -348,3 +349,17 @@ test("buildManifest: sha256 matches actual file content", async () => {
|
|||||||
await rm(dir, { recursive: true, force: true });
|
await rm(dir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("generateSkills: clears pre-existing empty generated directories without EISDIR", async () => {
|
||||||
|
const targetRoot = await mkdtemp(path.join(tmpdir(), "generate-skills-target-"));
|
||||||
|
try {
|
||||||
|
await mkdir(path.join(targetRoot, "skills", "create-plan", "claude-code", "templates"), { recursive: true });
|
||||||
|
|
||||||
|
await generateSkills(path.resolve(SCRIPTS_DIR, ".."), { targetRoot });
|
||||||
|
|
||||||
|
await readFile(path.join(targetRoot, "skills", "create-plan", "claude-code", "SKILL.md"), "utf8");
|
||||||
|
await readFile(path.join(targetRoot, "skills", "create-plan", "claude-code", "templates", "milestone-plan.md"), "utf8");
|
||||||
|
} finally {
|
||||||
|
await rm(targetRoot, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ test("cli exits without confirmation when no operations are planned", () => {
|
|||||||
const output = execFileSync(process.execPath, [
|
const output = execFileSync(process.execPath, [
|
||||||
path.join(REPO_ROOT, "scripts", "manage-skills.mjs"),
|
path.join(REPO_ROOT, "scripts", "manage-skills.mjs"),
|
||||||
"--answers",
|
"--answers",
|
||||||
"/dev/stdin",
|
"-",
|
||||||
], {
|
], {
|
||||||
cwd: REPO_ROOT,
|
cwd: REPO_ROOT,
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"path": "run-review.sh",
|
"path": "run-review.sh",
|
||||||
"kind": "file",
|
"kind": "file",
|
||||||
"mode": "755",
|
"mode": "755",
|
||||||
"sha256": "c5e4fd082ee1a14059183d2cd2c45653e16d63821edf9cf82e548c9307d29e75"
|
"sha256": "1af5076f0e4451c0870109216ee5780553ef7d402ec1359f38afefdaf53627c1"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ kill_child_process_group() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2329
|
# shellcheck disable=SC2317,SC2329
|
||||||
handle_signal() {
|
handle_signal() {
|
||||||
local signal_name=$1
|
local signal_name=$1
|
||||||
INTERRUPTED=1
|
INTERRUPTED=1
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ kill_child_process_group() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2329
|
# shellcheck disable=SC2317,SC2329
|
||||||
handle_signal() {
|
handle_signal() {
|
||||||
local signal_name=$1
|
local signal_name=$1
|
||||||
INTERRUPTED=1
|
INTERRUPTED=1
|
||||||
|
|||||||
Reference in New Issue
Block a user