init command

This commit is contained in:
grngxd 2025-06-24 13:56:56 +01:00
parent 1642272fae
commit f724fc0ecb
5 changed files with 251 additions and 220 deletions

24
cmd/init.ts Normal file
View file

@ -0,0 +1,24 @@
import type { Command } from "commander";
import { readdirSync, writeFileSync } from "fs";
import * as h from "hjson";
export const registerInitCommand = (p: Command) => {
p
.command("init")
.action(() => {
const dir = readdirSync(process.cwd(), { withFileTypes: true })
.filter((dirent) => dirent.isFile() && (dirent.name.endsWith("mix.hjson") || dirent.name === "mix.lock"));
if (dir.length > 0) {
console.error("Error: Mix project already initialized. Please remove existing .mix.hjson or mix.lock files.");
process.exit(1);
}
writeFileSync("mix.hjson", h.stringify({
default: {
packages: []
}
}));
writeFileSync("mix.lock", "[]");
});
}