summaryrefslogtreecommitdiff
path: root/tools/format.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-11-05 15:53:21 +0100
committerGitHub <noreply@github.com>2020-11-05 15:53:21 +0100
commit791119d4af1066b20fa2b5bf8fc82d04d843d51d (patch)
tree94890756f4380fb2c1d8abd92af66128533a1535 /tools/format.js
parente7cfd90b0f72874aa1535a382df32dce28bd587a (diff)
build: rewrite tools/ scripts to deno (#8247)
This commit rewrites scripts in "tools/" directory to use Deno instead of Python. In return it allows to remove huge number of Python packages in "third_party/".
Diffstat (limited to 'tools/format.js')
-rwxr-xr-xtools/format.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/format.js b/tools/format.js
new file mode 100755
index 000000000..9786e6fe3
--- /dev/null
+++ b/tools/format.js
@@ -0,0 +1,63 @@
+#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { getPrebuiltToolPath, getSources, join, ROOT_PATH } from "./util.js";
+
+async function dprint() {
+ const execPath = getPrebuiltToolPath("dprint");
+ console.log("dprint");
+ const p = Deno.run({
+ cmd: [execPath, "fmt"],
+ });
+ const { success } = await p.status();
+ if (!success) {
+ throw new Error("dprint failed");
+ }
+ p.close();
+}
+
+async function rustfmt() {
+ const configFile = join(ROOT_PATH, ".rustfmt.toml");
+ const sourceFiles = await getSources(ROOT_PATH, ["*.rs"]);
+
+ if (!sourceFiles.length) {
+ return;
+ }
+
+ console.log(`rustfmt ${sourceFiles.length} file(s)`);
+ const p = Deno.run({
+ cmd: ["rustfmt", "--config-path=" + configFile, "--", ...sourceFiles],
+ });
+ const { success } = await p.status();
+ if (!success) {
+ throw new Error("rustfmt failed");
+ }
+ p.close();
+}
+
+async function main() {
+ await Deno.chdir(ROOT_PATH);
+ await dprint();
+ await rustfmt();
+
+ 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();