-
Notifications
You must be signed in to change notification settings - Fork 13
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 #2 from azz/prettier-config
feat: respect .prettierrc and .prettierignore
- Loading branch information
Showing
8 changed files
with
63 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import globby from "globby"; | ||
|
||
const expandGlob = glob => { | ||
return globby.sync(glob, { | ||
dot: true, | ||
}); | ||
}; | ||
|
||
export default expandGlob; |
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,15 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import ignore from "ignore"; | ||
|
||
const filterIgnored = filePaths => { | ||
const ignorePath = path.resolve(process.cwd(), ".prettierignore"); | ||
if (fs.existsSync(ignorePath)) { | ||
return ignore() | ||
.add(fs.readFileSync(ignorePath, "utf8")) | ||
.filter(filePaths); | ||
} | ||
return filePaths; | ||
}; | ||
|
||
export default filterIgnored; |
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 |
---|---|---|
@@ -1,19 +1,26 @@ | ||
import fs from "fs"; | ||
import minimist from "minimist"; | ||
|
||
import expandGlob from "./expand-glob"; | ||
import filterIgnored from "./filter-ignored"; | ||
import runTsLint from "./run-tslint"; | ||
import runPrettier from "./run-prettier"; | ||
|
||
const format = filepath => { | ||
runPrettier(filepath); | ||
runTsLint(filepath); | ||
const format = filePath => { | ||
runPrettier(filePath); | ||
runTsLint(filePath); | ||
}; | ||
|
||
const formatFiles = filePattern => { | ||
const files = filterIgnored(expandGlob(filePattern)); | ||
files.forEach(format); | ||
}; | ||
|
||
const cliOpts = {}; | ||
|
||
export const cli = argv => { | ||
const args = minimist(argv, cliOpts); | ||
args._.forEach(format); | ||
args._.forEach(formatFiles); | ||
}; | ||
|
||
export default format; |
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