Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support {String} patterns #155

Merged
merged 2 commits into from
Oct 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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' },

4 changes: 3 additions & 1 deletion src/preProcessPattern.js
Original file line number Diff line number Diff line change
@@ -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)) {
19 changes: 19 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -1053,6 +1053,25 @@ describe('apply function', () => {
});
});

describe('with simple string patterns', () => {
it('can move multiple files', (done) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording could be better if anyone has suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describe('Patterns - {String}', () => { 
   it('Multiple Files', () => {})
})

But 🐦 , all good

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) => {