Created
October 2, 2017 12:34
-
-
Save benkroeger/27f6f4d33a7698140310d0f407d24b1d to your computer and use it in GitHub Desktop.
apply prettier-eslint formatting on files found via glob
This file contains hidden or 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
'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