summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2019-02-09 11:38:59 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-02-08 21:38:59 -0500
commit4c869dc8851527756b774e3ea202529aa2b3ae1e (patch)
treeaeac462bf81de1392820660cfb75f1b36fb77e2d
parent99ce807a121efdbbee784409094c1596299d90de (diff)
Use std/prettier in deno //tools/format.ts (#1708)
-rw-r--r--.prettierignore3
-rwxr-xr-xtools/format.ts24
-rw-r--r--tools/util.ts33
3 files changed, 44 insertions, 16 deletions
diff --git a/.prettierignore b/.prettierignore
deleted file mode 100644
index 9d83dd750..000000000
--- a/.prettierignore
+++ /dev/null
@@ -1,3 +0,0 @@
-js/flatbuffers.js
-tests/error_syntax.js
-tests/badly_formatted.js
diff --git a/tools/format.ts b/tools/format.ts
index ebf9285fe..93cfd6ccb 100755
--- a/tools/format.ts
+++ b/tools/format.ts
@@ -2,16 +2,10 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as deno from "deno";
import { join } from "../js/deps/https/deno.land/x/std/fs/path.ts";
-import { findFiles } from "./util.ts";
+import { findFiles, lookupDenoPath } from "./util.ts";
const clangFormat = join("third_party", "depot_tools", "clang-format");
const gn = join("third_party", "depot_tools", "gn");
-const prettier = join(
- "third_party",
- "node_modules",
- "prettier",
- "bin-prettier.js"
-);
const yapf = join("third_party", "python_packages", "bin", "yapf");
const rustfmt = join("third_party", "rustfmt", deno.platform.os, "rustfmt");
const rustfmtConfig = join("tools", "rustfmt.toml");
@@ -54,16 +48,22 @@ const run = (...args: string[]) => {
console.log("prettier");
await run(
- "node",
- prettier,
- "--write",
- "--loglevel=error",
+ lookupDenoPath(),
+ "--allow-write",
+ "js/deps/https/deno.land/x/std/prettier/main.ts",
"rollup.config.js",
...findFiles(["."], [".json", ".md"], { depth: 1 }),
...findFiles(
[".github", "js", "tests", "tools", "website"],
[".js", ".json", ".ts", ".md"],
- { skip: [join("tools", "clang"), join("js", "deps")] }
+ {
+ skip: [
+ join("tools", "clang"),
+ join("js", "deps"),
+ join("tests", "badly_formatted.js"),
+ join("tests", "error_syntax.js")
+ ]
+ }
)
);
diff --git a/tools/util.ts b/tools/util.ts
index 5ff7da344..c055959fe 100644
--- a/tools/util.ts
+++ b/tools/util.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { lstatSync, readDirSync } from "deno";
+import { platform, lstatSync, readDirSync } from "deno";
+import { join } from "../js/deps/https/deno.land/x/std/fs/path/mod.ts";
export interface FindOptions {
skip?: string[];
@@ -38,3 +39,33 @@ function findFilesWalk(paths: string[], depth: number) {
return [].concat(...foundPaths);
}
+
+export const executableSuffix = platform.os === "win" ? ".exe" : "";
+
+/** Returns true if the path exists. */
+export function existsSync(path: string): boolean {
+ try {
+ lstatSync(path);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Looks up the available deno path with the priority
+ * of release -> debug -> global
+ */
+export function lookupDenoPath(): string {
+ const denoExe = "deno" + executableSuffix;
+ const releaseExe = join("target", "release", denoExe);
+ const debugExe = join("target", "debug", denoExe);
+
+ if (existsSync(releaseExe)) {
+ return releaseExe;
+ } else if (existsSync(debugExe)) {
+ return debugExe;
+ }
+
+ return denoExe;
+}