2020-11-05 09:53:21 -05:00
|
|
|
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
|
2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 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-07-21 04:45:15 -04:00
|
|
|
const { success } = await Deno.spawn(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-07-21 04:45:15 -04:00
|
|
|
if (!success) {
|
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-07-21 04:45:15 -04:00
|
|
|
const { success, stdout } = await Deno.spawn("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-07-21 04:45:15 -04:00
|
|
|
if (!success) {
|
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();
|