Skip to content

Commit

Permalink
[INTERNAL] Align set of known file types with runtime
Browse files Browse the repository at this point in the history
UI5 runtime knows JavaScript file types controller, designtime,
fragment, support and view.

TODO: support files should not be uglified (to keep the rules source
code readable). It has to be decided whether this is realized by
configuration or whether it should be hard coded in the task / processor
or (library) type.
  • Loading branch information
codeworrior committed Sep 20, 2019
1 parent 327cca0 commit 6a53ed1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/lbt/utils/ModuleName.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function toRequireJSName(path) {
return path.slice(0, -3); // cut off '.js'
}

const KNOWN_TYPES = /\.(properties|css|(?:(?:view\.|fragment\.)?(?:html|json|xml|js))|(?:(?:controller\.)?js))$/;
const KNOWN_TYPES = /\.(properties|css|(?:(?:view\.|fragment\.)?(?:html|json|xml|js))|(?:(?:controller\.|designtime\.|support\.)?js))$/;

function getDebugName(name) {
const m = KNOWN_TYPES.exec(name);
Expand Down
2 changes: 1 addition & 1 deletion lib/processors/debugFileCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const util = require("util");
*/
module.exports = function({resources, fs}) {
const options = {
pattern: /((\.view|\.fragment|\.controller)?\.js)/,
pattern: /((\.view|\.fragment|\.controller|\.designtime|\.support)?\.js)/,
replacement: "-dbg$1"
};

Expand Down
8 changes: 8 additions & 0 deletions test/lib/lbt/utils/ModuleName.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@ test("toRequireJSName", (t) => {

test("getDebugName", (t) => {
t.deepEqual(ModuleName.getDebugName("a.controller.js"), "a-dbg.controller.js", "'-dbg' is added");
t.deepEqual(ModuleName.getDebugName("a.designtime.js"), "a-dbg.designtime.js", "'-dbg' is added");
t.deepEqual(ModuleName.getDebugName("a.fragment.js"), "a-dbg.fragment.js", "'-dbg' is added");
t.deepEqual(ModuleName.getDebugName("a.support.js"), "a-dbg.support.js", "'-dbg' is added");
t.deepEqual(ModuleName.getDebugName("a.view.js"), "a-dbg.view.js", "'-dbg' is added");
t.deepEqual(ModuleName.getDebugName("a.css"), "a-dbg.css", "'-dbg' is added");
t.falsy(ModuleName.getDebugName("a"), "non supported file ending");
t.falsy(ModuleName.getDebugName("a.mjs"), "non supported file ending");
});

test("getNonDebugName", (t) => {
t.deepEqual(ModuleName.getNonDebugName("a-dbg.controller.js"), "a.controller.js", "contains '-dbg'");
t.deepEqual(ModuleName.getNonDebugName("a-dbg.designtime.js"), "a.designtime.js", "contains '-dbg'");
t.deepEqual(ModuleName.getNonDebugName("a-dbg.fragment.js"), "a.fragment.js", "contains '-dbg'");
t.deepEqual(ModuleName.getNonDebugName("a-dbg.support.js"), "a.support.js", "contains '-dbg'");
t.deepEqual(ModuleName.getNonDebugName("a-dbg.view.js"), "a.view.js", "contains '-dbg'");
t.deepEqual(ModuleName.getNonDebugName("a-dbg.css"), "a.css", "contains '-dbg'");
t.falsy(ModuleName.getNonDebugName("a"), "does not contain '-dbg'");
t.falsy(ModuleName.getNonDebugName("a-dbg.mjs"), "does contain '-dbg' but ending is not supported");
Expand Down
62 changes: 62 additions & 0 deletions test/lib/tasks/createDebugFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ test("integration: test.controller.js: dbg file creation", (t) => {
});
});

test("integration: test.designtime.js: dbg file creation", (t) => {
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "sap.ui.define([],function(){return {};});";

const resource = resourceFactory.createResource({
path: "/test.designtime.js",
string: content
});

return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return sourceAdapter.byPath("/test-dbg.designtime.js").then((resource) => {
if (!resource) {
t.fail("Could not find /test-dbg.designtime.js in target");
} else {
return resource.getBuffer();
}
});
}).then((buffer) => {
t.deepEqual(buffer.toString(), content, "Correct content");
});
});
});

test("integration: test.fragment.js: dbg file creation", (t) => {
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
Expand Down Expand Up @@ -129,6 +160,37 @@ test("integration: test.fragment.js: dbg file creation", (t) => {
});
});

test("integration: test.support.js: dbg file creation", (t) => {
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
});
const content = "sap.ui.define([],function(){return {};});";

const resource = resourceFactory.createResource({
path: "/test.support.js",
string: content
});

return sourceAdapter.write(resource).then(() => {
return tasks.createDebugFiles({
workspace: sourceAdapter,
options: {
pattern: "/**/*.js"
}
}).then(() => {
return sourceAdapter.byPath("/test-dbg.support.js").then((resource) => {
if (!resource) {
t.fail("Could not find /test-dbg.support.js in target");
} else {
return resource.getBuffer();
}
});
}).then((buffer) => {
t.deepEqual(buffer.toString(), content, "Correct content");
});
});
});

test("integration: test-dbg.js: dbg-dbg file creation", (t) => {
const sourceAdapter = resourceFactory.createAdapter({
virBasePath: "/"
Expand Down

0 comments on commit 6a53ed1

Please sign in to comment.