Skip to content

Commit 8343698

Browse files
committed
Use a script for formatting
1 parent 6a83f86 commit 8343698

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "./lib/index.d.ts",
77
"scripts": {
88
"build": "tsc --pretty",
9-
"format": "prettier $([[ \"$CI\" == true ]] && echo --list-different || echo --write) './**/*.{ts,tsx,js,json,css}'",
9+
"format": "node scripts/format.js",
1010
"test": "yarn build && jest --no-cache --verbose --coverage",
1111
"test:watch": "jest --watchAll",
1212
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"

scripts/format.js

Lines changed: 25 additions & 0 deletions
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)