Skip to content

Instantly share code, notes, and snippets.

@benkroeger
Created October 2, 2017 12:34
Show Gist options
  • Save benkroeger/27f6f4d33a7698140310d0f407d24b1d to your computer and use it in GitHub Desktop.
Save benkroeger/27f6f4d33a7698140310d0f407d24b1d to your computer and use it in GitHub Desktop.
apply prettier-eslint formatting on files found via glob
'use strict';
// node core modules
const fs = require('fs');
const path = require('path');
// 3rd party modules
const glob = require('glob');
const format = require('prettier-eslint');
// internal modules
// this means you cann call invoke this via `node prettier-glob.js <my-custom-glob>`
const [, , globPattern = 'lib/**/*.js'] = process.argv;
glob(globPattern, {}, (globError, files) => {
if (globError) {
throw globError;
}
files
.map(item => path.resolve(item))
.forEach(filePath => fs.writeFileSync(filePath, format({ filePath })));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment