use home dir for init
This commit is contained in:
parent
f724fc0ecb
commit
eac55e01c5
5 changed files with 45 additions and 11 deletions
16
cmd/sync.ts
16
cmd/sync.ts
|
@ -3,6 +3,9 @@ import type { Command } from "commander";
|
|||
import { createHash } from "crypto";
|
||||
import { readdirSync, readFileSync, writeFileSync } from "fs";
|
||||
import * as h from "hjson";
|
||||
import { homedir } from "os";
|
||||
import path from "path";
|
||||
import { isDev } from "../lib";
|
||||
|
||||
export const registerSyncCommand = (p: Command) => {
|
||||
p
|
||||
|
@ -10,7 +13,7 @@ export const registerSyncCommand = (p: Command) => {
|
|||
.action(() => {
|
||||
const getMixFiles = (): { name: string, content: MixFile}[] => {
|
||||
const files = readdirSync(process.cwd(), { withFileTypes: true })
|
||||
.filter((dirent) => dirent.isFile() && dirent.name.endsWith(".hjson") && !dirent.name.startsWith("_"))
|
||||
.filter((dirent) => dirent.isFile() && dirent.name.endsWith("mix.hjson") && !dirent.name.startsWith("_"))
|
||||
.map((dirent) => ({
|
||||
name: dirent.name,
|
||||
content: h.parse(readFileSync(dirent.name, "utf-8"))
|
||||
|
@ -106,7 +109,7 @@ export const registerSyncCommand = (p: Command) => {
|
|||
|
||||
for (const pkg of installing) {
|
||||
console.log(`Installing ${pkg.id} version ${pkg.version}`);
|
||||
exec(`winget install ${pkg.id} --version ${pkg.version}`, (error, stdout, stderr) => {
|
||||
exec(`winget install --id ${pkg.id} --version ${pkg.version}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error installing ${pkg.id}: ${error.message}`);
|
||||
return;
|
||||
|
@ -126,7 +129,8 @@ export const registerSyncCommand = (p: Command) => {
|
|||
|
||||
lock.push(l);
|
||||
const content = h.stringify(lock);
|
||||
writeFileSync("mix.lock", content, "utf-8");
|
||||
const mixDir = isDev ? "" : path.join(homedir(), ".mix");
|
||||
writeFileSync(path.join(mixDir, "mix.lock"), content, "utf-8");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -147,7 +151,8 @@ export const registerSyncCommand = (p: Command) => {
|
|||
if (index !== -1) {
|
||||
lock.splice(index, 1);
|
||||
const content = h.stringify(lock);
|
||||
writeFileSync("mix.lock", content, "utf-8");
|
||||
const mixDir = isDev ? "" : path.join(homedir(), ".mix");
|
||||
writeFileSync(path.join(mixDir, "mix.lock"), content, "utf-8");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -179,7 +184,8 @@ export const registerSyncCommand = (p: Command) => {
|
|||
}
|
||||
|
||||
const content = h.stringify(lock);
|
||||
writeFileSync("mix.lock", content, "utf-8");
|
||||
const mixDir = isDev ? "" : path.join(homedir(), ".mix");
|
||||
writeFileSync(path.join(mixDir, "mix.lock"), content, "utf-8");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue