1 | "use strict";
|
2 | const execa = require("execa");
|
3 |
|
4 | const NO_ERROR = "All files using prettier code style.";
|
5 | const GENERAL_ERROR = "Error when running prettier:";
|
6 | const STYLE_ERROR = "Forgot to run prettier? There are files without correct code style:";
|
7 | const UNEXPECTED_ERROR = "Unexpected error:";
|
8 |
|
9 | module.exports = args => {
|
10 | args.push("-l");
|
11 |
|
12 | return execa("prettier", args)
|
13 | .then(() => {
|
14 | console.log(NO_ERROR);
|
15 | return 0;
|
16 | })
|
17 | .catch(error => {
|
18 | if (error.stderr) {
|
19 | console.error(GENERAL_ERROR);
|
20 | console.error(error.stderr);
|
21 | return 4;
|
22 | } else if (error.stdout) {
|
23 | console.log(STYLE_ERROR);
|
24 | console.log(error.stdout);
|
25 | return 3;
|
26 | } else {
|
27 | console.error(UNEXPECTED_ERROR);
|
28 | console.error(error);
|
29 | return 1;
|
30 | }
|
31 | });
|
32 | };
|