2018-12-18 18:56:12 -05:00
|
|
|
#!/usr/bin/env deno --allow-run
|
2019-01-02 09:56:17 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-12-18 18:56:12 -05:00
|
|
|
|
2018-12-19 13:01:26 -05:00
|
|
|
import { readAll, exit, run } from "deno";
|
|
|
|
|
|
|
|
async function checkVersion() {
|
|
|
|
const prettierVersion = run({
|
|
|
|
args: ["bash", "-c", "prettier --version"],
|
|
|
|
stdout: "piped"
|
|
|
|
});
|
|
|
|
const b = await readAll(prettierVersion.stdout);
|
|
|
|
const s = await prettierVersion.status();
|
|
|
|
if (s.code != 0) {
|
|
|
|
console.log("error calling prettier --version error");
|
|
|
|
exit(s.code);
|
|
|
|
}
|
|
|
|
const version = new TextDecoder().decode(b).trim();
|
|
|
|
const requiredVersion = "1.15";
|
|
|
|
if (!version.startsWith(requiredVersion)) {
|
|
|
|
console.log(`Required prettier version: ${requiredVersion}`);
|
|
|
|
console.log(`Installed prettier version: ${version}`);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2018-12-18 18:56:12 -05:00
|
|
|
|
|
|
|
async function main() {
|
2018-12-19 13:01:26 -05:00
|
|
|
await checkVersion();
|
|
|
|
|
2018-12-18 18:56:12 -05:00
|
|
|
const prettier = run({
|
2019-01-06 14:19:15 -05:00
|
|
|
args: [
|
|
|
|
"bash",
|
|
|
|
"-c",
|
2019-01-15 11:09:55 -05:00
|
|
|
"prettier --write *.ts */*.ts */**/*.ts *.md */*.md */**/*.md"
|
2019-01-06 14:19:15 -05:00
|
|
|
]
|
2018-12-18 18:56:12 -05:00
|
|
|
});
|
|
|
|
const s = await prettier.status();
|
|
|
|
exit(s.code);
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|