Skip to content

Commit

Permalink
adjust transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
flovogt committed Jan 3, 2024
1 parent 421ed45 commit 18a3dcf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 24 deletions.
57 changes: 39 additions & 18 deletions lib/processors/manifestTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ function getTerminologieBundles(bundleConfig, bundleConfigs) {
terminologyBundles.push(bundleConfig.terminologies[key]);
});
}
return bundleConfigs.concat(terminologyBundles);
bundleConfigs.push(...terminologyBundles);
}

function getEnhanceWithBundles(bundleConfig, bundleConfigs) {
if (!bundleConfig.enhanceWith) {
return bundleConfigs;
}
return bundleConfigs.concat(bundleConfig.enhanceWith);

bundleConfig.enhanceWith.forEach((config) => {
getTerminologieBundles(config, bundleConfigs);
});

bundleConfigs.push(...bundleConfig.enhanceWith);
}

function getSapAppBundle(manifest, bundleConfigs) {
Expand All @@ -109,14 +114,12 @@ function getSapAppBundle(manifest, bundleConfigs) {
bundleUrl: sapAppBundleConfig
};
} else {
bundleConfigs = getTerminologieBundles(sapAppBundleConfig, bundleConfigs);
bundleConfigs = getEnhanceWithBundles(sapAppBundleConfig, bundleConfigs);
getTerminologieBundles(sapAppBundleConfig, bundleConfigs);
getEnhanceWithBundles(sapAppBundleConfig, bundleConfigs);
}

sapAppConfig.i18n = sapAppBundleConfig;
bundleConfigs.push(sapAppBundleConfig);

return bundleConfigs;
}

function getSapUi5ModelBundles(manifest, bundleConfigs) {
Expand All @@ -125,10 +128,10 @@ function getSapUi5ModelBundles(manifest, bundleConfigs) {
.filter((model) => model.type === "sap.ui.model.resource.ResourceModel")
.map((model) => model.settings);
sapui5ModelConfigBundles.forEach((bundleConfig) => {
bundleConfigs = bundleConfigs.concat(getTerminologieBundles(bundleConfig, bundleConfigs));
bundleConfigs = bundleConfigs.concat(getEnhanceWithBundles(bundleConfig, bundleConfigs));
getTerminologieBundles(bundleConfig, bundleConfigs);
getEnhanceWithBundles(bundleConfig, bundleConfigs);
});
return bundleConfigs.concat(sapui5ModelConfigBundles);
bundleConfigs.push(...sapui5ModelConfigBundles);
}

function getSapUi5LibrariesBundles(manifest, bundleConfigs) {
Expand All @@ -148,26 +151,24 @@ function getSapUi5LibrariesBundles(manifest, bundleConfigs) {
bundleUrl: "messagebundle.properties"
};
} else {
bundleConfigs = getTerminologieBundles(sapui5LibraryBundleConfig, bundleConfigs);
bundleConfigs = getEnhanceWithBundles(sapui5LibraryBundleConfig, bundleConfigs);
getTerminologieBundles(sapui5LibraryBundleConfig, bundleConfigs);
getEnhanceWithBundles(sapui5LibraryBundleConfig, bundleConfigs);
}

sapui5LibraryConfig.i18n = sapui5LibraryBundleConfig;
bundleConfigs.push(sapui5LibraryBundleConfig);

return bundleConfigs;
}

function getBundles(manifest) {
let bundleConfigs = [];
const bundleConfigs = [];
const appType = getType(manifest);

bundleConfigs = getSapAppBundle(manifest, bundleConfigs);
getSapAppBundle(manifest, bundleConfigs);

if (appType === "library") {
bundleConfigs = getSapUi5LibrariesBundles(manifest, bundleConfigs);
getSapUi5LibrariesBundles(manifest, bundleConfigs);
} else {
bundleConfigs = getSapUi5ModelBundles(manifest, bundleConfigs);
getSapUi5ModelBundles(manifest, bundleConfigs);
}

return bundleConfigs
Expand All @@ -180,6 +181,11 @@ async function transformManifest(resource, readdir, options) {
prettyPrint: true,
}, options);
const content = await resource.getString();

// in case of server middleware --> isNamespaced ist false
// const namespace = resource.getProject().getNamespace();
// const isNamespaced = resource.getPath().includes(namespace);

const manifest = JSON.parse(content);

