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