This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from wincent/glh/pretty
Prettify codebase
- Loading branch information
Showing
12 changed files
with
1,247 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* Copyright (c) Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const { spawnSync } = require('child_process'); | ||
const { join } = require('path'); | ||
|
||
const INVERSE = '\x1b[7m'; | ||
const RESET = '\x1b[0m'; | ||
const YELLOW = '\x1b[33m'; | ||
|
||
const options = ['--single-quote', '--trailing-comma=all']; | ||
const glob = '{resources,src}/**/*.js'; | ||
const root = join(__dirname, '..'); | ||
const executable = join(root, 'node_modules', '.bin', 'prettier'); | ||
|
||
const check = process.argv.indexOf('--check') !== -1; | ||
const mode = check ? '--list-different' : '--write'; | ||
process.chdir(root); | ||
|
||
const { stdout, stderr, status, error } = spawnSync(executable, [ | ||
...options, | ||
mode, | ||
glob, | ||
]); | ||
const out = stdout.toString().trim(); | ||
const err = stdout.toString().trim(); | ||
|
||
function print(message) { | ||
if (message) { | ||
process.stdout.write(message + '\n'); | ||
} | ||
} | ||
|
||
if (status) { | ||
print(out); | ||
print(err); | ||
if (check) { | ||
print(`\n${YELLOW}The files listed above are not correctly formatted.`); | ||
print(`Try: ${INVERSE} npm run pretty ${RESET}`); | ||
} | ||
} | ||
if (error) { | ||
print('error', error); | ||
} | ||
process.exit(status != null ? status : 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.