Skip to content

Commit

Permalink
Use std/prettier in deno //tools/format.ts (denoland#1708)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored and ry committed Feb 9, 2019
1 parent 99ce807 commit 4c869dc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

24 changes: 12 additions & 12 deletions tools/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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")
]
}
)
);

Expand Down
33 changes: 32 additions & 1 deletion tools/util.ts
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down Expand Up @@ -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;
}

0 comments on commit 4c869dc

Please sign in to comment.