diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2019-02-09 11:38:59 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-08 21:38:59 -0500 |
commit | 4c869dc8851527756b774e3ea202529aa2b3ae1e (patch) | |
tree | aeac462bf81de1392820660cfb75f1b36fb77e2d /tools/util.ts | |
parent | 99ce807a121efdbbee784409094c1596299d90de (diff) |
Use std/prettier in deno //tools/format.ts (#1708)
Diffstat (limited to 'tools/util.ts')
-rw-r--r-- | tools/util.ts | 33 |
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; +} |