From 7cbab0f4b7829fa85603dd1225d07472c222472b Mon Sep 17 00:00:00 2001 From: Bauke Date: Mon, 5 Jun 2023 13:27:29 +0200 Subject: [PATCH] Change deprecated Deno.run to Deno.Command calls. --- .bauke/scripts/codium-extensions.ts | 12 +++++------- .bauke/scripts/copy-nixos-config.ts | 21 ++++++++++----------- .bauke/scripts/desktop-wallpaper.ts | 13 ++++++------- .bauke/scripts/edit-youtube-video.ts | 7 +++---- .bauke/scripts/project-avatar.ts | 23 +++++++++++------------ .bauke/scripts/simple-git-push.ts | 8 ++++---- .bauke/scripts/tauon-controls.ts | 11 ++++++----- .bauke/scripts/utilities.ts | 19 +++++++++++++++---- 8 files changed, 60 insertions(+), 54 deletions(-) diff --git a/.bauke/scripts/codium-extensions.ts b/.bauke/scripts/codium-extensions.ts index 0bf9e11..255be63 100644 --- a/.bauke/scripts/codium-extensions.ts +++ b/.bauke/scripts/codium-extensions.ts @@ -21,13 +21,11 @@ async function main(): Promise { if (options.install) { const extensions = await getSavedExtensions(options.file); - const process = Deno.run({ - cmd: [ - "codium", + await new Deno.Command("codium", { + args: [ ...extensions.flatMap((id) => ["--install-extension", id]), ], - }); - await process.status(); + }).output(); } if (options.list) { @@ -48,8 +46,8 @@ async function main(): Promise { } async function getInstalledExtensions(): Promise { - const extensions = await runAndReturnStdout({ - cmd: ["codium", "--list-extensions"], + const extensions = await runAndReturnStdout("codium", { + args: ["--list-extensions"], }); return extensions.trim().split("\n"); } diff --git a/.bauke/scripts/copy-nixos-config.ts b/.bauke/scripts/copy-nixos-config.ts index fa0ad5c..042e391 100644 --- a/.bauke/scripts/copy-nixos-config.ts +++ b/.bauke/scripts/copy-nixos-config.ts @@ -8,7 +8,7 @@ async function main(): Promise { 'Copy NixOS configuration from "$BAUKE_DIR/nix//" to "/etc/nixos/"', ) .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.', { standalone: true, @@ -27,29 +27,28 @@ async function main(): Promise { if (options.diff) { for (const file of files) { const filename = file.slice(file.lastIndexOf("/") + 1); - await Deno.run({ - cmd: ["delta", `/etc/nixos/${filename}`, file], - }).status(); + await new Deno.Command("delta", { + args: [`/etc/nixos/${filename}`, file], + }).output(); } return; } - await Deno.run({ - cmd: [ - "sudo", + await new Deno.Command("sudo", { + args: [ "cp", "--preserve=timestamps", "--verbose", ...files, "/etc/nixos/", ], - }).status(); + }).output(); if (options.rebuild) { - await Deno.run({ - cmd: ["sudo", "nixos-rebuild", options.rebuild], - }).status(); + await new Deno.Command("sudo", { + args: ["nixos-rebuild", options.rebuild], + }).output(); } } diff --git a/.bauke/scripts/desktop-wallpaper.ts b/.bauke/scripts/desktop-wallpaper.ts index df3108d..e1552e2 100644 --- a/.bauke/scripts/desktop-wallpaper.ts +++ b/.bauke/scripts/desktop-wallpaper.ts @@ -41,17 +41,16 @@ async function main(): Promise { } async function downloadImage(url: string): Promise { - await Deno.run({ - cmd: ["curl", "-fsLS", url, "-o", imagePath], - }).status(); + await new Deno.Command("curl", { + args: ["-fsLS", url, "-o", imagePath], + }).output(); } async function setWallpaper(file: string = imagePath): Promise { const monitors = ["monitorHDMI-0", "monitorHDMI-1"]; for (const monitor of monitors) { - await Deno.run({ - cmd: [ - "xfconf-query", + await new Deno.Command("xfconf-query", { + args: [ "-c", "xfce4-desktop", "-p", @@ -59,7 +58,7 @@ async function setWallpaper(file: string = imagePath): Promise { "-s", file, ], - }).status(); + }).output(); } } diff --git a/.bauke/scripts/edit-youtube-video.ts b/.bauke/scripts/edit-youtube-video.ts index a1a5e41..cd9d4ad 100644 --- a/.bauke/scripts/edit-youtube-video.ts +++ b/.bauke/scripts/edit-youtube-video.ts @@ -49,9 +49,8 @@ async function main(): Promise { return; } - await Deno.run({ - cmd: [ - "youtube3", + await new Deno.Command("youtube3", { + args: [ "videos", "update", "-r", @@ -63,7 +62,7 @@ async function main(): Promise { "-r", `snippet.title=${title}`, ], - }).status(); + }).output(); } function formatDescription(frontmatter: Frontmatter): string { diff --git a/.bauke/scripts/project-avatar.ts b/.bauke/scripts/project-avatar.ts index f6e00a9..480cfba 100644 --- a/.bauke/scripts/project-avatar.ts +++ b/.bauke/scripts/project-avatar.ts @@ -1,4 +1,5 @@ -import { Command, nodeFs } from "./dependencies.ts"; +import { Command } from "./dependencies.ts"; +import { pathExists } from "./utilities.ts"; async function main(): Promise { const { args, options } = await new Command() @@ -20,7 +21,7 @@ async function main(): Promise { const [file, text] = args; - if (nodeFs.existsSync(file)) { + if (await pathExists(file)) { if (options.overwrite) { await Deno.remove(file); } else { @@ -29,9 +30,8 @@ async function main(): Promise { } } - await Deno.run({ - cmd: [ - "gegl", + await new Deno.Command("gegl", { + args: [ "-o", file, "--", @@ -42,16 +42,15 @@ async function main(): Promise { width: options.width, }), ], - }).status(); + }).output(); - if (!nodeFs.existsSync(file)) { + if (!await pathExists(file)) { console.log("Something went wrong with GEGL."); Deno.exit(1); } - await Deno.run({ - cmd: [ - "convert", + await new Deno.Command("convert", { + args: [ file, "-background", "transparent", @@ -61,10 +60,10 @@ async function main(): Promise { `${options.width}x${options.height}`, file, ], - }).status(); + }).output(); if (options.clean) { - await Deno.run({ cmd: ["mat2", "--inplace", file] }).status(); + await new Deno.Command("mat2", { args: ["--inplace", file] }).output(); } } diff --git a/.bauke/scripts/simple-git-push.ts b/.bauke/scripts/simple-git-push.ts index 23c3262..d660764 100644 --- a/.bauke/scripts/simple-git-push.ts +++ b/.bauke/scripts/simple-git-push.ts @@ -24,19 +24,19 @@ async function main(): Promise { } async function gitPush(remote: string, args: string[]): Promise { - await Deno.run({ - cmd: [ + await new Deno.Command("git", { + args: [ "git", "push", "--follow-tags", remote, ...args, ], - }).status(); + }).output(); } async function gitRemote(): Promise { - const output = await runAndReturnStdout({ cmd: ["git", "remote"] }); + const output = await runAndReturnStdout("git", { args: ["remote"] }); return output.trim().split("\n").filter((remote) => remote.length > 0); } diff --git a/.bauke/scripts/tauon-controls.ts b/.bauke/scripts/tauon-controls.ts index 71bf54b..c694e5e 100644 --- a/.bauke/scripts/tauon-controls.ts +++ b/.bauke/scripts/tauon-controls.ts @@ -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 remoteApi = "http://127.0.0.1:7814/api1"; @@ -62,7 +63,7 @@ async function main(): Promise { if (options.writeImage) { const status = await getStatus(); const path = `/tmp/tauon-cover-${status.id}.jpg`; - if (nodeFs.existsSync(path)) { + if (await pathExists(path)) { console.log(path); return; } @@ -95,9 +96,9 @@ async function getStatus(): Promise { async function notifyCurrentSong(): Promise { const status = await getStatus(); - await Deno.run({ - cmd: ["notify-send", status.title, status.artist], - }).status(); + await new Deno.Command("notify-send", { + args: [status.title, status.artist], + }).output(); } if (import.meta.main) { diff --git a/.bauke/scripts/utilities.ts b/.bauke/scripts/utilities.ts index e21c70e..05fa5eb 100644 --- a/.bauke/scripts/utilities.ts +++ b/.bauke/scripts/utilities.ts @@ -1,14 +1,25 @@ -import { nodeUtil, toml } from "./dependencies.ts"; +import { toml } from "./dependencies.ts"; + +export async function pathExists(path: string): Promise { + try { + await Deno.stat(path); + return true; + } catch { + return false; + } +} export function stringifyJsonPretty(input: unknown): string { return JSON.stringify(input, null, 2); } export async function runAndReturnStdout( - options: Deno.RunOptions, + command: string, + options: Deno.CommandOptions = {}, ): Promise { - const process = Deno.run({ stdout: "piped", ...options }); - return new nodeUtil.TextDecoder().decode(await process.output()); + const process = new Deno.Command(command, { stdout: "piped", ...options }); + const { stdout } = await process.output(); + return new TextDecoder().decode(stdout); } export function tomlFrontmatter(