2020-11-05 09:53:21 -05:00
|
|
|
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
|
2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-02-21 12:47:08 -05:00
|
|
|
import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js";
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
async function dprint() {
|
2021-05-06 00:22:24 -04:00
|
|
|
const configFile = join(ROOT_PATH, ".dprint.json");
|
2020-11-05 09:53:21 -05:00
|
|
|
const execPath = getPrebuiltToolPath("dprint");
|
2022-12-01 10:51:47 -05:00
|
|
|
const cmd = new Deno.Command(execPath, {
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["fmt", "--config=" + configFile],
|
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
2022-12-01 10:51:47 -05:00
|
|
|
|
|
|
|
const { code } = await cmd.output();
|
|
|
|
|
|
|
|
if (code > 0) {
|
2020-11-05 09:53:21 -05:00
|
|
|
throw new Error("dprint failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await Deno.chdir(ROOT_PATH);
|
|
|
|
await dprint();
|
|
|
|
|
|
|
|
if (Deno.args.includes("--check")) {
|
2022-12-01 10:51:47 -05:00
|
|
|
const cmd = new Deno.Command("git", {
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["status", "-uno", "--porcelain", "--ignore-submodules"],
|
|
|
|
stderr: "inherit",
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
|
|
|
|
2022-12-01 10:51:47 -05:00
|
|
|
const { code, stdout } = await cmd.output();
|
|
|
|
|
|
|
|
if (code > 0) {
|
2020-11-05 09:53:21 -05:00
|
|
|
throw new Error("git status failed");
|
|
|
|
}
|
2022-05-18 16:00:11 -04:00
|
|
|
const out = new TextDecoder().decode(stdout);
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
if (out) {
|
|
|
|
console.log("run tools/format.js");
|
|
|
|
console.log(out);
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await main();
|