Skip to content

Commit

Permalink
feat: support {String} patterns (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Oct 19, 2017
2 parents d49c989 + f456985 commit b6c2e66
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -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 |
Expand Down Expand Up @@ -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' },

Expand Down
4 changes: 3 additions & 1 deletion src/preProcessPattern.js
Expand Up @@ -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)) {
Expand Down
19 changes: 19 additions & 0 deletions tests/index.js
Expand Up @@ -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) => {
Expand Down

0 comments on commit b6c2e66

Please sign in to comment.