diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-01-13 13:42:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 13:42:15 -0500 |
commit | 3d423e114e46f206ad2c6bfa5dfcb22094c5d2f6 (patch) | |
tree | 2bc1e25c9703128cd0b0ceccea63f659750226f2 /tools/format.js | |
parent | 377f59327344bbb4f37b2eec189ae981a9a9db45 (diff) |
chore: small cleanup of scripts in ./tools and run copyright checker in lint.js (#17393)
Diffstat (limited to 'tools/format.js')
-rwxr-xr-x | tools/format.js | 54 |
1 files changed, 12 insertions, 42 deletions
diff --git a/tools/format.js b/tools/format.js index 223eb1b0d..bd34b1cfd 100755 --- a/tools/format.js +++ b/tools/format.js @@ -2,45 +2,15 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js"; -async function dprint() { - const configFile = join(ROOT_PATH, ".dprint.json"); - const execPath = getPrebuiltToolPath("dprint"); - const cmd = new Deno.Command(execPath, { - args: ["fmt", "--config=" + configFile], - stdout: "inherit", - stderr: "inherit", - }); - - const { code } = await cmd.output(); - - if (code > 0) { - throw new Error("dprint failed"); - } -} - -async function main() { - await Deno.chdir(ROOT_PATH); - await dprint(); - - if (Deno.args.includes("--check")) { - const cmd = new Deno.Command("git", { - args: ["status", "-uno", "--porcelain", "--ignore-submodules"], - stderr: "inherit", - }); - - const { code, stdout } = await cmd.output(); - - if (code > 0) { - throw new Error("git status failed"); - } - const out = new TextDecoder().decode(stdout); - - if (out) { - console.log("run tools/format.js"); - console.log(out); - Deno.exit(1); - } - } -} - -await main(); +const subcommand = Deno.args.includes("--check") ? "check" : "fmt"; +const configFile = join(ROOT_PATH, ".dprint.json"); +const execPath = getPrebuiltToolPath("dprint"); +const cmd = new Deno.Command(execPath, { + args: [subcommand, "--config=" + configFile], + cwd: ROOT_PATH, + stdout: "inherit", + stderr: "inherit", +}); + +const { code } = await cmd.output(); +Deno.exit(code); |