Skip to content

Commit

Permalink
feat: Added non-wildcard glob support
Browse files Browse the repository at this point in the history
Resolves: #88
  • Loading branch information
kevlened authored and joshwiens committed Sep 29, 2017
1 parent 1b2c21a commit 405d1ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
"bluebird": "^2.10.2",
"fs-extra": "^0.26.4",
"glob": "^6.0.4",
"is-glob": "^3.1.0",
"loader-utils": "^0.2.15",
"lodash": "^4.3.0",
"minimatch": "^3.0.0",
"node-dir": "^0.1.10",
"loader-utils": "^0.2.15"
"node-dir": "^0.1.10"
},
"scripts": {
"lint": "eslint src/ tests/",
Expand Down
4 changes: 2 additions & 2 deletions src/preProcessPattern.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Promise from 'bluebird';
import path from 'path';
import _ from 'lodash';
import isGlob from 'is-glob';

const fs = Promise.promisifyAll(require('fs')); // eslint-disable-line import/no-commonjs

var isGlobLike = /\*/;
// https://www.debuggex.com/r/VH2yS2mvJOitiyr3
var isTemplateLike = /(\[ext\])|(\[name\])|(\[path\])|(\[folder\])|(\[emoji(:\d+)?\])|(\[(\w+:)?hash(:\w+)?(:\d+)?\])|(\[\d+\])/;

Expand Down Expand Up @@ -57,7 +57,7 @@ export default function preProcessPattern(globalRef, pattern) {
.statAsync(pattern.absoluteFrom)
.catch(() => {
// If from doesn't appear to be a glob, then log a warning
if (isGlobLike.test(pattern.from)) {
if (isGlob(pattern.from)) {
pattern.fromType = 'glob';
} else {
const msg = `unable to locate '${pattern.from}' at '${pattern.absoluteFrom}'`;
Expand Down
16 changes: 16 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ describe('apply function', () => {
.catch(done);
});

it('can use a bracketed glob to move a file to the root directory', (done) => {
runEmit({
expectedAssetKeys: [
'directory/directoryfile.txt',
'directory/nested/nestedfile.txt',
'file.txt',
'noextension'
],
patterns: [{
from: '{file.txt,noextension,directory/**/*}'
}]
})
.then(done)
.catch(done);
});

it('can use a glob object to move a file to the root directory', (done) => {
runEmit({
expectedAssetKeys: [
Expand Down

0 comments on commit 405d1ec

Please sign in to comment.