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

[FEATURE] buildThemes: Add "compress" option #363

Merged
merged 2 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions lib/tasks/buildThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const fsInterface = require("@ui5/fs").fsInterface;
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
* @param {Object} parameters.options Options
* @param {string} parameters.options.pattern Pattern to locate the files to be processed
* @param {string} parameters.options.projectName Project name
* @param {string} parameters.options.inputPattern Search pattern for *.less files to be built
* @param {string} [parameters.options.librariesPattern] Search pattern for .library files
* @param {boolean} [parameters.options.compress=true]
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
module.exports = function({workspace, dependencies, options}) {
Expand All @@ -27,6 +30,8 @@ module.exports = function({workspace, dependencies, options}) {
promises.push(combo.byGlob(options.librariesPattern));
}

const compress = options.compress === undefined ? true : options.compress;

return Promise.all(promises).then(([allResources, availableLibraries]) => {
if (!availableLibraries || availableLibraries.length === 0) {
// Try to build all themes
Expand Down Expand Up @@ -55,7 +60,7 @@ module.exports = function({workspace, dependencies, options}) {
resources,
fs: fsInterface(combo),
options: {
compress: true
compress
}
});
}).then((processedResources) => {
Expand Down
157 changes: 157 additions & 0 deletions test/lib/tasks/buildThemes.integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
const test = require("ava");

const ui5Builder = require("../../../");
const tasks = ui5Builder.builder.tasks;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const DuplexCollection = ui5Fs.DuplexCollection;

test("integration: simple", (t) => {
const reader = resourceFactory.createAdapter({
virBasePath: "/"
});
const writer = resourceFactory.createAdapter({
virBasePath: "/"
});
const duplexCollection = new DuplexCollection({reader, writer});
const dependencies = resourceFactory.createAdapter({
virBasePath: "/"
});

const content =
`@deepSea: #123456;
.fluffyHammer {
color: @deepSea;
padding: 1px 2px 3px 4px;
}`;
const cssExpected =
`.fluffyHammer{color:#123456;padding:1px 2px 3px 4px}
/* Inline theming parameters */
#sap-ui-theme-super\\.duper\\.looper{background-image:url('data:text/plain;utf-8,%7B%22deepSea%22%3A%22%23123456%22%7D')}
`;
const cssRtlExpected =
`.fluffyHammer{color:#123456;padding:1px 4px 3px 2px}
/* Inline theming parameters */
#sap-ui-theme-super\\.duper\\.looper{background-image:url('data:text/plain;utf-8,%7B%22deepSea%22%3A%22%23123456%22%7D')}
`;
const parametersExpected =
`{"deepSea":"#123456"}`;
const lessPath = "/resources/super/duper/looper/themes/brightlight/library.source.less";
const cssPath = "/resources/super/duper/looper/themes/brightlight/library.css";
const cssRtlPath = "/resources/super/duper/looper/themes/brightlight/library-RTL.css";
const parametersPath = "/resources/super/duper/looper/themes/brightlight/library-parameters.json";

const resource = resourceFactory.createResource({
path: lessPath,
string: content
});
return reader.write(resource).then(() => {
return tasks.buildThemes({
workspace: duplexCollection,
dependencies: dependencies,
options: {
inputPattern: "/resources/**/themes/**/library.source.less"
}
}).then(() => {
return Promise.all([
writer.byPath(cssPath),
writer.byPath(cssRtlPath),
writer.byPath(parametersPath)
]);
}).then(([cssResource, cssRtlResource, parametersResource]) => {
t.truthy(cssResource, "CSS resource has been created");
t.truthy(cssRtlResource, "CSS right-to-left resource has been created");
t.truthy(parametersResource, "Parameters JSON resource has been created");

return Promise.all([
cssResource.getBuffer(),
cssRtlResource.getBuffer(),
parametersResource.getBuffer()
]);
}).then(([cssBuffer, cssRtlBuffer, parametersBuffer]) => {
t.deepEqual(cssBuffer.toString(), cssExpected, "Correct CSS content");
t.deepEqual(cssRtlBuffer.toString(), cssRtlExpected, "Correct CSS right-to-left content");
t.deepEqual(parametersBuffer.toString(), parametersExpected, "Correct parameters JSON content");
});
});
});

test("integration: imports", (t) => {
const reader = resourceFactory.createAdapter({
virBasePath: "/"
});
const writer = resourceFactory.createAdapter({
virBasePath: "/"
});
const duplexCollection = new DuplexCollection({reader, writer});
const dependencies = resourceFactory.createAdapter({
virBasePath: "/"
});
const lessContent =
`@import "variables.less";
.fluffyHammer {
color: @deepSea;
padding: 1px 2px 3px 4px;
}`;
const lessVariablesContent =
"@deepSea: #123456;";
const cssExpected =
`.fluffyHammer{color:#123456;padding:1px 2px 3px 4px}
/* Inline theming parameters */
#sap-ui-theme-super\\.duper\\.looper{background-image:url('data:text/plain;utf-8,%7B%22deepSea%22%3A%22%23123456%22%7D')}
`;
const cssRtlExpected =
`.fluffyHammer{color:#123456;padding:1px 4px 3px 2px}
/* Inline theming parameters */
#sap-ui-theme-super\\.duper\\.looper{background-image:url('data:text/plain;utf-8,%7B%22deepSea%22%3A%22%23123456%22%7D')}
`;
const parametersExpected =
`{"deepSea":"#123456"}`;
const lessPath = "/resources/super/duper/looper/themes/brightlight/library.source.less";
const lessVariablesPath = "/resources/super/duper/looper/themes/brightlight/variables.less";
const cssPath = "/resources/super/duper/looper/themes/brightlight/library.css";
const cssRtlPath = "/resources/super/duper/looper/themes/brightlight/library-RTL.css";
const parametersPath = "/resources/super/duper/looper/themes/brightlight/library-parameters.json";

const lessResource = resourceFactory.createResource({
path: lessPath,
string: lessContent
});

const lessVariablesResource = resourceFactory.createResource({
path: lessVariablesPath,
string: lessVariablesContent
});

return Promise.all([lessResource, lessVariablesResource].map((resource) => {
return reader.write(resource);
})).then(() => {
return tasks.buildThemes({
workspace: duplexCollection,
dependencies: dependencies,
options: {
inputPattern: "/resources/**/themes/**/library.source.less"
}
}).then(() => {
return Promise.all([
writer.byPath(cssPath),
writer.byPath(cssRtlPath),
writer.byPath(parametersPath)
]);
}).then(([cssResource, cssRtlResource, parametersResource]) => {
t.truthy(cssResource, "CSS resource has been created");
t.truthy(cssRtlResource, "CSS right-to-left resource has been created");
t.truthy(parametersResource, "Parameters JSON resource has been created");

return Promise.all([
cssResource.getBuffer(),
cssRtlResource.getBuffer(),
parametersResource.getBuffer()
]);
}).then(([cssBuffer, cssRtlBuffer, parametersBuffer]) => {
t.deepEqual(cssBuffer.toString(), cssExpected, "Correct CSS content");
t.deepEqual(cssRtlBuffer.toString(), cssRtlExpected, "Correct CSS right-to-left content");
t.deepEqual(parametersBuffer.toString(), parametersExpected, "Correct parameters JSON content");
});
});
});
Loading