if (!manifest._version) {
Expand Down Expand Up @@ -208,14 +214,29 @@ async function transformManifest(resource, readdir, options) {
propertyFilesPath = bundleName.replace(/\./g, "/") + ".properties";
}

// Library:
// library.n.i18n.messagebundle
// i18n/messagebundle.properties

// Application
// sap.ui.demo.todo.i18n.i18n -> i18n/i18n.properties
// i18n.properties
// ../../i18n.properties
// /hjfbjfbsfjhb/i18n.properties
// ui5://i18n.properties


const propertyFileNameRaw = propertyFilesPath.substring(propertyFilesPath.lastIndexOf("/") + 1);
const propertyFileName = propertyFileNameRaw.replaceAll(".properties", "");
propertyFilesPath = propertyFilesPath.substring(0, propertyFilesPath.lastIndexOf("/"));
if (propertyFilesPath) {
propertyFilesPath += "/";
}

log.verbose("Locales Path: " + propertyFilesPath);
log.verbose("Locales File: " + propertyFileNameRaw);

const path = `/resources/${propertyFilesPath}/`;
const path = `/resources/${propertyFilesPath}`;
log.verbose("Path: " + path);

const generatedSupportedLocales = (await readdir(path))
Expand Down
2 changes: 1 addition & 1 deletion test/lib/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ test.serial("Build theme-library with CSS variables and theme designer resources
t.pass();
});

test.serial("Build library.n with terminologies and supportedLocales", async (t) => {
test.serial.only("Build library.n with terminologies and supportedLocales", async (t) => {
const destPath = path.join("test", "tmp", "build", "library.n", "dest");
const expectedPath = path.join("test", "expected", "build", "library.n");

Expand Down
8 changes: 4 additions & 4 deletions test/lib/processors/manifestTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1173,15 +1173,15 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit
"bundleUrl": "myfolder1/messagebundlenc1.properties",
"terminologies": {
"sports": {
"bundleUrl": "i18nc_sports/messagebundle.soccer.properties"
"bundleUrl": "i18nc_sports_soccer/messagebundle.soccer.properties"
}
}
},
{
"bundleUrl": "myfolder2/messagebundlenc2.properties",
"terminologies": {
"sports": {
"bundleUrl": "i18nc_sports/messagebundle.euroleaguesoccer.properties"
"bundleUrl": "i18nc_sports_soccer_el/messagebundle.elsoccer.properties"
}
}
}
Expand Down Expand Up @@ -1222,7 +1222,7 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit
"bundleUrl": "myfolder2/messagebundlenc2.properties",
"terminologies": {
"sports": {
"bundleUrl": "i18nc_sports_soccer_euroleague/messagebundle.elsoccer.properties",
"bundleUrl": "i18nc_sports_soccer_el/messagebundle.elsoccer.properties",
"supportedLocales": ["", "de", "en"]
}
},
Expand Down Expand Up @@ -1270,7 +1270,7 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit
"messagebundle.soccer_en.properties",
"messagebundle.soccer.properties"
]);
} else if (fsPath && fsPath.endsWith("i18nc_sports_soccer_euroleague/")) {
} else if (fsPath && fsPath.endsWith("i18nc_sports_soccer_el/")) {
return callback(null, [
"messagebundle.elsoccer_de.properties",
"messagebundle.elsoccer_en.properties",
Expand Down
26 changes: 25 additions & 1 deletion test/lib/tasks/transformManifest.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import test from "ava";
import sinonGlobal from "sinon";
import esmock from "esmock";
import {createAdapter, createResource} from "@ui5/fs/resourceFactory";

function createWorkspace() {
return createAdapter({
virBasePath: "/",
project: {
getName: () => "test.lib",
getVersion: () => "2.0.0",
}
});
}

test.beforeEach(async (t) => {
const sinon = t.context.sinon = sinonGlobal.createSandbox();

t.context.log = {
verbose: sinon.stub(),
warn: sinon.stub(),
error: sinon.stub()
};
Expand All @@ -19,6 +31,7 @@ test.beforeEach(async (t) => {
"@ui5/fs/fsInterface": t.context.fsInterfaceStub,
"../../../lib/processors/manifestTransformer": t.context.manifestTransformerStub,
});
t.context.workspace = createWorkspace();
});

test.afterEach.always((t) => {
Expand All @@ -30,7 +43,18 @@ test.serial("Transforms manifest.json resource", async (t) => {

t.plan(6);

const resource = {};
const resource = createResource({
path: "/resources/sap/ui/demo/app/manifest.json",
string: `{
"_version": "1.58.0",
"sap.app": {
"id": "sap.ui.demo.app",
"type": "application",
"title": "{{title}}"
}
`,
project: t.context.workspace._project
});

const workspace = {
byGlob: (actualPath) => {
Expand Down

0 comments on commit 18a3dcf

Please sign in to comment.