Skip to content
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
26 changes: 14 additions & 12 deletions lib/tasks/createDebugFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ const dbg = require("../processors/debugFileCreator");
* @param {string} [parameters.options.pattern] Pattern to locate the files to be processed
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
module.exports = function({workspace, options}) {
return workspace.byGlob(options.pattern)
.then((allResources) => {
return dbg({
resources: allResources
});
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return workspace.write(resource);
}));
});
module.exports = async function({workspace, options}) {
let allResources;
if (workspace.byGlobSource) { // API only available on duplex collections
allResources = await workspace.byGlobSource(options.pattern);
} else {
allResources = await workspace.byGlob(options.pattern);
}
return dbg({
resources: allResources
}).then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return workspace.write(resource);
}));
});
};
22 changes: 11 additions & 11 deletions lib/types/application/ApplicationBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class ApplicationBuilder extends AbstractBuilder {
this.availableTasks = [
"replaceCopyright",
"replaceVersion",
"createDebugFiles",
"generateFlexChangesBundle",
"generateManifestBundle",
"generateComponentPreload",
"generateStandaloneAppBundle",
"generateBundle",
"createDebugFiles",
"uglify",
"generateVersionInfo"
];
Expand All @@ -52,16 +52,6 @@ class ApplicationBuilder extends AbstractBuilder {
});
});

this.addTask("createDebugFiles", () => {
const createDebugFiles = tasks.createDebugFiles;
return createDebugFiles({
workspace: resourceCollections.workspace,
options: {
pattern: "/**/*.js"
}
});
});

