feat(cli): add SQLite cache, shared solution runner, and submit command

This commit is contained in:
Prad Nukala
2026-08-26 15:25:35 -04:00
parent f1445a071f
commit d57d75efcc
6 changed files with 307 additions and 102 deletions
+2 -50
View File
@@ -2,54 +2,6 @@
/**
* Fuzzy-select a solution file from work/ and run leetcode-cli tests on it.
*/
import { autocomplete, cancel, isCancel, log } from "@clack/prompts";
import { join, relative } from "node:path";
import { runOnSolution } from "./solutions";
const ROOT = join(import.meta.dir, "..", "..");
const WORK_DIR = join(ROOT, "work");
const files = [...new Bun.Glob("**/*.{js,ts,py,java,c,cpp,go,rs,rb,swift,kt,cs}").scanSync({ cwd: WORK_DIR })]
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
if (files.length === 0) {
log.error(`No solution files found in ${relative(process.cwd(), WORK_DIR)}/`);
process.exit(1);
}
const picked = await autocomplete<string>({
message: "Test which solution?",
placeholder: "Type to search...",
maxItems: 12,
options: files.map((f) => {
// work layout: Difficulty/Category/<id>.<slug>.<ext>
const [difficulty, category, name] = f.split("/");
return {
value: f,
label: name ?? f,
hint: category ? `${difficulty} · ${category}` : difficulty,
};
}),
filter: (search, option) => {
const haystack = option.value.toLowerCase();
return search
.toLowerCase()
.split(/\s+/)
.every((token) => haystack.includes(token));
},
});
if (isCancel(picked)) {
cancel("Nothing selected.");
process.exit(0);
}
const proc = Bun.spawn(
[
// bun installs workspace-dep bins into this package's node_modules, not the root's
join(import.meta.dir, "node_modules", ".bin", "leetcode"),
"test",
join(WORK_DIR, picked),
],
{ cwd: ROOT, stdio: ["inherit", "inherit", "inherit"] },
);
process.exit(await proc.exited);
await runOnSolution("test", "Test which solution?");