From c0895fff4c6849d1543a0b34d3611d6819013d9c Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Tue, 27 Aug 2019 22:27:21 +0200 Subject: [PATCH] Allow multiple patterns specified --- README.md | 5 ++--- src/cli.js | 6 +++--- src/index.js | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0e9e662..983bb42 100644 --- a/README.md +++ b/README.md @@ -133,10 +133,9 @@ It also exposes one additional method that works similarly to its CLI: - **cwd** - path where to execute prettier-standard - **config** - object configuring execution - - **pattern** - pattern to use for formatting files (string) + - **patterns** - patterns to use for formatting files (array of strings) - **check** - whether to check instead of format files (boolean, default: false) - - **onProcess** - callback that is called for each processed file matching pattern: - { file, formatted, check, runtime } + - **onProcess** - callback that is called for each processed file matching pattern: { file, formatted, check, runtime } ## LICENSE diff --git a/src/cli.js b/src/cli.js index 9843453..1672520 100755 --- a/src/cli.js +++ b/src/cli.js @@ -40,8 +40,8 @@ async function main () { } }) - if (flags._ && flags._.length > 0 && !flags.pattern) { - flags.pattern = flags._[0] + if (flags._ && flags._.length > 0) { + flags.patterns = flags._ } const stdin = await getStdin() @@ -81,7 +81,7 @@ async function main () { } const result = run(process.cwd(), { - pattern: flags.pattern, + patterns: flags.patterns, check: flags.check || false, options, onProcessed: ({ file, formatted, check, runtime }) => { diff --git a/src/index.js b/src/index.js index 20c041e..67682b0 100644 --- a/src/index.js +++ b/src/index.js @@ -23,13 +23,12 @@ function formatWithCursor (source, options) { function run (cwd, config) { const onProcessed = config.onProcessed || function () {} - const patterns = [ - config.pattern, + const patterns = config.patterns.concat([ '!**/node_modules/**', '!./node_modules/**', '!**/.{git,svn,hg}/**', '!./.{git,svn,hg}/**' - ] + ]) let filePaths try {