Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Add a Prettier task (#88)
Browse files Browse the repository at this point in the history
* Add a Prettier task

* Add docs for setting up Prettier in an app

* Update Prettier readme

* Update Prettier docs

* Don't write files with Prettier by default

* Upgrade Prettier

* Bump minor version 7.3.0
  • Loading branch information
iamlacroix committed Jun 13, 2017
1 parent 08b42ce commit 3b2bbf4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
File renamed without changes.
11 changes: 11 additions & 0 deletions docs/PRETTIER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Prettier

## Adding Prettier to an App

Prettier is available in @trunkclub/build version 7.3 and above.

### Usage

```bash
yarn tcweb-build prettier -- --write "{src,spec}/**/*.{js,jsx,es6}"
```
1 change: 1 addition & 0 deletions packages/react-scripts/bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function run (s) {
case 'test':
case 'build-module':
case 'lint':
case 'prettier':
case 'publish':
case 'deploy':
var result = spawn.sync(
Expand Down
10 changes: 8 additions & 2 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trunkclub/build",
"version": "7.2.0",
"version": "7.3.0",
"upstream-version": "0.9.5",
"description": "Configuration and scripts for Create React App. Fork maintained by Trunk Club",
"repository": "trunkclub/create-react-app",
Expand Down Expand Up @@ -71,6 +71,7 @@
"object-assign": "4.1.1",
"path-exists": "2.1.0",
"postcss-loader": "1.2.2",
"prettier": "^1.4.4",
"progress-bar-webpack-plugin": "1.9.0",
"promise": "7.1.1",
"recursive-readdir": "2.1.0",
Expand All @@ -89,11 +90,16 @@
"devDependencies": {
"babel-runtime": "^6.11.6",
"bundle-deps": "1.0.0",
"flow-runtime": "^0.12.0",
"husky": "^0.13.3",
"lint-staged": "^3.4.1",
"publish": "^0.6.0",
"react": "^15.3.0",
"react-dom": "^15.3.0"
},
"peerDependencies": {
"husky": "^0.13.3",
"lint-staged": "^3.4.1"
},
"optionalDependencies": {
"fsevents": "1.0.17"
}
Expand Down
39 changes: 39 additions & 0 deletions packages/react-scripts/scripts/prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

var path = require('path');
var spawn = require('cross-spawn');

// First two args will always be:
// - node
// - path/to/prettier.js (this file)
var argsIndex = process.argv[2] === '--' ? 3 : 2;
var args = process.argv.slice(argsIndex);

var result = spawn.sync(
path.resolve(__dirname, '../node_modules/.bin/prettier'),
[
'--single-quote',
'--no-semi',
'--trailing-comma', 'all',
].concat(args),
{ stdio: 'inherit' }
);

if (result.signal) {
if (result.signal === 'SIGKILL') {
console.log(
'The prettier task failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if (result.signal === 'SIGTERM') {
console.log(
'The prettier task failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
process.exit(1);
}

process.exit(result.status);

0 comments on commit 3b2bbf4

Please sign in to comment.