mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
Use std/prettier in deno //tools/format.ts (#1708)
This commit is contained in:
parent
99ce807a12
commit
4c869dc885
3 changed files with 44 additions and 16 deletions
|
@ -1,3 +0,0 @@
|
||||||
js/flatbuffers.js
|
|
||||||
tests/error_syntax.js
|
|
||||||
tests/badly_formatted.js
|
|
|
@ -2,16 +2,10 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
import * as deno from "deno";
|
import * as deno from "deno";
|
||||||
import { join } from "../js/deps/https/deno.land/x/std/fs/path.ts";
|
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 clangFormat = join("third_party", "depot_tools", "clang-format");
|
||||||
const gn = join("third_party", "depot_tools", "gn");
|
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 yapf = join("third_party", "python_packages", "bin", "yapf");
|
||||||
const rustfmt = join("third_party", "rustfmt", deno.platform.os, "rustfmt");
|
const rustfmt = join("third_party", "rustfmt", deno.platform.os, "rustfmt");
|
||||||
const rustfmtConfig = join("tools", "rustfmt.toml");
|
const rustfmtConfig = join("tools", "rustfmt.toml");
|
||||||
|
@ -54,16 +48,22 @@ const run = (...args: string[]) => {
|
||||||
|
|
||||||
console.log("prettier");
|
console.log("prettier");
|
||||||
await run(
|
await run(
|
||||||
"node",
|
lookupDenoPath(),
|
||||||
prettier,
|
"--allow-write",
|
||||||
"--write",
|
"js/deps/https/deno.land/x/std/prettier/main.ts",
|
||||||
"--loglevel=error",
|
|
||||||
"rollup.config.js",
|
"rollup.config.js",
|
||||||
...findFiles(["."], [".json", ".md"], { depth: 1 }),
|
...findFiles(["."], [".json", ".md"], { depth: 1 }),
|
||||||
...findFiles(
|
...findFiles(
|
||||||
[".github", "js", "tests", "tools", "website"],
|
[".github", "js", "tests", "tools", "website"],
|
||||||
[".js", ".json", ".ts", ".md"],
|
[".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")
|
||||||
|
]
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// 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 {
|
export interface FindOptions {
|
||||||
skip?: string[];
|
skip?: string[];
|
||||||
|
@ -38,3 +39,33 @@ function findFilesWalk(paths: string[], depth: number) {
|
||||||
|
|
||||||
return [].concat(...foundPaths);
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue