init command
This commit is contained in:
parent
1642272fae
commit
f724fc0ecb
5 changed files with 251 additions and 220 deletions
24
cmd/init.ts
Normal file
24
cmd/init.ts
Normal 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", "[]");
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue