Skip to content

Commit

Permalink
[FIX] Enable buildThemes for libraries without .library
Browse files Browse the repository at this point in the history
Fixes that libraries using a "library.js" file but no ".library"
file can also build theming files.

Fixes: SAP/ui5-tooling#582
  • Loading branch information
larskissel committed Dec 6, 2021
1 parent e92ec97 commit 7b941a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
8 changes: 6 additions & 2 deletions lib/tasks/buildThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ module.exports = async function({
*/
let availableLibraries;
if (pAvailableLibraries) {
availableLibraries = (await pAvailableLibraries).map((resource) => {
return resource.getPath().replace(/[^/]*\.library/i, "");
availableLibraries = [];
(await pAvailableLibraries).forEach((resource) => {
const library = path.dirname(resource.getPath());
if (!availableLibraries.includes(library)) {
availableLibraries.push(library);
}
});
}
let availableThemes;
Expand Down
2 changes: 1 addition & 1 deletion lib/types/library/LibraryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class LibraryBuilder extends AbstractBuilder {
dependencies: resourceCollections.dependencies,
options: {
projectName: project.metadata.name,
librariesPattern: !taskUtil.isRootProject() ? "/resources/**/*.library" : undefined,
librariesPattern: !taskUtil.isRootProject() ? "/resources/**/(*.library|library.js)" : undefined,
themesPattern: !taskUtil.isRootProject() ? "/resources/sap/ui/core/themes/*" : undefined,
inputPattern
}
Expand Down
2 changes: 1 addition & 1 deletion lib/types/themeLibrary/ThemeLibraryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ThemeLibraryBuilder extends AbstractBuilder {
dependencies: resourceCollections.dependencies,
options: {
projectName: project.metadata.name,
librariesPattern: !taskUtil.isRootProject() ? "/resources/**/*.library" : undefined,
librariesPattern: !taskUtil.isRootProject() ? "/resources/**/(*.library|library.js)" : undefined,
themesPattern: !taskUtil.isRootProject() ? "/resources/sap/ui/core/themes/*" : undefined,
inputPattern: "/resources/**/themes/*/library.source.less"
}
Expand Down
28 changes: 18 additions & 10 deletions test/lib/tasks/buildThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,11 @@ test.serial("buildThemes (filtering libraries)", async (t) => {
"sap/ui/lib1/.library": {
getPath: sinon.stub().returns("/resources/sap/ui/lib1/.library")
},
"sap/ui/lib3/.library": {
getPath: sinon.stub().returns("/resources/sap/ui/lib3/.library")
"sap/ui/lib1/library.js": {
getPath: sinon.stub().returns("/resources/sap/ui/lib1/library.js")
},
"sap/ui/lib3/library.js": {
getPath: sinon.stub().returns("/resources/sap/ui/lib3/library.js")
}
};

Expand All @@ -252,9 +255,10 @@ test.serial("buildThemes (filtering libraries)", async (t) => {
]);

t.context.comboByGlob
.withArgs("/resources/**/*.library").resolves([
.withArgs("/resources/**/(*.library|library.js)").resolves([
dotLibraryResources["sap/ui/lib1/.library"],
dotLibraryResources["sap/ui/lib3/.library"]
dotLibraryResources["sap/ui/lib1/library.js"],
dotLibraryResources["sap/ui/lib3/library.js"]
]);

t.context.themeBuilderStub.returns([{}]);
Expand All @@ -264,7 +268,7 @@ test.serial("buildThemes (filtering libraries)", async (t) => {
options: {
projectName: "sap.ui.test.lib1",
inputPattern: "/resources/**/themes/*/library.source.less",
librariesPattern: "/resources/**/*.library"
librariesPattern: "/resources/**/(*.library|library.js)"
}
});

Expand Down Expand Up @@ -403,8 +407,11 @@ test.serial("buildThemes (filtering libraries + themes)", async (t) => {
"sap/ui/lib1/.library": {
getPath: sinon.stub().returns("/resources/sap/ui/lib1/.library")
},
"sap/ui/lib3/.library": {
getPath: sinon.stub().returns("/resources/sap/ui/lib3/.library")
"sap/ui/lib1/library.js": {
getPath: sinon.stub().returns("/resources/sap/ui/lib1/library.js")
},
"sap/ui/lib3/library.js": {
getPath: sinon.stub().returns("/resources/sap/ui/lib3/library.js")
}
};

Expand Down Expand Up @@ -443,9 +450,10 @@ test.serial("buildThemes (filtering libraries + themes)", async (t) => {
]);

t.context.comboByGlob
.withArgs("/resources/**/*.library").resolves([
.withArgs("/resources/**/(*.library|library.js)").resolves([
dotLibraryResources["sap/ui/lib1/.library"],
dotLibraryResources["sap/ui/lib3/.library"]
dotLibraryResources["sap/ui/lib1/library.js"],
dotLibraryResources["sap/ui/lib3/library.js"]
])
.withArgs("/resources/sap/ui/core/themes/*", {nodir: false}).resolves([
baseThemes["sap/ui/core/themes/theme1/"],
Expand All @@ -459,7 +467,7 @@ test.serial("buildThemes (filtering libraries + themes)", async (t) => {
options: {
projectName: "sap.ui.test.lib1",
inputPattern: "/resources/**/themes/*/library.source.less",
librariesPattern: "/resources/**/*.library",
librariesPattern: "/resources/**/(*.library|library.js)",
themesPattern: "/resources/sap/ui/core/themes/*"
}
});
Expand Down

0 comments on commit 7b941a7

Please sign in to comment.