diff --git a/lib/processors/manifestTransformer.js b/lib/processors/manifestTransformer.js index 9e6317fbe..0774c00ee 100644 --- a/lib/processors/manifestTransformer.js +++ b/lib/processors/manifestTransformer.js @@ -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 + "_", ""); + } } /** @@ -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); @@ -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()); diff --git a/test/expected/build/application.m/dest/Component-preload.js b/test/expected/build/application.m/dest/Component-preload.js new file mode 100644 index 000000000..dcefc3638 --- /dev/null +++ b/test/expected/build/application.m/dest/Component-preload.js @@ -0,0 +1,12 @@ +//@ui5-bundle application/m/Component-preload.js +sap.ui.require.preload({ + "application/m/i18n/i18n.properties":'welcome=Hello world', + "application/m/i18n/i18n_en.properties":'welcome=Hello EN world', + "application/m/i18n/i18n_en_US.properties":'welcome=Hello EN US world', + "application/m/i18n/i18n_en_US_sapprc.properties":'welcome=Hello EN US sapprc world', + "application/m/manifest.json":'{"_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"]}}}}}', + "application/m/test.js":function(){ +sap.ui.define([],()=>{test(e=>{const s=e;console.log(s)});test()}); +} +}); +//# sourceMappingURL=Component-preload.js.map diff --git a/test/expected/build/application.m/dest/Component-preload.js.map b/test/expected/build/application.m/dest/Component-preload.js.map new file mode 100644 index 000000000..2a9a6053e --- /dev/null +++ b/test/expected/build/application.m/dest/Component-preload.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Component-preload.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["Component-preload.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":8,"column":0},"map":{"version":3,"file":"test.js","names":["sap","ui","define","test","paramA","variableA","console","log"],"sources":["test-dbg.js"],"mappings":"AAAAA,IAAIC,GAAGC,OAAO,GACX,KACFC,KAAMC,IACL,MAAMC,EAAYD,EAClBE,QAAQC,IAAIF,EAAU,GAEvBF,MAAM","sourceRoot":""}}]} \ No newline at end of file diff --git a/test/expected/build/application.m/dest/i18n/i18n.properties b/test/expected/build/application.m/dest/i18n/i18n.properties new file mode 100644 index 000000000..4fa9396ef --- /dev/null +++ b/test/expected/build/application.m/dest/i18n/i18n.properties @@ -0,0 +1 @@ +welcome=Hello world \ No newline at end of file diff --git a/test/expected/build/application.m/dest/i18n/i18n_en.properties b/test/expected/build/application.m/dest/i18n/i18n_en.properties new file mode 100644 index 000000000..f03a373b0 --- /dev/null +++ b/test/expected/build/application.m/dest/i18n/i18n_en.properties @@ -0,0 +1 @@ +welcome=Hello EN world \ No newline at end of file diff --git a/test/expected/build/application.m/dest/i18n/i18n_en_US.properties b/test/expected/build/application.m/dest/i18n/i18n_en_US.properties new file mode 100644 index 000000000..60d20479d --- /dev/null +++ b/test/expected/build/application.m/dest/i18n/i18n_en_US.properties @@ -0,0 +1 @@ +welcome=Hello EN US world \ No newline at end of file diff --git a/test/expected/build/application.m/dest/i18n/i18n_en_US_sapprc.properties b/test/expected/build/application.m/dest/i18n/i18n_en_US_sapprc.properties new file mode 100644 index 000000000..2376090d4 --- /dev/null +++ b/test/expected/build/application.m/dest/i18n/i18n_en_US_sapprc.properties @@ -0,0 +1 @@ +welcome=Hello EN US sapprc world \ No newline at end of file diff --git a/test/expected/build/application.m/dest/index.html b/test/expected/build/application.m/dest/index.html new file mode 100644 index 000000000..fd6a73c97 --- /dev/null +++ b/test/expected/build/application.m/dest/index.html @@ -0,0 +1,11 @@ + + + + Application M + + + + + + \ No newline at end of file diff --git a/test/expected/build/application.m/dest/manifest.json b/test/expected/build/application.m/dest/manifest.json new file mode 100644 index 000000000..86edba135 --- /dev/null +++ b/test/expected/build/application.m/dest/manifest.json @@ -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" + ] + } + } + } + } +} \ No newline at end of file diff --git a/test/expected/build/application.m/dest/test-dbg.js b/test/expected/build/application.m/dest/test-dbg.js new file mode 100644 index 000000000..399a1b6a1 --- /dev/null +++ b/test/expected/build/application.m/dest/test-dbg.js @@ -0,0 +1,8 @@ +sap.ui.define([ +], () => { + test((paramA) => { + const variableA = paramA; + console.log(variableA); + }) + test(); +}); diff --git a/test/expected/build/application.m/dest/test.js b/test/expected/build/application.m/dest/test.js new file mode 100644 index 000000000..2a39c7bc3 --- /dev/null +++ b/test/expected/build/application.m/dest/test.js @@ -0,0 +1,2 @@ +sap.ui.define([],()=>{test(e=>{const s=e;console.log(s)});test()}); +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/test/expected/build/application.m/dest/test.js.map b/test/expected/build/application.m/dest/test.js.map new file mode 100644 index 000000000..01a23e40f --- /dev/null +++ b/test/expected/build/application.m/dest/test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test.js","names":["sap","ui","define","test","paramA","variableA","console","log"],"sources":["test-dbg.js"],"mappings":"AAAAA,IAAIC,GAAGC,OAAO,GACX,KACFC,KAAMC,IACL,MAAMC,EAAYD,EAClBE,QAAQC,IAAIF,EAAU,GAEvBF,MAAM"} \ No newline at end of file diff --git a/test/expected/build/library.n/resources/library/n/library-preload.js b/test/expected/build/library.n/resources/library/n/library-preload.js index 30753c851..50a6ff5a4 100644 --- a/test/expected/build/library.n/resources/library/n/library-preload.js +++ b/test/expected/build/library.n/resources/library/n/library-preload.js @@ -4,6 +4,6 @@ */ sap.ui.predefine("library/n/library", ["sap/ui/core/Core"],e=>{"use strict";sap.ui.getCore().initLibrary({name:"library.n",version:"1.0.0",dependencies:[]});return thisLib}); sap.ui.require.preload({ - "library/n/manifest.json":'{"_version":"1.21.0","sap.app":{"id":"library.n","type":"library","embeds":[],"applicationVersion":{"version":"1.0.0"},"title":"{{title}}","description":"{{description}}","resources":"resources.json","offline":true},"sap.ui":{"technology":"UI5","supportedThemes":[]},"sap.ui5":{"dependencies":{"libs":{}},"library":{"i18n":{"bundleUrl":"messagebundle.properties","supportedLocales":["","de","en"],"terminologies":{"sports":{"bundleUrl":"sports.properties","bundleUrlRelativeTo":"manifest","supportedLocales":["en","fr"]},"travel":{"bundleUrl":"travel.properties","bundleUrlRelativeTo":"manifest","supportedLocales":["en","pt"]}}}}}}' + "library/n/manifest.json":'{"_version":"1.58.0","sap.app":{"id":"library.n","type":"library","embeds":[],"applicationVersion":{"version":"1.0.0"},"title":"{{title}}","description":"{{description}}","resources":"resources.json","offline":true},"sap.ui":{"technology":"UI5","supportedThemes":[]},"sap.ui5":{"dependencies":{"libs":{}},"library":{"i18n":{"bundleUrl":"messagebundle.properties","terminologies":{"sports":{"bundleUrl":"sports.properties","bundleUrlRelativeTo":"manifest","supportedLocales":["","de","en"]},"travel":{"bundleUrl":"travel.properties","bundleUrlRelativeTo":"manifest","supportedLocales":["","de","en"]}},"enhanceWith":[{"bundleUrl":"myfolder1/i18n.properties","bundleUrlRelativeTo":"manifest","terminologies":{"sports":{"bundleUrl":"myfolder1/soccer.properties","bundleUrlRelativeTo":"manifest","supportedLocales":["","de","en"]},"travel":{"bundleUrl":"myfolder1/vehicles.properties","bundleUrlRelativeTo":"manifest","supportedLocales":["","de","en"]}},"supportedLocales":["","en"]},{"bundleUrl":"myfolder2/i18n.properties","bundleUrlRelativeTo":"manifest","terminologies":{"travel":{"bundleUrl":"myfolder2/bicycles.properties","bundleUrlRelativeTo":"manifest","supportedLocales":["","de","en"]}},"supportedLocales":["","en"]}],"supportedLocales":["","de","en"]}}}}' }); //# sourceMappingURL=library-preload.js.map diff --git a/test/expected/build/library.n/resources/library/n/manifest.json b/test/expected/build/library.n/resources/library/n/manifest.json index cd830fcc5..33b527ef3 100644 --- a/test/expected/build/library.n/resources/library/n/manifest.json +++ b/test/expected/build/library.n/resources/library/n/manifest.json @@ -1,105 +1,103 @@ { - "_version": "1.21.0", - "sap.app": { - "id": "library.n", - "type": "library", - "embeds": [], - "applicationVersion": { - "version": "1.0.0" - }, - "title": "{{title}}", - "description": "{{description}}", - "resources": "resources.json", - "offline": true + "_version": "1.58.0", + "sap.app": { + "id": "library.n", + "type": "library", + "embeds": [], + "applicationVersion": { + "version": "1.0.0" }, - "sap.ui": { - "technology": "UI5", - "supportedThemes": [] + "title": "{{title}}", + "description": "{{description}}", + "resources": "resources.json", + "offline": true + }, + "sap.ui": { + "technology": "UI5", + "supportedThemes": [] + }, + "sap.ui5": { + "dependencies": { + "libs": {} }, - "sap.ui5": { - "dependencies": { - "libs": {} + "library": { + "i18n": { + "bundleUrl": "messagebundle.properties", + "terminologies": { + "sports": { + "bundleUrl": "sports.properties", + "bundleUrlRelativeTo": "manifest", + "supportedLocales": [ + "", + "de", + "en" + ] + }, + "travel": { + "bundleUrl": "travel.properties", + "bundleUrlRelativeTo": "manifest", + "supportedLocales": [ + "", + "de", + "en" + ] + } }, - "library": { - "i18n": { - "bundleUrl": "messagebundle.properties", + "enhanceWith": [ + { + "bundleUrl": "myfolder1/i18n.properties", + "bundleUrlRelativeTo": "manifest", + "terminologies": { + "sports": { + "bundleUrl": "myfolder1/soccer.properties", + "bundleUrlRelativeTo": "manifest", + "supportedLocales": [ + "", + "de", + "en" + ] + }, + "travel": { + "bundleUrl": "myfolder1/vehicles.properties", + "bundleUrlRelativeTo": "manifest", + "supportedLocales": [ + "", + "de", + "en" + ] + } + }, + "supportedLocales": [ + "", + "en" + ] + }, + { + "bundleUrl": "myfolder2/i18n.properties", + "bundleUrlRelativeTo": "manifest", + "terminologies": { + "travel": { + "bundleUrl": "myfolder2/bicycles.properties", + "bundleUrlRelativeTo": "manifest", "supportedLocales": [ - "", - "de", - "en" - ], - "terminologies": { - "sports": { - "bundleUrl": "sports.properties", - "bundleUrlRelativeTo": "manifest", - "supportedLocales": [ - "", - "en", - "de" - ] - }, - "travel": { - "bundleUrl": "travel.properties", - "bundleUrlRelativeTo": "manifest", - "supportedLocales": [ - "", - "en", - "de" - ] - } - } + "", + "de", + "en" + ] + } }, - "enhanceWith": [ - { - "bundleUrl": "myfolder1/i18n.properties", - "bundleUrlRelativeTo": "manifest", - "supportedLocales": [ - "", - "en", - "de" - ], - "terminologies": { - "sports": { - "bundleUrl": "myfolder1/soccer.properties", - "bundleUrlRelativeTo": "manifest", - "supportedLocales": [ - "", - "en", - "de" - ] - }, - "travel": { - "bundleUrl": "myfolder1/vehicles.properties", - "bundleUrlRelativeTo": "manifest", - "supportedLocales": [ - "", - "en", - "de" - ] - } - } - }, - { - "bundleUrl": "myfolder2/i18n.properties", - "bundleUrlRelativeTo": "manifest", - "supportedLocales": [ - "", - "en", - "de" - ], - "terminologies": { - "travel": { - "bundleUrl": "myfolder2/bicycles.properties", - "bundleUrlRelativeTo": "manifest", - "supportedLocales": [ - "", - "en", - "de" - ] - } - } - } + "supportedLocales": [ + "", + "en" ] - } + } + ], + "supportedLocales": [ + "", + "de", + "en" + ] + } } + } } \ No newline at end of file diff --git a/test/fixtures/application.m/package.json b/test/fixtures/application.m/package.json new file mode 100644 index 000000000..d70e686e8 --- /dev/null +++ b/test/fixtures/application.m/package.json @@ -0,0 +1,8 @@ +{ + "name": "application.m", + "version": "1.0.0", + "description": "Simple SAPUI5 based application", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +} diff --git a/test/fixtures/application.m/ui5.yaml b/test/fixtures/application.m/ui5.yaml new file mode 100644 index 000000000..e6739d0ec --- /dev/null +++ b/test/fixtures/application.m/ui5.yaml @@ -0,0 +1,5 @@ +--- +specVersion: "3.2" +type: application +metadata: + name: application.m diff --git a/test/fixtures/application.m/webapp/i18n/i18n.properties b/test/fixtures/application.m/webapp/i18n/i18n.properties new file mode 100644 index 000000000..4fa9396ef --- /dev/null +++ b/test/fixtures/application.m/webapp/i18n/i18n.properties @@ -0,0 +1 @@ +welcome=Hello world \ No newline at end of file diff --git a/test/fixtures/application.m/webapp/i18n/i18n_en.properties b/test/fixtures/application.m/webapp/i18n/i18n_en.properties new file mode 100644 index 000000000..f03a373b0 --- /dev/null +++ b/test/fixtures/application.m/webapp/i18n/i18n_en.properties @@ -0,0 +1 @@ +welcome=Hello EN world \ No newline at end of file diff --git a/test/fixtures/application.m/webapp/i18n/i18n_en_US.properties b/test/fixtures/application.m/webapp/i18n/i18n_en_US.properties new file mode 100644 index 000000000..60d20479d --- /dev/null +++ b/test/fixtures/application.m/webapp/i18n/i18n_en_US.properties @@ -0,0 +1 @@ +welcome=Hello EN US world \ No newline at end of file diff --git a/test/fixtures/application.m/webapp/i18n/i18n_en_US_sapprc.properties b/test/fixtures/application.m/webapp/i18n/i18n_en_US_sapprc.properties new file mode 100644 index 000000000..2376090d4 --- /dev/null +++ b/test/fixtures/application.m/webapp/i18n/i18n_en_US_sapprc.properties @@ -0,0 +1 @@ +welcome=Hello EN US sapprc world \ No newline at end of file diff --git a/test/fixtures/application.m/webapp/index.html b/test/fixtures/application.m/webapp/index.html new file mode 100644 index 000000000..fd6a73c97 --- /dev/null +++ b/test/fixtures/application.m/webapp/index.html @@ -0,0 +1,11 @@ + + + + Application M + + + + + + \ No newline at end of file diff --git a/test/fixtures/application.m/webapp/manifest.json b/test/fixtures/application.m/webapp/manifest.json new file mode 100644 index 000000000..dd4efb090 --- /dev/null +++ b/test/fixtures/application.m/webapp/manifest.json @@ -0,0 +1,21 @@ +{ + "_version": "1.22.0", + "sap.app": { + "id": "application.m", + "type": "application", + "applicationVersion": { + "version": "1.0.0" + }, + "title": "{{title}}" + }, + "sap.ui5": { + "models": { + "i18n": { + "type": "sap.ui.model.resource.ResourceModel", + "settings": { + "bundleName": "application.m.i18n.i18n" + } + } + } + } +} \ No newline at end of file diff --git a/test/fixtures/application.m/webapp/test.js b/test/fixtures/application.m/webapp/test.js new file mode 100644 index 000000000..399a1b6a1 --- /dev/null +++ b/test/fixtures/application.m/webapp/test.js @@ -0,0 +1,8 @@ +sap.ui.define([ +], () => { + test((paramA) => { + const variableA = paramA; + console.log(variableA); + }) + test(); +}); diff --git a/test/lib/builder/builder.js b/test/lib/builder/builder.js index 9bc4c8c60..dd7675361 100644 --- a/test/lib/builder/builder.js +++ b/test/lib/builder/builder.js @@ -27,6 +27,7 @@ const applicationJPath = path.join(__dirname, "..", "..", "fixtures", "applicati const applicationKPath = path.join(__dirname, "..", "..", "fixtures", "application.k"); const applicationLPath = path.join(__dirname, "..", "..", "fixtures", "application.l"); const applicationØPath = path.join(__dirname, "..", "..", "fixtures", "application.ø"); +const applicationMPath = path.join(__dirname, "..", "..", "fixtures", "application.m"); const collectionPath = path.join(__dirname, "..", "..", "fixtures", "collection"); const libraryDPath = path.join(__dirname, "..", "..", "fixtures", "library.d"); const libraryEPath = path.join(__dirname, "..", "..", "fixtures", "library.e"); @@ -1276,7 +1277,7 @@ test.serial("Build theme-library with CSS variables and theme designer resources t.pass(); }); -test.serial.only("Build library.n with terminologies and supportedLocales", async (t) => { +test.serial("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"); @@ -1296,6 +1297,26 @@ test.serial.only("Build library.n with terminologies and supportedLocales", asyn t.pass(); }); +test.serial("Build application.m with terminologies and supportedLocales", async (t) => { + const destPath = path.join("test", "tmp", "build", "application.m", "dest"); + const expectedPath = path.join("test", "expected", "build", "application.m", "dest"); + + const graph = await graphFromPackageDependencies({ + cwd: applicationMPath + }); + graph.setTaskRepository(taskRepository); + await graph.build({ + destPath + }); + + const expectedFiles = await findFiles(expectedPath); + // Check for all directories and files + directoryDeepEqual(t, destPath, expectedPath); + // Check for all file contents + await checkFileContentsIgnoreLineFeeds(t, expectedFiles, expectedPath, destPath); + t.pass(); +}); + const libraryDTree = { "id": "library.d", "version": "1.0.0", diff --git a/test/lib/processors/manifestTransformer.js b/test/lib/processors/manifestTransformer.js index fb38e2e3d..5c23645ab 100644 --- a/test/lib/processors/manifestTransformer.js +++ b/test/lib/processors/manifestTransformer.js @@ -22,6 +22,25 @@ test.afterEach.always((t) => { sinon.restore(); }); + +function createResource(path, bNamespaced, input, fnOnSetString) { + return { + getString: () => Promise.resolve(input), + setString: fnOnSetString, + getProject() { + return { + getNamespace() { + const namespace = path.substring(0, path.lastIndexOf("/") + 1).replace("/resources/", ""); + return bNamespaced ? namespace : ""; + } + }; + }, + getPath() { + return path; + } + }; +} + // ####################################################### // Type: Application // ####################################################### @@ -37,12 +56,8 @@ test.serial("Application: No replacement at all", async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -86,12 +101,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -136,12 +147,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -202,12 +209,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -249,12 +252,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -295,12 +294,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -359,12 +354,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -426,12 +417,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -472,12 +459,8 @@ test.serial("Application: sap.ui5/models: Log verbose if manifest version is not } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -517,12 +500,8 @@ test.serial("Application: sap.ui5/models: Log verbose if manifest version is bel } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -569,12 +548,8 @@ test.serial("Library: No replacement at all", async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -605,12 +580,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -653,12 +624,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -711,12 +678,8 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with available } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -767,12 +730,8 @@ async (t) => { } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], @@ -805,12 +764,8 @@ test.serial("Library: sap.ui5/library: Do not replace supportedLocales with disa } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: () => { - t.fail("setString should never be called because resource should not be changed"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.fail("setString should never be called because resource should not be changed")); const processedResources = await manifestTransformer({ resources: [resource], @@ -872,18 +827,14 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with terminolog } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], fs: { readdir: sinon.stub().callsFake((fsPath, callback) => { - if (fsPath && fsPath.endsWith("i18nc_sports/")) { + if (fsPath && fsPath.endsWith("i18nc_sports")) { return callback(null, [ "messagebundle.sports_de.properties", "messagebundle.sports_en.properties", @@ -952,18 +903,14 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with terminolog } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], fs: { readdir: sinon.stub().callsFake((fsPath, callback) => { - if (fsPath && fsPath.endsWith("i18nc_sports/")) { + if (fsPath && fsPath.endsWith("i18nc_sports")) { return callback(null, [ "messagebundle.sports_de.properties", "messagebundle.sports_en.properties", @@ -1028,18 +975,14 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with deactivate } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], fs: { readdir: sinon.stub().callsFake((fsPath, callback) => { - if (fsPath && fsPath.endsWith("i18nc_sports/")) { + if (fsPath && fsPath.endsWith("i18nc_sports")) { t.fail("Should never be called"); } else { return callback(null, [ @@ -1110,24 +1053,20 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], fs: { readdir: sinon.stub().callsFake((fsPath, callback) => { - if (fsPath && fsPath.endsWith("myfolder1/")) { + if (fsPath && fsPath.endsWith("myfolder1")) { return callback(null, [ "messagebundlenc1_de.properties", "messagebundlenc1_en.properties", "messagebundlenc1.properties" ]); - } else if (fsPath && fsPath.endsWith("myfolder2/")) { + } else if (fsPath && fsPath.endsWith("myfolder2")) { return callback(null, [ "messagebundlenc2_de.properties", "messagebundlenc2_en.properties", @@ -1235,42 +1174,38 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit } }, null, 2); - const resource = { - getString: () => Promise.resolve(input), - setString: (actual) => { - t.deepEqual(actual, expected, "Correct file content should be set"); - } - }; + const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input, + (actual) => t.deepEqual(actual, expected, "Correct file content should be set")); const processedResources = await manifestTransformer({ resources: [resource], fs: { readdir: sinon.stub().callsFake((fsPath, callback) => { - if (fsPath && fsPath.endsWith("myfolder1/")) { + if (fsPath && fsPath.endsWith("myfolder1")) { return callback(null, [ "messagebundlenc1_de.properties", "messagebundlenc1_en.properties", "messagebundlenc1.properties" ]); - } else if (fsPath && fsPath.endsWith("myfolder2/")) { + } else if (fsPath && fsPath.endsWith("myfolder2")) { return callback(null, [ "messagebundlenc2_de.properties", "messagebundlenc2_en.properties", "messagebundlenc2.properties" ]); - } else if (fsPath && fsPath.endsWith("i18nc_sports/")) { + } else if (fsPath && fsPath.endsWith("i18nc_sports")) { return callback(null, [ "messagebundle.sports_de.properties", "messagebundle.sports_en.properties", "messagebundle.sports.properties" ]); - } else if (fsPath && fsPath.endsWith("i18nc_sports_soccer/")) { + } else if (fsPath && fsPath.endsWith("i18nc_sports_soccer")) { return callback(null, [ "messagebundle.soccer_de.properties", "messagebundle.soccer_en.properties", "messagebundle.soccer.properties" ]); - } else if (fsPath && fsPath.endsWith("i18nc_sports_soccer_el/")) { + } else if (fsPath && fsPath.endsWith("i18nc_sports_soccer_el")) { return callback(null, [ "messagebundle.elsoccer_de.properties", "messagebundle.elsoccer_en.properties",