use home dir for init
This commit is contained in:
parent
f724fc0ecb
commit
eac55e01c5
5 changed files with 45 additions and 11 deletions
11
cmd/init.ts
11
cmd/init.ts
|
@ -1,24 +1,29 @@
|
|||
import type { Command } from "commander";
|
||||
import { readdirSync, writeFileSync } from "fs";
|
||||
import * as h from "hjson";
|
||||
import { homedir } from "os";
|
||||
import path from "path";
|
||||
import { isDev } from "../lib";
|
||||
|
||||
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"));
|
||||
.filter((dirent) => dirent.isFile() && (dirent.name.endsWith("mix.hjson") || dirent.name === "mix.lock") && !dirent.name.startsWith("_"));
|
||||
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({
|
||||
// userhomedir/.mix/mix.hjson
|
||||
const mixDir = isDev ? "" : path.join(homedir(), ".mix");
|
||||
writeFileSync(path.join(mixDir, "mix.hjson"), h.stringify({
|
||||
default: {
|
||||
packages: []
|
||||
}
|
||||
}));
|
||||
|
||||
writeFileSync("mix.lock", "[]");
|
||||
writeFileSync(path.join(mixDir, "mix.lock"), "[]");
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue