refactorizar helpers
asdfasdf
This commit is contained in:
parent
db7ae846f7
commit
4380042db3
6 changed files with 25 additions and 22 deletions
|
@ -11,7 +11,7 @@ import {
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { cwd } from "node:process";
|
import { cwd } from "node:process";
|
||||||
import { execFile } from "./helpers.js";
|
import { execFile } from "./helpers/better-api";
|
||||||
|
|
||||||
export class Alpine {
|
export class Alpine {
|
||||||
dir: string;
|
dir: string;
|
||||||
|
|
18
helpers/better-api.ts
Normal file
18
helpers/better-api.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { promisify } from "node:util";
|
||||||
|
import {
|
||||||
|
execFile as execFileCallback,
|
||||||
|
spawn as spawnCallback,
|
||||||
|
} from "node:child_process";
|
||||||
|
import { access } from "node:fs/promises";
|
||||||
|
|
||||||
|
export const execFile = promisify(execFileCallback);
|
||||||
|
export const spawn = promisify(spawnCallback);
|
||||||
|
|
||||||
|
export async function canAccess(path: string): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
await access(path);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,22 +1,5 @@
|
||||||
import { promisify } from "node:util";
|
|
||||||
import {
|
|
||||||
execFile as execFileCallback,
|
|
||||||
spawn as spawnCallback,
|
|
||||||
} from "node:child_process";
|
|
||||||
import { access } from "node:fs/promises";
|
|
||||||
import { getuid } from "node:process";
|
import { getuid } from "node:process";
|
||||||
|
import { execFile } from "./better-api";
|
||||||
export const execFile = promisify(execFileCallback);
|
|
||||||
export const spawn = promisify(spawnCallback);
|
|
||||||
|
|
||||||
export async function canAccess(path: string): Promise<boolean> {
|
|
||||||
try {
|
|
||||||
await access(path);
|
|
||||||
return true;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function sudoChown(path: string, owner: string): Promise<void> {
|
export async function sudoChown(path: string, owner: string): Promise<void> {
|
||||||
await execFile("sudo", ["chown", owner, path]);
|
await execFile("sudo", ["chown", owner, path]);
|
3
index.ts
3
index.ts
|
@ -3,7 +3,8 @@ import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { cwd } from "node:process";
|
import { cwd } from "node:process";
|
||||||
import { Alpine } from "./alpine.js";
|
import { Alpine } from "./alpine.js";
|
||||||
import { execFile, spawn, sudoChownToRunningUser } from "./helpers.js";
|
import { execFile } from "./helpers/better-api.js";
|
||||||
|
import { sudoChownToRunningUser } from "./helpers/sudo.js";
|
||||||
import { setupKernel } from "./kernel.js";
|
import { setupKernel } from "./kernel.js";
|
||||||
import { runQemu } from "./qemu.js";
|
import { runQemu } from "./qemu.js";
|
||||||
import { Runit } from "./runit/index.js";
|
import { Runit } from "./runit/index.js";
|
||||||
|
|
|
@ -2,7 +2,8 @@ import { constants } from "node:fs";
|
||||||
import { copyFile } from "node:fs/promises";
|
import { copyFile } from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { Alpine } from "./alpine.js";
|
import { Alpine } from "./alpine.js";
|
||||||
import { canAccess, sudoChownToRunningUser, sudoRm } from "./helpers.js";
|
import { canAccess } from "./helpers/better-api.js";
|
||||||
|
import { sudoChownToRunningUser, sudoRm } from "./helpers/sudo.js";
|
||||||
|
|
||||||
export type Kind = "lts" | "virt";
|
export type Kind = "lts" | "virt";
|
||||||
export type Kernel = {
|
export type Kernel = {
|
||||||
|
|
2
qemu.ts
2
qemu.ts
|
@ -1,7 +1,7 @@
|
||||||
import { mkdtemp, rm } from "node:fs/promises";
|
import { mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { execFile } from "./helpers.js";
|
import { execFile } from "./helpers/better-api.js";
|
||||||
import { Kernel } from "./kernel.js";
|
import { Kernel } from "./kernel.js";
|
||||||
|
|
||||||
export async function runQemu(
|
export async function runQemu(
|
||||||
|
|
Loading…
Reference in a new issue