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] Add included/excludedDependencies parameter #380

Merged
merged 7 commits into from
Dec 16, 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
37 changes: 30 additions & 7 deletions lib/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ module.exports = {
* @param {string} parameters.destPath Target path
* @param {boolean} [parameters.cleanDest=false] Decides whether project should clean the target path before build
* @param {boolean} [parameters.buildDependencies=false] Decides whether project dependencies are built as well
* @param {Array.<string|RegExp>} [parameters.includedDependencies=[]] List of build dependencies to be included if buildDependencies is true
* @param {Array.<string|RegExp>} [parameters.excludedDependencies=[]] List of build dependencies to be excluded if buildDependencies is true. If the wildcard '*' is provided, only the included dependencies will be built.
* @param {boolean} [parameters.dev=false] Decides whether a development build should be activated (skips non-essential and time-intensive tasks)
* @param {boolean} [parameters.selfContained=false] Flag to activate self contained build
* @param {boolean} [parameters.jsdoc=false] Flag to activate JSDoc build
Expand All @@ -217,7 +219,8 @@ module.exports = {
*/
async build({
tree, destPath, cleanDest = false,
buildDependencies = false, dev = false, selfContained = false, jsdoc = false,
buildDependencies = false, includedDependencies = [], excludedDependencies = [],
dev = false, selfContained = false, jsdoc = false,
includedTasks = [], excludedTasks = [], devExcludeProject = []
}) {
const startTime = process.hrtime();
Expand All @@ -237,11 +240,30 @@ module.exports = {

const projects = {}; // Unique project index to prevent building the same project multiple times
const projectWriters = {}; // Collection of memory adapters of already built libraries
function projectFilter(project) {
function projectMatchesAny(deps) {
return deps.some((dep) => dep instanceof RegExp ?
dep.test(project.metadata.name) : dep === project.metadata.name);
}

// if everything is included, this overrules exclude lists
if (includedDependencies.includes("*")) return true;
let test = !excludedDependencies.includes("*"); // exclude everything?

if (test && projectMatchesAny(excludedDependencies)) {
test = false;
}
if (!test && projectMatchesAny(includedDependencies)) {
test = true;
}

return test;
}

const projectCountMarker = {};
function projectCount(project, count = 0) {
if (buildDependencies) {
count = project.dependencies.reduce((depCount, depProject) => {
count = project.dependencies.filter(projectFilter).reduce((depCount, depProject) => {
return projectCount(depProject, depCount);
}, count);
}
Expand All @@ -251,21 +273,22 @@ module.exports = {
}
return count;
}
const iProjectCount = projectCount(tree);
const buildLogger = log.createTaskLogger("🛠 ", iProjectCount);
const buildLogger = log.createTaskLogger("🛠 ", projectCount(tree));

function buildProject(project) {
let depPromise;
let projectTasks = selectedTasks;

// Build dependencies in sequence as it is far easier to detect issues and reduces
// side effects or other issues such as too many open files
if (buildDependencies) {
// Build dependencies in sequence as it is far easier to detect issues and reduces
// side effects or other issues such as too many open files
depPromise = project.dependencies.reduce(function(p, depProject) {
depPromise = project.dependencies.filter(projectFilter).reduce(function(p, depProject) {
return p.then(() => buildProject(depProject));
}, Promise.resolve());
} else {
depPromise = Promise.resolve();
}

// Build the project after all dependencies have been built
return depPromise.then(() => {
if (projects[project.metadata.name]) {
Expand Down
11 changes: 11 additions & 0 deletions test/expected/build/application.a/dest-deps-excl/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Application A</title>
<script id="sap-ui-bootstrap" src="test.js">
</script>
</head>
<body>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.a</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright ${currentYear}</copyright>
<version>1.0.0</version>

<documentation>Library A</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.library-a-foo{color:#fafad2;padding:1px 4px 3px 2px}
/* Inline theming parameters */
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"libraryAColor1":"#fafad2"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.library-a-foo{color:#fafad2;padding:1px 2px 3px 4px}
/* Inline theming parameters */
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@libraryAColor1: lightgoldenrodyellow;

.library-a-foo {
color: @libraryAColor1;
padding: 1px 2px 3px 4px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.b</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright ${currentYear}</copyright>
<version>1.0.0</version>

<documentation>Library B</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

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

<documentation>Library C</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</library>
9 changes: 9 additions & 0 deletions test/expected/build/application.a/dest-deps-excl/test-dbg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sap.ui.define([
"library/d/some"
], function(someObject) {
function test(paramA) {
var variableA = paramA;
console.log(variableA);
}
test();
});
1 change: 1 addition & 0 deletions test/expected/build/application.a/dest-deps-excl/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sap.ui.define(["library/d/some"],function(n){function o(n){var o=n;console.log(o)}o()});
11 changes: 11 additions & 0 deletions test/expected/build/application.a/dest-deps/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Application A</title>
<script id="sap-ui-bootstrap" src="test.js">
</script>
</head>
<body>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.a</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright ${currentYear}</copyright>
<version>1.0.0</version>

<documentation>Library A</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.library-a-foo{color:#fafad2;padding:1px 4px 3px 2px}
/* Inline theming parameters */
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"libraryAColor1":"#fafad2"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.library-a-foo{color:#fafad2;padding:1px 2px 3px 4px}
/* Inline theming parameters */
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@libraryAColor1: lightgoldenrodyellow;

.library-a-foo {
color: @libraryAColor1;
padding: 1px 2px 3px 4px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.b</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright ${currentYear}</copyright>
<version>1.0.0</version>

<documentation>Library B</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

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

<documentation>Library C</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</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.d</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<documentation>Library D</documentation>

</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*!
* Some fancy copyright
*/
(function() {
var someNonUglifiedVariable = "World";
console.log('Hello ' + someNonUglifiedVariable);
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*!
* Some fancy copyright
*/
(function(){var o="World";console.log("Hello "+o)})();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// this is just a marker file to enable the EVO bundle format
Empty file.
9 changes: 9 additions & 0 deletions test/expected/build/application.a/dest-deps/test-dbg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sap.ui.define([
"library/d/some"
], function(someObject) {
function test(paramA) {
var variableA = paramA;
console.log(variableA);
}
test();
});
1 change: 1 addition & 0 deletions test/expected/build/application.a/dest-deps/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sap.ui.define(["library/d/some"],function(n){function o(n){var o=n;console.log(o)}o()});
11 changes: 11 additions & 0 deletions test/expected/build/application.a/dest-depself/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Application A</title>
<script id="sap-ui-bootstrap" src="resources/sap-ui-custom.js">
</script>
</head>
<body>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.a</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright ${currentYear}</copyright>
<version>1.0.0</version>

<documentation>Library A</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.library-a-foo{color:#fafad2;padding:1px 4px 3px 2px}
/* Inline theming parameters */
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"libraryAColor1":"#fafad2"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.library-a-foo{color:#fafad2;padding:1px 2px 3px 4px}
/* Inline theming parameters */
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@libraryAColor1: lightgoldenrodyellow;

.library-a-foo {
color: @libraryAColor1;
padding: 1px 2px 3px 4px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.b</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright ${currentYear}</copyright>
<version>1.0.0</version>

<documentation>Library B</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

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

<documentation>Library C</documentation>

<dependencies>
<dependency>
<libraryName>library.d</libraryName>
</dependency>
</dependencies>

</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.d</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<documentation>Library D</documentation>

</library>
Loading