Skip to content

Commit 04eb695

Browse files
mauriciolaufferRandomByte
authored andcommitted
[FEATURE] clean build folder: Allows developers to clean build folder before start building a project
1 parent e2117f4 commit 04eb695

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/builder/builder.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const {promisify} = require("util");
2+
const rimraf = promisify(require("rimraf"));
13
const log = require("@ui5/logger").getGroupLogger("builder:builder");
24
const resourceFactory = require("@ui5/fs").resourceFactory;
35
const MemAdapter = require("@ui5/fs").adapters.Memory;
@@ -203,6 +205,7 @@ module.exports = {
203205
* @param {Object} parameters Parameters
204206
* @param {Object} parameters.tree Dependency tree
205207
* @param {string} parameters.destPath Target path
208+
* @param {boolean} [parameters.cleanDest=false] Decides whether project should clean the target path before build
206209
* @param {boolean} [parameters.buildDependencies=false] Decides whether project dependencies are built as well
207210
* @param {boolean} [parameters.dev=false] Decides whether a development build should be activated (skips non-essential and time-intensive tasks)
208211
* @param {boolean} [parameters.selfContained=false] Flag to activate self contained build
@@ -213,7 +216,7 @@ module.exports = {
213216
* @returns {Promise} Promise resolving to <code>undefined</code> once build has finished
214217
*/
215218
async build({
216-
tree, destPath,
219+
tree, destPath, cleanDest = false,
217220
buildDependencies = false, dev = false, selfContained = false, jsdoc = false,
218221
includedTasks = [], excludedTasks = [], devExcludeProject = []
219222
}) {
@@ -342,6 +345,9 @@ module.exports = {
342345
}
343346

344347
try {
348+
if (cleanDest) {
349+
await rimraf(destPath);
350+
}
345351
await buildProject(tree);
346352
log.info(`Build succeeded in ${getElapsedTime(startTime)}`);
347353
} catch (err) {

test/lib/builder/builder.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,34 @@ test("Build application.a [dev mode]", (t) => {
129129
});
130130
});
131131

132+
test("Build application.a and clean target path [dev mode]", (t) => {
133+
const destPath = "./test/tmp/build/application.a/dest-clean";
134+
const destPathRubbishSubFolder = destPath + "/rubbish-should-be-deleted";
135+
const expectedPath = path.join("test", "expected", "build", "application.a", "dest-dev");
136+
137+
return builder.build({
138+
tree: applicationATree,
139+
destPath: destPathRubbishSubFolder,
140+
dev: true
141+
}).then(() => {
142+
return builder.build({
143+
tree: applicationATree,
144+
destPath,
145+
cleanDest: true,
146+
dev: true
147+
});
148+
}).then(() => {
149+
return findFiles(expectedPath);
150+
}).then((expectedFiles) => {
151+
// Check for all directories and files
152+
assert.directoryDeepEqual(destPath, expectedPath);
153+
// Check for all file contents
154+
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
155+
}).then(() => {
156+
t.pass();
157+
});
158+
});
159+
132160
test("Build application.g", (t) => {
133161
const destPath = "./test/tmp/build/application.g/dest";
134162
const expectedPath = path.join("test", "expected", "build", "application.g", "dest");

0 commit comments

Comments
 (0)