2017-05-18 21:21:33 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2017-05-25 21:45:57 +03:00
|
|
|
const { config } = require('../package.json');
|
|
|
|
const forceArray = require('force-array');
|
2017-05-18 21:21:33 +03:00
|
|
|
const execa = require('execa');
|
|
|
|
const globby = require('globby');
|
|
|
|
const main = require('apr-main');
|
|
|
|
const argv = require('yargs').argv;
|
|
|
|
const path = require('path');
|
|
|
|
|
2017-05-25 21:45:57 +03:00
|
|
|
const optOut = forceArray(config['fmt-opt-out']);
|
|
|
|
|
|
|
|
const filter = (files = []) =>
|
|
|
|
files
|
|
|
|
.filter(file => !/node_modules/.test(file))
|
|
|
|
.filter(file => !optOut.some(pkg => file.indexOf(`packages/${pkg}`) === 0));
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
const run = async (files = []) => {
|
2017-05-25 21:45:57 +03:00
|
|
|
const cp = execa(
|
|
|
|
'prettier',
|
|
|
|
['--write', '--single-quote'].concat(filter(files))
|
|
|
|
);
|
2017-05-18 21:21:33 +03:00
|
|
|
|
|
|
|
cp.stdout.pipe(process.stdout);
|
|
|
|
cp.stderr.pipe(process.stderr);
|
|
|
|
|
|
|
|
return cp;
|
|
|
|
};
|
|
|
|
|
|
|
|
const all = async () => {
|
|
|
|
const files = await globby('{scripts,packages}/**/*.js', {
|
|
|
|
cwd: path.join(__dirname, '..')
|
|
|
|
});
|
|
|
|
|
2017-05-25 21:45:57 +03:00
|
|
|
return run(files);
|
2017-05-18 21:21:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
main(argv._.length ? run(argv._) : all());
|