1
Fork 0

Change deprecated Deno.run to Deno.Command calls.

This commit is contained in:
Bauke 2023-06-05 13:27:29 +02:00
parent 89a1257e60
commit 7cbab0f4b7
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
8 changed files with 60 additions and 54 deletions

View File

@ -21,13 +21,11 @@ async function main(): Promise<void> {
if (options.install) { if (options.install) {
const extensions = await getSavedExtensions(options.file); const extensions = await getSavedExtensions(options.file);
const process = Deno.run({ await new Deno.Command("codium", {
cmd: [ args: [
"codium",
...extensions.flatMap((id) => ["--install-extension", id]), ...extensions.flatMap((id) => ["--install-extension", id]),
], ],
}); }).output();
await process.status();
} }
if (options.list) { if (options.list) {
@ -48,8 +46,8 @@ async function main(): Promise<void> {
} }
async function getInstalledExtensions(): Promise<string[]> { async function getInstalledExtensions(): Promise<string[]> {
const extensions = await runAndReturnStdout({ const extensions = await runAndReturnStdout("codium", {
cmd: ["codium", "--list-extensions"], args: ["--list-extensions"],
}); });
return extensions.trim().split("\n"); return extensions.trim().split("\n");
} }

View File

@ -8,7 +8,7 @@ async function main(): Promise<void> {
'Copy NixOS configuration from "$BAUKE_DIR/nix/<hostname>/" to "/etc/nixos/"', 'Copy NixOS configuration from "$BAUKE_DIR/nix/<hostname>/" to "/etc/nixos/"',
) )
.option("--hostname", "The machine's configuration to copy.", { .option("--hostname", "The machine's configuration to copy.", {
default: (await runAndReturnStdout({ cmd: ["hostname"] })).trim(), default: (await runAndReturnStdout("hostname")).trim(),
}) })
.option("--diff", 'Output diffs between local and "/etc/nixos/" files.', { .option("--diff", 'Output diffs between local and "/etc/nixos/" files.', {
standalone: true, standalone: true,
@ -27,29 +27,28 @@ async function main(): Promise<void> {
if (options.diff) { if (options.diff) {
for (const file of files) { for (const file of files) {
const filename = file.slice(file.lastIndexOf("/") + 1); const filename = file.slice(file.lastIndexOf("/") + 1);
await Deno.run({ await new Deno.Command("delta", {
cmd: ["delta", `/etc/nixos/${filename}`, file], args: [`/etc/nixos/${filename}`, file],
}).status(); }).output();
} }
return; return;
} }
await Deno.run({ await new Deno.Command("sudo", {
cmd: [ args: [
"sudo",
"cp", "cp",
"--preserve=timestamps", "--preserve=timestamps",
"--verbose", "--verbose",
...files, ...files,
"/etc/nixos/", "/etc/nixos/",
], ],
}).status(); }).output();
if (options.rebuild) { if (options.rebuild) {
await Deno.run({ await new Deno.Command("sudo", {
cmd: ["sudo", "nixos-rebuild", options.rebuild], args: ["nixos-rebuild", options.rebuild],
}).status(); }).output();
} }
} }

View File

@ -41,17 +41,16 @@ async function main(): Promise<void> {
} }
async function downloadImage(url: string): Promise<void> { async function downloadImage(url: string): Promise<void> {
await Deno.run({ await new Deno.Command("curl", {
cmd: ["curl", "-fsLS", url, "-o", imagePath], args: ["-fsLS", url, "-o", imagePath],
}).status(); }).output();
} }
async function setWallpaper(file: string = imagePath): Promise<void> { async function setWallpaper(file: string = imagePath): Promise<void> {
const monitors = ["monitorHDMI-0", "monitorHDMI-1"]; const monitors = ["monitorHDMI-0", "monitorHDMI-1"];
for (const monitor of monitors) { for (const monitor of monitors) {
await Deno.run({ await new Deno.Command("xfconf-query", {
cmd: [ args: [
"xfconf-query",
"-c", "-c",
"xfce4-desktop", "xfce4-desktop",
"-p", "-p",
@ -59,7 +58,7 @@ async function setWallpaper(file: string = imagePath): Promise<void> {
"-s", "-s",
file, file,
], ],
}).status(); }).output();
} }
} }

View File

@ -49,9 +49,8 @@ async function main(): Promise<void> {
return; return;
} }
await Deno.run({ await new Deno.Command("youtube3", {
cmd: [ args: [
"youtube3",
"videos", "videos",
"update", "update",
"-r", "-r",
@ -63,7 +62,7 @@ async function main(): Promise<void> {
"-r", "-r",
`snippet.title=${title}`, `snippet.title=${title}`,
], ],
}).status(); }).output();
} }
function formatDescription(frontmatter: Frontmatter): string { function formatDescription(frontmatter: Frontmatter): string {

View File

@ -1,4 +1,5 @@
import { Command, nodeFs } from "./dependencies.ts"; import { Command } from "./dependencies.ts";
import { pathExists } from "./utilities.ts";
async function main(): Promise<void> { async function main(): Promise<void> {
const { args, options } = await new Command() const { args, options } = await new Command()
@ -20,7 +21,7 @@ async function main(): Promise<void> {
const [file, text] = args; const [file, text] = args;
if (nodeFs.existsSync(file)) { if (await pathExists(file)) {
if (options.overwrite) { if (options.overwrite) {
await Deno.remove(file); await Deno.remove(file);
} else { } else {
@ -29,9 +30,8 @@ async function main(): Promise<void> {
} }
} }
await Deno.run({ await new Deno.Command("gegl", {
cmd: [ args: [
"gegl",
"-o", "-o",
file, file,
"--", "--",
@ -42,16 +42,15 @@ async function main(): Promise<void> {
width: options.width, width: options.width,
}), }),
], ],
}).status(); }).output();
if (!nodeFs.existsSync(file)) { if (!await pathExists(file)) {
console.log("Something went wrong with GEGL."); console.log("Something went wrong with GEGL.");
Deno.exit(1); Deno.exit(1);
} }
await Deno.run({ await new Deno.Command("convert", {
cmd: [ args: [
"convert",
file, file,
"-background", "-background",
"transparent", "transparent",
@ -61,10 +60,10 @@ async function main(): Promise<void> {
`${options.width}x${options.height}`, `${options.width}x${options.height}`,
file, file,
], ],
}).status(); }).output();
if (options.clean) { if (options.clean) {
await Deno.run({ cmd: ["mat2", "--inplace", file] }).status(); await new Deno.Command("mat2", { args: ["--inplace", file] }).output();
} }
} }

View File

@ -24,19 +24,19 @@ async function main(): Promise<void> {
} }
async function gitPush(remote: string, args: string[]): Promise<void> { async function gitPush(remote: string, args: string[]): Promise<void> {
await Deno.run({ await new Deno.Command("git", {
cmd: [ args: [
"git", "git",
"push", "push",
"--follow-tags", "--follow-tags",
remote, remote,
...args, ...args,
], ],
}).status(); }).output();
} }
async function gitRemote(): Promise<string[]> { async function gitRemote(): Promise<string[]> {
const output = await runAndReturnStdout({ cmd: ["git", "remote"] }); const output = await runAndReturnStdout("git", { args: ["remote"] });
return output.trim().split("\n").filter((remote) => remote.length > 0); return output.trim().split("\n").filter((remote) => remote.length > 0);
} }

View File

@ -1,4 +1,5 @@
import { Command, nodeFs } from "./dependencies.ts"; import { Command } from "./dependencies.ts";
import { pathExists } from "./utilities.ts";
const hiddenApi = "http://127.0.0.1:7813"; const hiddenApi = "http://127.0.0.1:7813";
const remoteApi = "http://127.0.0.1:7814/api1"; const remoteApi = "http://127.0.0.1:7814/api1";
@ -62,7 +63,7 @@ async function main(): Promise<void> {
if (options.writeImage) { if (options.writeImage) {
const status = await getStatus(); const status = await getStatus();
const path = `/tmp/tauon-cover-${status.id}.jpg`; const path = `/tmp/tauon-cover-${status.id}.jpg`;
if (nodeFs.existsSync(path)) { if (await pathExists(path)) {
console.log(path); console.log(path);
return; return;
} }
@ -95,9 +96,9 @@ async function getStatus(): Promise<Status> {
async function notifyCurrentSong(): Promise<void> { async function notifyCurrentSong(): Promise<void> {
const status = await getStatus(); const status = await getStatus();
await Deno.run({ await new Deno.Command("notify-send", {
cmd: ["notify-send", status.title, status.artist], args: [status.title, status.artist],
}).status(); }).output();
} }
if (import.meta.main) { if (import.meta.main) {

View File

@ -1,14 +1,25 @@
import { nodeUtil, toml } from "./dependencies.ts"; import { toml } from "./dependencies.ts";
export async function pathExists(path: string): Promise<boolean> {
try {
await Deno.stat(path);
return true;
} catch {
return false;
}
}
export function stringifyJsonPretty(input: unknown): string { export function stringifyJsonPretty(input: unknown): string {
return JSON.stringify(input, null, 2); return JSON.stringify(input, null, 2);
} }
export async function runAndReturnStdout( export async function runAndReturnStdout(
options: Deno.RunOptions, command: string,
options: Deno.CommandOptions = {},
): Promise<string> { ): Promise<string> {
const process = Deno.run({ stdout: "piped", ...options }); const process = new Deno.Command(command, { stdout: "piped", ...options });
return new nodeUtil.TextDecoder().decode(await process.output()); const { stdout } = await process.output();
return new TextDecoder().decode(stdout);
} }
export function tomlFrontmatter<T>( export function tomlFrontmatter<T>(