refactorizar helpers

asdfasdf
This commit is contained in:
Cat /dev/Nulo 2023-02-02 19:02:38 -03:00
parent db7ae846f7
commit 4380042db3
6 changed files with 25 additions and 22 deletions

View file

@ -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
View 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;
}
}

View file

@ -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]);

View file

@ -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";

View file

@ -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 = {

View file

@ -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(