Skip to content

Commit 4f264bd

Browse files
committed
Use a script for formatting
1 parent 8381f7c commit 4f264bd

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"types": "./lib/index.d.ts",
1010
"scripts": {
1111
"build": "tsc --pretty",
12-
"format": "prettier $([ \"$CI\" == true ] && echo --list-different || echo --write) './**/*.{ts,tsx,js,json,css}'",
12+
"format": "node scripts/format.js",
1313
"test": "jest --no-cache --verbose --coverage",
1414
"test:watch": "jest --watch"
1515
},
@@ -34,4 +34,4 @@
3434
"mapCoverage": true,
3535
"testEnvironment": "node"
3636
}
37-
}
37+
}

Diff for: scripts/format.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
// Makes the script crash on unhandled rejections instead of silently
4+
// ignoring them. In the future, promise rejections that are not handled will
5+
// terminate the Node.js process with a non-zero exit code.
6+
process.on('unhandledRejection', err => {
7+
throw err;
8+
});
9+
10+
const { exec } = require('child_process');
11+
12+
const command = [
13+
'$(npm bin)/prettier',
14+
process.env.CI ? '--list-different' : '--write',
15+
'"./**/*.{ts,tsx,js,json,css}"',
16+
];
17+
18+
exec(command.join(' '), (error, stdout) => {
19+
if (error) {
20+
console.error('Found formatting issues in:\n');
21+
console.error(stdout);
22+
console.error('Looks like someone forgot to run `yarn format` before pushing 😱');
23+
process.exit(1);
24+
}
25+
});

0 commit comments

Comments
 (0)