this.addTask("generateFlexChangesBundle", () => {
const generateFlexChangesBundle = tasks.generateFlexChangesBundle;
return generateFlexChangesBundle({
Expand Down Expand Up @@ -137,6 +127,16 @@ class ApplicationBuilder extends AbstractBuilder {
});
}

this.addTask("createDebugFiles", () => {
const createDebugFiles = tasks.createDebugFiles;
return createDebugFiles({
workspace: resourceCollections.workspace,
options: {
pattern: "/**/*.js"
}
});
});

this.addTask("uglify", () => {
const uglify = tasks.uglify;
return uglify({
Expand Down
22 changes: 11 additions & 11 deletions lib/types/library/LibraryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class LibraryBuilder extends AbstractBuilder {
this.availableTasks = [
"replaceCopyright",
"replaceVersion",
"createDebugFiles",
"generateComponentPreload",
"generateBundle",
"generateLibraryPreload",
"buildThemes",
"createDebugFiles",
"uglify"
];

Expand All @@ -52,16 +52,6 @@ class LibraryBuilder extends AbstractBuilder {
});
});

this.addTask("createDebugFiles", () => {
const createDebugFiles = tasks.createDebugFiles;
return createDebugFiles({
workspace: resourceCollections.workspace,
options: {
pattern: "/resources/**/*.js"
}
});
});

const componentPreload = project.builder && project.builder.componentPreload;
if (componentPreload) {
const generateComponentPreload = tasks.generateComponentPreload;
Expand Down Expand Up @@ -120,6 +110,16 @@ class LibraryBuilder extends AbstractBuilder {
});
});

this.addTask("createDebugFiles", () => {
const createDebugFiles = tasks.createDebugFiles;
return createDebugFiles({
workspace: resourceCollections.workspace,
options: {
pattern: "/resources/**/*.js"
}
});
});

this.addTask("uglify", () => {
const uglify = tasks.uglify;
return uglify({
Expand Down
2 changes: 0 additions & 2 deletions test/expected/build/application.g/dest/Component-preload.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
jQuery.sap.registerPreloadedModules({
"version":"2.0",
"modules":{
"application/g/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})});
},
"application/g/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})});
},
"application/g/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
jQuery.sap.registerPreloadedModules({
"version":"2.0",
"modules":{
"application/g/subcomponentA/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})});
},
"application/g/subcomponentA/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})});
},
"application/g/subcomponentA/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentA","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
jQuery.sap.registerPreloadedModules({
"version":"2.0",
"modules":{
"application/g/subcomponentB/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})});
},
"application/g/subcomponentB/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})});
},
"application/g/subcomponentB/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentB","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}'
Expand Down
65 changes: 29 additions & 36 deletions test/lib/tasks/createDebugFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;

test("test.js: dbg file creation", (t) => {
const sourceReader = resourceFactory.createAdapter({
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "console.log('Hello World');";
Expand All @@ -16,15 +16,14 @@ test("test.js: dbg file creation", (t) => {
string: content
});

const workspace = resourceFactory.createWorkspace({reader: sourceReader});
return workspace.write(resource).then(() => {
return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: workspace,
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return workspace.byPath("/test-dbg.js").then((resource) => {
return sourceAdapter.byPath("/test-dbg.js").then((resource) => {
if (!resource) {
t.fail("Could not find /test-dbg.js in target");
} else {
Expand All @@ -38,7 +37,7 @@ test("test.js: dbg file creation", (t) => {
});

test("test.view.js: dbg file creation", (t) => {
const sourceReader = resourceFactory.createAdapter({
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "console.log('Hello World');";
Expand All @@ -48,15 +47,14 @@ test("test.view.js: dbg file creation", (t) => {
string: content
});

const workspace = resourceFactory.createWorkspace({reader: sourceReader});
return workspace.write(resource).then(() => {
return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: workspace,
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return workspace.byPath("/test-dbg.view.js").then((resource) => {
return sourceAdapter.byPath("/test-dbg.view.js").then((resource) => {
if (!resource) {
t.fail("Could not find /test-dbg.view.js in target");
} else {
Expand All @@ -70,7 +68,7 @@ test("test.view.js: dbg file creation", (t) => {
});

test("test.controller.js: dbg file creation", (t) => {
const sourceReader = resourceFactory.createAdapter({
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "console.log('Hello World');";
Expand All @@ -80,15 +78,14 @@ test("test.controller.js: dbg file creation", (t) => {
string: content
});

const workspace = resourceFactory.createWorkspace({reader: sourceReader});
return workspace.write(resource).then(() => {
return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: workspace,
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return workspace.byPath("/test-dbg.controller.js").then((resource) => {
return sourceAdapter.byPath("/test-dbg.controller.js").then((resource) => {
if (!resource) {
t.fail("Could not find /test-dbg.controller.js in target");
} else {
Expand All @@ -102,7 +99,7 @@ test("test.controller.js: dbg file creation", (t) => {
});

test("test.fragment.js: dbg file creation", (t) => {
const sourceReader = resourceFactory.createAdapter({
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "console.log('Hello World');";
Expand All @@ -112,15 +109,14 @@ test("test.fragment.js: dbg file creation", (t) => {
string: content
});

const workspace = resourceFactory.createWorkspace({reader: sourceReader});
return workspace.write(resource).then(() => {
return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: workspace,
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return workspace.byPath("/test-dbg.fragment.js").then((resource) => {
return sourceAdapter.byPath("/test-dbg.fragment.js").then((resource) => {
if (!resource) {
t.fail("Could not find /test-dbg.fragment.js in target locator");
} else {
Expand All @@ -134,7 +130,7 @@ test("test.fragment.js: dbg file creation", (t) => {
});

test("test-dbg.js: dbg-dbg file creation", (t) => {
const sourceReader = resourceFactory.createAdapter({
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "console.log('Hello World');";
Expand All @@ -144,15 +140,14 @@ test("test-dbg.js: dbg-dbg file creation", (t) => {
string: content
});

const workspace = resourceFactory.createWorkspace({reader: sourceReader});
return workspace.write(resource).then(() => {
return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: workspace,
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return workspace.byPath("/test-dbg-dbg.js").then((resource) => {
return sourceAdapter.byPath("/test-dbg-dbg.js").then((resource) => {
if (!resource) {
t.fail("Could not find /test-dbg-dbg.js in target locator");
} else {
Expand All @@ -166,7 +161,7 @@ test("test-dbg.js: dbg-dbg file creation", (t) => {
});

test("test.xml: *no* dbg file creation", (t) => {
const sourceReader = resourceFactory.createAdapter({
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "<xml></xml>";
Expand All @@ -176,15 +171,14 @@ test("test.xml: *no* dbg file creation", (t) => {
string: content
});

const workspace = resourceFactory.createWorkspace({reader: sourceReader});
return workspace.write(resource).then(() => {
return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: workspace,
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return workspace.byPath("/test-dbg.xml").then((resource) => {
return sourceAdapter.byPath("/test-dbg.xml").then((resource) => {
if (!resource) {
t.pass("Could not find /test-dbg.xml in target locator as it is not a JavaScript file");
} else {
Expand All @@ -196,7 +190,7 @@ test("test.xml: *no* dbg file creation", (t) => {
});

test("test1.js, test2.js: dbg file creation", (t) => {
const sourceReader = resourceFactory.createAdapter({
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "console.log('Hello World');";
Expand All @@ -212,19 +206,18 @@ test("test1.js, test2.js: dbg file creation", (t) => {
})
];

const workspace = resourceFactory.createWorkspace({reader: sourceReader});
return Promise.all(resources.map((resource) => {
return workspace.write(resource);
return sourceAdapter.write(resource);
})).then(() => {
return tasks.createDebugFiles({
workspace: workspace,
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return Promise.all([
workspace.byPath("/test1-dbg.js"),
workspace.byPath("/test2-dbg.js")
sourceAdapter.byPath("/test1-dbg.js"),
sourceAdapter.byPath("/test2-dbg.js")
]).then((resources) => {
if (!resources || !resources[0] || !resources[1]) {
t.fail("Could not find /test1-dbg.js and/or /test2-dbg.js in target locator");
Expand Down