mirror of
https://github.com/prdlk/leetcode.git
synced 2026-09-16 23:16:26 +00:00
feat(cli): add SQLite cache, shared solution runner, and submit command
This commit is contained in:
+2
-50
@@ -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?");
|
||||
|
||||
Reference in New Issue
Block a user