From 056a60bdfce199d8ae49540c3f808d0443e2c384 Mon Sep 17 00:00:00 2001 From: Clayton Watts Date: Tue, 10 Oct 2017 11:07:09 -0600 Subject: [PATCH 1/2] feat: Support simple string patterns Fixes #150 --- src/preProcessPattern.js | 4 +++- tests/index.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/preProcessPattern.js b/src/preProcessPattern.js index 76c3404b..787fd91b 100644 --- a/src/preProcessPattern.js +++ b/src/preProcessPattern.js @@ -12,7 +12,9 @@ export default function preProcessPattern(globalRef, pattern) { const {info, debug, warning, context, fileDependencies, contextDependencies, compilation} = globalRef; - pattern = _.cloneDeep(pattern); + pattern = typeof pattern === 'string' ? { + from: pattern + } : _.cloneDeep(pattern); pattern.to = pattern.to || ''; pattern.context = pattern.context || context; if (!path.isAbsolute(pattern.context)) { diff --git a/tests/index.js b/tests/index.js index 22810fed..3c5b9ed0 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1053,6 +1053,25 @@ describe('apply function', () => { }); }); + describe('with simple string patterns', () => { + it('can move multiple files', (done) => { + runEmit({ + expectedAssetKeys: [ + 'binextension.bin', + 'file.txt', + 'noextension' + ], + patterns: [ + 'binextension.bin', + 'file.txt', + 'noextension' + ] + }) + .then(done) + .catch(done); + }); + }); + describe('options', () => { describe('ignore', () => { it('ignores files when from is a file', (done) => { From f456985217b93512de0aeb3877445c2e4ad33e52 Mon Sep 17 00:00:00 2001 From: Clayton Watts Date: Wed, 11 Oct 2017 09:46:55 -0600 Subject: [PATCH 2/2] Update README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index efb5ade4..f866b1a4 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ npm install --save-dev copy-webpack-plugin A pattern looks like: `{ from: 'source', to: 'dest' }` +Or, in the simple case of just a `from` with the default destination, you can use a string primitive instead of an object: +`'source'` + #### Pattern properties: | Name | Required | Default | Details | @@ -67,6 +70,9 @@ module.exports = { // {output}/file.txt { from: 'from/file.txt' }, + // equivalent + 'from/file.txt', + // {output}/to/file.txt { from: 'from/file.txt', to: 'to/file.txt' },