Skip to content

Commit

Permalink
further steps
Browse files Browse the repository at this point in the history
  • Loading branch information
flovogt committed Dec 15, 2023
1 parent cf76002 commit 37903f9
Show file tree
Hide file tree
Showing 25 changed files with 349 additions and 265 deletions.
60 changes: 29 additions & 31 deletions lib/processors/manifestTransformer.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import semver from "semver";
const {SemVer: Version} = semver;
import {promisify} from "node:util";
import path from "node:path/posix";
import {getLogger} from "@ui5/logger";
const log = getLogger("builder:processors:manifestTransformer");

const APP_DESCRIPTOR_V22 = new Version("1.21.0");

/**
* Transforms i18n_en.properties to en
* Transforms i18n_en_US.properties to en_US
*
* @param {string} name
* @param {string} bundleName
* @param {string} defaultBundleName
*/
function getLocale(name) {
log.verbose("File name: " + name);
return name.substring(name.lastIndexOf("_") + 1).replaceAll(".properties", "");
}
function getLocale(bundleName, defaultBundleName) {
log.verbose("File name: " + bundleName);
bundleName = path.basename(bundleName, ".properties");
defaultBundleName = path.basename(defaultBundleName, ".properties");

function cleanup(name, defaultBundleName) {
return name === defaultBundleName ? "" : name;
if (bundleName === defaultBundleName) {
return "";
} else {
return bundleName.replace(defaultBundleName + "_", "");
}
}

/**
Expand Down Expand Up @@ -183,8 +188,8 @@ async function transformManifest(resource, readdir, 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 namespace = resource.getProject().getNamespace();
const isNamespaced = resource.getPath().includes(namespace);

const manifest = JSON.parse(content);

Expand All @@ -208,41 +213,34 @@ async function transformManifest(resource, readdir, options) {
// check which locales are avalable
await Promise.all(bundles.map(async (bundleConfig) => {
const {bundleUrl, bundleName, fallbackLocale} = bundleConfig;
let propertyFilesPath = bundleUrl;
let defaultBundleName = bundleUrl;

if (bundleName) {
propertyFilesPath = bundleName.replace(/\./g, "/") + ".properties";
defaultBundleName = bundleName.replace(/\./g, "/");
defaultBundleName = defaultBundleName.replace(namespace, "");
}

// Library:
// library.n.i18n.messagebundle
// i18n/messagebundle.properties
if (bundleUrl) {
defaultBundleName = bundleUrl.replace(".properties", "");
}

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

let pathToDefaultBundleName = "";

const propertyFileNameRaw = propertyFilesPath.substring(propertyFilesPath.lastIndexOf("/") + 1);
const propertyFileName = propertyFileNameRaw.replaceAll(".properties", "");
propertyFilesPath = propertyFilesPath.substring(0, propertyFilesPath.lastIndexOf("/"));
if (propertyFilesPath) {
propertyFilesPath += "/";
if (isNamespaced) {
pathToDefaultBundleName= `/resources/${namespace}`;
}

log.verbose("Locales Path: " + propertyFilesPath);
log.verbose("Locales File: " + propertyFileNameRaw);
pathToDefaultBundleName = path.join(pathToDefaultBundleName, defaultBundleName);

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

const generatedSupportedLocales = (await readdir(path))
const generatedSupportedLocales = (await readdir(path.dirname(pathToDefaultBundleName)))
.filter((name) => name.endsWith(".properties") && name.startsWith(path.basename(defaultBundleName)))
.map((name) => {
log.verbose("File name: " + name);
return cleanup(getLocale(name), propertyFileName);
return getLocale(name, defaultBundleName);
}).sort();

log.verbose("Generated locales: " + generatedSupportedLocales.toString());
Expand Down
12 changes: 12 additions & 0 deletions test/expected/build/application.m/dest/Component-preload.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
welcome=Hello world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
welcome=Hello EN world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
welcome=Hello EN US world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
welcome=Hello EN US sapprc world
11 changes: 11 additions & 0 deletions test/expected/build/application.m/dest/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Application M</title>
<script id="sap-ui-bootstrap" src="test.js">
</script>
</head>
<body>

</body>
</html>
36 changes: 36 additions & 0 deletions test/expected/build/application.m/dest/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"_version": "1.22.0",
"sap.app": {
"id": "application.m",
"type": "application",
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{title}}",
"i18n": {
"bundleUrl": "i18n/i18n.properties",
"supportedLocales": [
"",
"en",
"en_US",
"en_US_sapprc"
]
}
},
"sap.ui5": {
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "application.m.i18n.i18n",
"supportedLocales": [
"",
"en",
"en_US",
"en_US_sapprc"
]
}
}
}
}
}
8 changes: 8 additions & 0 deletions test/expected/build/application.m/dest/test-dbg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sap.ui.define([
], () => {
test((paramA) => {
const variableA = paramA;
console.log(variableA);
})
test();
});
2 changes: 2 additions & 0 deletions test/expected/build/application.m/dest/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/expected/build/application.m/dest/test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 37903f9

Please sign in to comment.