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");
|
|
|
|
const p = Deno.run({
|
2020-11-09 14:56:43 -05:00
|
|
|
cmd: [execPath, "fmt", "--config=" + configFile],
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
|
|
|
const { success } = await p.status();
|
|
|
|
if (!success) {
|
|
|
|
throw new Error("dprint failed");
|
|
|
|
}
|
|
|
|
p.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await Deno.chdir(ROOT_PATH);
|
|
|
|
await dprint();
|
|
|
|
|
|
|
|
if (Deno.args.includes("--check")) {
|
|
|
|
const git = Deno.run({
|
|
|
|
cmd: ["git", "status", "-uno", "--porcelain", "--ignore-submodules"],
|
|
|
|
stdout: "piped",
|
|
|
|
});
|
|
|
|
|
|
|
|
const { success } = await git.status();
|
|
|
|
if (!success) {
|
|
|
|
throw new Error("git status failed");
|
|
|
|
}
|
|
|
|
const out = new TextDecoder().decode(await git.output());
|
|
|
|
git.close();
|
|
|
|
|
|
|
|
if (out) {
|
|
|
|
console.log("run tools/format.js");
|
|
|
|
console.log(out);
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await main();
|