Skip to content

Commit

Permalink
Add exclude array to appropriate constructors. Fix test for pattern e…
Browse files Browse the repository at this point in the history
…xcludes.
  • Loading branch information
romaniam committed May 21, 2019
1 parent dc44f95 commit 05911c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
14 changes: 13 additions & 1 deletion lib/adapters/AbstractAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ class AbstractAdapter extends AbstractReaderWriter {
super();
this._virBasePath = virBasePath;
this._virBaseDir = virBasePath.slice(0, -1);
this._excludes = excludes;
this._excludes = Array.isArray(excludes) ? excludes.map(this._negateGlob) : [];
this._project = project;
}

_negateGlob(glob) {
return /^!/.test(glob) ? glob : "!" + glob;
}

/**
* Locates resources by glob.
*
Expand All @@ -44,14 +48,22 @@ class AbstractAdapter extends AbstractReaderWriter {
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/
_byGlob(virPattern, options = {nodir: true}, trace) {
// TODO: Should be passed as parameter
let excludes = this._excludes || [];

if (!(virPattern instanceof Array)) {
virPattern = [virPattern];
}

virPattern = Array.prototype.concat.apply(virPattern, excludes);

return Promise.all(virPattern.map(this._normalizePattern, this)).then((patterns) => {

if (patterns.length === 0) {
return [];
}
patterns = Array.prototype.concat.apply([], patterns);

if (!options.nodir) {
for (let i = patterns.length - 1; i >= 0; i--) {
const idx = this._virBaseDir.indexOf(patterns[i]);
Expand Down
5 changes: 3 additions & 2 deletions lib/adapters/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class FileSystem extends AbstractAdapter {
* @param {Object} parameters Parameters
* @param {string} parameters.virBasePath Virtual base path
* @param {string} parameters.fsBasePath (Physical) File system path
* @param {string[]} [parameters.excludes] List of GLOB patterns to exclude
*/
constructor({virBasePath, project, fsBasePath}) {
super({virBasePath, project});
constructor({virBasePath, project, fsBasePath, excludes}) {
super({virBasePath, project, excludes});
this._fsBasePath = fsBasePath;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/adapters/Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class Memory extends AbstractAdapter {
* @public
* @param {Object} parameters Parameters
* @param {string} parameters.virBasePath Virtual base path
* @param {string[]} [parameters.excludes] List of GLOB patterns to exclude
*/
constructor({virBasePath, project}) {
super({virBasePath, project});
constructor({virBasePath, project, excludes}) {
super({virBasePath, project, excludes});
this._virFiles = {}; // map full of files
this._virDirs = {}; // map full of directories
}
Expand Down
6 changes: 3 additions & 3 deletions lib/resourceFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ const resourceFactory = {
* @param {string} [parameters.fsBasePath] File system base path
* @returns {module:@ui5/fs.adapters.FileSystem|module:@ui5/fs.adapters.Memory} File System- or Virtual Adapter
*/
createAdapter({fsBasePath, virBasePath, project}) {
createAdapter({fsBasePath, virBasePath, project, excludes}) {
if (fsBasePath) {
return new FsAdapter({fsBasePath, virBasePath, project});
return new FsAdapter({fsBasePath, virBasePath, project, excludes});
} else {
return new MemAdapter({virBasePath, project});
return new MemAdapter({virBasePath, project, excludes});
}
},

Expand Down
2 changes: 1 addition & 1 deletion test/lib/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ test("glob with multiple patterns", (t) => {
test("glob with multiple patterns with exclude", (t) => {
t.plan(2);
return t.context.readerWriter.filesystem.byGlob([
"/**/*.yaml", "/test-resources/**/i18n_de.properties", "!/resources/application.b/**"])
"/**/*.yaml", "/test-resources/**/i18n_de.properties", "!/test-resources/application.b/**"])
.then((resources) => {
const expectedResources = [
"/test-resources/application.a/ui5.yaml"
Expand Down

0 comments on commit 05911c3

Please sign in to comment.