Skip to content

Commit

Permalink
[FEATURE] AbstractAdapter: Add excludes option
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed May 21, 2019
1 parent 79a3637 commit dc44f95
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/adapters/AbstractAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class AbstractAdapter extends AbstractReaderWriter {
* @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}) {
constructor({virBasePath, excludes, project}) {
if (new.target === AbstractAdapter) {
throw new TypeError("Class 'AbstractAdapter' is abstract");
}
super();
this._virBasePath = virBasePath;
this._virBaseDir = virBasePath.slice(0, -1);
this._excludes = excludes;
this._project = project;
}

Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/library.l/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "library.l",
"version": "1.0.0",
"description": "Simple SAPUI5 based library - test for glob excludes",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
11 changes: 11 additions & 0 deletions test/fixtures/library.l/src/library/l/.library
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.l</name>
<vendor>SAP SE</vendor>
<copyright>${copyright}</copyright>
<version>${version}</version>

<documentation>Library L</documentation>

</library>
4 changes: 4 additions & 0 deletions test/fixtures/library.l/src/library/l/some.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*!
* ${copyright}
*/
console.log('HelloWorld');
Empty file.
13 changes: 13 additions & 0 deletions test/fixtures/library.l/ui5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
specVersion: "0.1"
type: library
metadata:
name: library.l
copyright: |-
UI development toolkit for HTML5 (OpenUI5)
* (c) Copyright 2009-xxx SAP SE or an SAP affiliate company.
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
builder:
excludes:
- /resources/**/some.js
- /test-resources/**
23 changes: 23 additions & 0 deletions test/lib/adapters/FileSystem_read.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,26 @@ test("glob virtual directory w/ virtual base path prefix and nodir: true", async
const resources = await readerWriter.byGlob("/app/*", {nodir: true});
t.deepEqual(resources.length, 0, "Found no resources");
});

test("glob library with static excludes", async (t) => {
const excludes = [
"/resources/**/some.js",
"/test-resources/**"
];
const srcReaderWriter = resourceFactory.createAdapter({
fsBasePath: "./test/fixtures/library.l/src",
virBasePath: "/resources/",
excludes
});

const testReaderWriter = resourceFactory.createAdapter({
fsBasePath: "./test/fixtures/library.l/test",
virBasePath: "/test-resources/",
excludes
});

const srcResources = await srcReaderWriter.byGlob("/**/*", {nodir: true});
const testResources = await testReaderWriter.byGlob("/**/*", {nodir: true});
t.deepEqual(srcResources.length, 1, "Found one src resource");
t.deepEqual(testResources.length, 0, "Found no test resources");
});
11 changes: 11 additions & 0 deletions test/lib/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ 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/**"])
.then((resources) => {
const expectedResources = [
"/test-resources/application.a/ui5.yaml"
];
matchGlobResult(t, resources, expectedResources);
});
});

test("glob only a specific filetype (yaml)", (t) => {
t.plan(2);
Expand Down

0 comments on commit dc44f95

Please sign in to comment.