summaryrefslogtreecommitdiff
path: root/tools/util.ts
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 /tools/util.ts
parent99ce807a121efdbbee784409094c1596299d90de (diff)
Use std/prettier in deno //tools/format.ts (#1708)
Diffstat (limited to 'tools/util.ts')
-rw-r--r--tools/util.ts33
1 files changed, 32 insertions, 1 deletions
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;
+}