@sap-ux/ui5-application-writer 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -29,4 +29,5 @@ declare function isTypescriptEnabled(basePath: string, fs?: Editor): Promise<boo
29
29
  declare function enableTypescript(basePath: string, fs?: Editor): Promise<Editor>;
30
30
  export { Ui5App, generate, enableTypescript, isTypescriptEnabled };
31
31
  export { App, Package, UI5, AppOptions };
32
+ export { compareUI5VersionGte, ui5LtsVersion_1_120, ui5LtsVersion_1_71, processDestinationPath, getTemplateVersionPath } from './utils';
32
33
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTemplateVersionPath = exports.processDestinationPath = exports.ui5LtsVersion_1_71 = exports.ui5LtsVersion_1_120 = exports.compareUI5VersionGte = void 0;
3
4
  exports.generate = generate;
4
5
  exports.enableTypescript = enableTypescript;
5
6
  exports.isTypescriptEnabled = isTypescriptEnabled;
@@ -135,4 +136,10 @@ async function enableTypescript(basePath, fs) {
135
136
  fs.write(ui5ConfigPath, ui5Config.toString());
136
137
  return fs;
137
138
  }
139
+ var utils_1 = require("./utils");
140
+ Object.defineProperty(exports, "compareUI5VersionGte", { enumerable: true, get: function () { return utils_1.compareUI5VersionGte; } });
141
+ Object.defineProperty(exports, "ui5LtsVersion_1_120", { enumerable: true, get: function () { return utils_1.ui5LtsVersion_1_120; } });
142
+ Object.defineProperty(exports, "ui5LtsVersion_1_71", { enumerable: true, get: function () { return utils_1.ui5LtsVersion_1_71; } });
143
+ Object.defineProperty(exports, "processDestinationPath", { enumerable: true, get: function () { return utils_1.processDestinationPath; } });
144
+ Object.defineProperty(exports, "getTemplateVersionPath", { enumerable: true, get: function () { return utils_1.getTemplateVersionPath; } });
138
145
  //# sourceMappingURL=index.js.map
package/dist/options.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
- import type { Ui5App } from './types';
2
+ import type { UI5, Ui5App } from './types';
3
3
  import type { UI5Config } from '@sap-ux/ui5-config';
4
4
  import type { ProjectType } from '@sap-ux/project-access';
5
5
  /**
@@ -12,6 +12,7 @@ export interface FeatureInput {
12
12
  baseComponent?: string;
13
13
  projectType?: ProjectType;
14
14
  };
15
+ ui5?: Partial<UI5>;
15
16
  };
16
17
  fs: Editor;
17
18
  basePath: string;
package/dist/options.js CHANGED
@@ -9,6 +9,7 @@ const ejs_1 = require("ejs");
9
9
  const project_access_1 = require("@sap-ux/project-access");
10
10
  const ui5Libs_1 = require("./data/ui5Libs");
11
11
  const ui5_config_1 = require("@sap-ux/ui5-config");
12
+ const utils_1 = require("./utils");
12
13
  /**
13
14
  * Copy all template files into the target project.
14
15
  *
@@ -20,7 +21,11 @@ const ui5_config_1 = require("@sap-ux/ui5-config");
20
21
  * @param input.tmplPath template basepath
21
22
  */
22
23
  async function copyTemplates(name, { ui5App, fs, basePath, tmplPath }) {
23
- const optTmplDirPath = (0, path_1.join)(tmplPath, 'optional', `${name}`);
24
+ let optTmplDirPath = (0, path_1.join)(tmplPath, 'optional', `${name}`);
25
+ const optionPath = (0, utils_1.getTemplateVersionPath)(ui5App.ui5);
26
+ if (name === 'loadReuseLibs') {
27
+ optTmplDirPath = (0, path_1.join)(optTmplDirPath, optionPath);
28
+ }
24
29
  const optTmplFilePaths = await (0, project_access_1.getFilePaths)(optTmplDirPath);
25
30
  optTmplFilePaths.forEach((optTmplFilePath) => {
26
31
  const relPath = optTmplFilePath.replace(optTmplDirPath, '');
@@ -28,7 +33,8 @@ async function copyTemplates(name, { ui5App, fs, basePath, tmplPath }) {
28
33
  // Extend or add
29
34
  if (!fs.exists(outPath)) {
30
35
  fs.copyTpl(optTmplFilePath, outPath, ui5App, undefined, {
31
- globOptions: { dot: true }
36
+ globOptions: { dot: true },
37
+ processDestinationPath: utils_1.processDestinationPath
32
38
  });
33
39
  }
34
40
  else {
@@ -0,0 +1,26 @@
1
+ import { type UI5 } from './types';
2
+ export declare const ui5LtsVersion_1_71 = "1.71.0";
3
+ export declare const ui5LtsVersion_1_120 = "1.120.0";
4
+ /**
5
+ * Compares two UI5 versions to determine if the first is greater than or equal to the second.
6
+ *
7
+ * @param {string} ui5VersionA - The first UI5 version to compare.
8
+ * @param {string} ui5VersionB - The second UI5 version to compare.
9
+ * @returns {boolean} - True if the first version is greater than or equal to the second, false otherwise.
10
+ */
11
+ export declare function compareUI5VersionGte(ui5VersionA: string, ui5VersionB: string): boolean;
12
+ /**
13
+ * Gets the template version path based on the UI5 version and template type.
14
+ *
15
+ * @param {UI5} ui5 - The UI5 configuration.
16
+ * @returns {string} - The template version path.
17
+ */
18
+ export declare function getTemplateVersionPath(ui5: UI5): string;
19
+ /**
20
+ * Processes the destination path by removing specific version segments.
21
+ *
22
+ * @param {string} filePath - The file path to process.
23
+ * @returns {string} - The processed file path.
24
+ */
25
+ export declare function processDestinationPath(filePath: string): string;
26
+ //# sourceMappingURL=utils.d.ts.map
package/dist/utils.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ui5LtsVersion_1_120 = exports.ui5LtsVersion_1_71 = void 0;
4
+ exports.compareUI5VersionGte = compareUI5VersionGte;
5
+ exports.getTemplateVersionPath = getTemplateVersionPath;
6
+ exports.processDestinationPath = processDestinationPath;
7
+ const semver_1 = require("semver");
8
+ exports.ui5LtsVersion_1_71 = '1.71.0';
9
+ exports.ui5LtsVersion_1_120 = '1.120.0';
10
+ /**
11
+ * Compares two UI5 versions to determine if the first is greater than or equal to the second.
12
+ *
13
+ * @param {string} ui5VersionA - The first UI5 version to compare.
14
+ * @param {string} ui5VersionB - The second UI5 version to compare.
15
+ * @returns {boolean} - True if the first version is greater than or equal to the second, false otherwise.
16
+ */
17
+ function compareUI5VersionGte(ui5VersionA, ui5VersionB) {
18
+ if (ui5VersionA === '') {
19
+ // latest version
20
+ return true;
21
+ }
22
+ else {
23
+ return (0, semver_1.gte)(ui5VersionA, ui5VersionB, { loose: true });
24
+ }
25
+ }
26
+ /**
27
+ * Gets the template version path based on the UI5 version and template type.
28
+ *
29
+ * @param {UI5} ui5 - The UI5 configuration.
30
+ * @returns {string} - The template version path.
31
+ */
32
+ function getTemplateVersionPath(ui5) {
33
+ let templateVersionPath = '';
34
+ const ui5Version = ui5?.minUI5Version ?? ui5?.version ?? '';
35
+ if (ui5Version && compareUI5VersionGte(ui5Version, exports.ui5LtsVersion_1_120)) {
36
+ templateVersionPath = exports.ui5LtsVersion_1_120;
37
+ }
38
+ else {
39
+ templateVersionPath = exports.ui5LtsVersion_1_71;
40
+ }
41
+ return templateVersionPath;
42
+ }
43
+ /**
44
+ * Processes the destination path by removing specific version segments.
45
+ *
46
+ * @param {string} filePath - The file path to process.
47
+ * @returns {string} - The processed file path.
48
+ */
49
+ function processDestinationPath(filePath) {
50
+ return filePath.replace('/1.120.0', '').replace('/1.71.0', '');
51
+ }
52
+ //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aui5-application-writer"
11
11
  },
12
- "version": "1.2.1",
12
+ "version": "1.2.2",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -38,7 +38,7 @@
38
38
  "@types/semver": "7.5.2",
39
39
  "fs-extra": "10.0.0",
40
40
  "@sap-ux/eslint-plugin-fiori-tools": "0.5.0",
41
- "@sap-ux/project-access": "1.28.2"
41
+ "@sap-ux/project-access": "1.28.4"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=18.x"
@@ -0,0 +1,267 @@
1
+ (function (sap) {
2
+ var fioriToolsGetManifestLibs = function (manifestPath) {
3
+ var url = manifestPath;
4
+ var result = "";
5
+ // SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
6
+ var ui5Libs = [
7
+ "sap.apf",
8
+ "sap.base",
9
+ "sap.chart",
10
+ "sap.collaboration",
11
+ "sap.f",
12
+ "sap.fe",
13
+ "sap.fileviewer",
14
+ "sap.gantt",
15
+ "sap.landvisz",
16
+ "sap.m",
17
+ "sap.ndc",
18
+ "sap.ovp",
19
+ "sap.rules",
20
+ "sap.suite",
21
+ "sap.tnt",
22
+ "sap.ui",
23
+ "sap.uiext",
24
+ "sap.ushell",
25
+ "sap.uxap",
26
+ "sap.viz",
27
+ "sap.webanalytics",
28
+ "sap.zen"
29
+ ];
30
+ var getKeys = function (libOrComp, libOrCompKeysString) {
31
+ var libOrCompKeysStringTmp = libOrCompKeysString;
32
+ Object.keys(libOrComp).forEach(function (libOrCompKey) {
33
+ // ignore libs or Components that start with SAPUI5 delivered namespaces
34
+ if (!ui5Libs.some(function (substring) { return libOrCompKey === substring || libOrCompKey.startsWith(substring + "."); })) {
35
+ if (libOrCompKeysStringTmp.length > 0) {
36
+ libOrCompKeysStringTmp = libOrCompKeysStringTmp + "," + libOrCompKey;
37
+ } else {
38
+ libOrCompKeysStringTmp = libOrCompKey;
39
+ }
40
+ }
41
+ });
42
+ return libOrCompKeysStringTmp;
43
+ }
44
+ var getComponentUsageNames = function (compUsages, libOrCompKeysString) {
45
+ var libOrCompKeysStringTmp = libOrCompKeysString;
46
+ var compNames = Object.keys(compUsages).map(function (compUsageKey) {
47
+ return compUsages[compUsageKey].name;
48
+ });
49
+ compNames.forEach(function (compName) {
50
+ // ignore libs or Components that start with SAPUI5 delivered namespaces
51
+ if (!ui5Libs.some(function (substring) { return compName === substring || compName.startsWith(substring + "."); })) {
52
+ if (libOrCompKeysStringTmp.length > 0) {
53
+ libOrCompKeysStringTmp = libOrCompKeysStringTmp + "," + compName;
54
+ } else {
55
+ libOrCompKeysStringTmp = compName;
56
+ }
57
+ }
58
+ });
59
+ return libOrCompKeysStringTmp;
60
+ }
61
+ return new Promise(function (resolve, reject) {
62
+
63
+ sap.ui.require(["sap/ui/thirdparty/jquery"], function (localJQuery) {
64
+ localJQuery.ajax(url)
65
+ .done(function (manifest) {
66
+ if (manifest) {
67
+ if (
68
+ manifest["sap.ui5"] &&
69
+ manifest["sap.ui5"].dependencies
70
+ ) {
71
+ if (manifest["sap.ui5"].dependencies.libs) {
72
+ result = getKeys(manifest["sap.ui5"].dependencies.libs, result);
73
+ }
74
+ if (manifest["sap.ui5"].dependencies.components) {
75
+ result = getKeys(manifest["sap.ui5"].dependencies.components, result);
76
+ }
77
+ }
78
+ if (
79
+ manifest["sap.ui5"] &&
80
+ manifest["sap.ui5"].componentUsages
81
+ ) {
82
+ result = getComponentUsageNames(manifest["sap.ui5"].componentUsages, result);
83
+ }
84
+ }
85
+ resolve(result);
86
+ })
87
+ .fail(function () {
88
+ reject(new Error("Could not fetch manifest at '" + manifestPath));
89
+ });
90
+ });
91
+ });
92
+ };
93
+ var registerModules = function (dataFromAppIndex) {
94
+ Object.keys(dataFromAppIndex).forEach(function (moduleDefinitionKey) {
95
+ var moduleDefinition = dataFromAppIndex[moduleDefinitionKey];
96
+ if (moduleDefinition && moduleDefinition.dependencies) {
97
+ moduleDefinition.dependencies.forEach(function (dependency) {
98
+ if (dependency.url && dependency.url.length > 0 && dependency.type === "UI5LIB") {
99
+ sap.ui.require(["sap/base/Log"], function (Log) {
100
+ Log.info("Registering Library " +
101
+ dependency.componentId +
102
+ " from server " +
103
+ dependency.url);
104
+ });
105
+ var compId = dependency.componentId.replace(/\./g, "/");
106
+ var config = {
107
+ paths: {
108
+ }
109
+ };
110
+ config.paths[compId] = dependency.url;
111
+ sap.ui.loader.config(config);
112
+ }
113
+ });
114
+ }
115
+ });
116
+ }
117
+ /**
118
+ * Registers the module paths for dependencies of the given component.
119
+ * @param {string} manifestPath The the path to the app manifest path
120
+ * for which the dependencies should be registered.
121
+ * @returns {Promise} A promise which is resolved when the ajax request for
122
+ * the app-index was successful and the module paths were registered.
123
+ */
124
+ var registerComponentDependencyPaths = function (manifestPath) {
125
+
126
+ return fioriToolsGetManifestLibs(manifestPath).then(function (libs) {
127
+ if (libs && libs.length > 0) {
128
+ var url = "/sap/bc/ui2/app_index/ui5_app_info?id=" + libs;
129
+ var sapClient = "";
130
+
131
+ return new Promise(
132
+ function (resolve) {
133
+ sapClient = new URLSearchParams(window.location.search).get("sap-client");
134
+ if (sapClient && sapClient.length === 3) {
135
+ url = url + "&sap-client=" + sapClient;
136
+ }
137
+ resolve(url);
138
+ }).then(function (url2) {
139
+ sap.ui.require(["sap/ui/thirdparty/jquery"], function (localJQuery) {
140
+ return localJQuery.ajax(url2)
141
+ .done(function (data) {
142
+ if (data) {
143
+ registerModules(data);
144
+ }
145
+ });
146
+ });
147
+ });
148
+ } else {
149
+ return undefined;
150
+ }
151
+ });
152
+ };
153
+
154
+ var registerSAPFonts = function () {
155
+ sap.ui.require(["sap/ui/core/IconPool"], function (IconPool) {
156
+ //Fiori Theme font family and URI
157
+ var fioriTheme = {
158
+ fontFamily: "SAP-icons-TNT",
159
+ fontURI: sap.ui.require.toUrl("sap/tnt/themes/base/fonts/")
160
+ };
161
+ //Registering to the icon pool
162
+ IconPool.registerFont(fioriTheme);
163
+ //SAP Business Suite Theme font family and URI
164
+ var bSuiteTheme = {
165
+ fontFamily: "BusinessSuiteInAppSymbols",
166
+ fontURI: sap.ui.require.toUrl("sap/ushell/themes/base/fonts/")
167
+ };
168
+ //Registering to the icon pool
169
+ IconPool.registerFont(bSuiteTheme);
170
+ });
171
+ }
172
+
173
+ /*eslint-disable fiori-custom/sap-browser-api-warning, fiori-custom/sap-no-dom-access*/
174
+ var currentScript = document.getElementById("locate-reuse-libs");
175
+ if (!currentScript) {
176
+ currentScript = document.currentScript;
177
+ }
178
+ var manifestUri = currentScript.getAttribute("data-sap-ui-manifest-uri");
179
+ var componentName = currentScript.getAttribute("data-sap-ui-componentName");
180
+ var useMockserver = currentScript.getAttribute("data-sap-ui-use-mockserver");
181
+
182
+ // Patch (KW): resourceRoot is needed to load the correct ResourceBundles
183
+ var resourceRoot = manifestUri.substring(0, manifestUri.lastIndexOf('/')+1);
184
+
185
+
186
+ return registerComponentDependencyPaths(manifestUri)
187
+ .catch(function (error) {
188
+ sap.ui.require(["sap/base/Log"], function (Log) {
189
+ Log.error(error);
190
+ });
191
+ })
192
+ .finally(function () {
193
+
194
+ // setting the app title with internationalization
195
+ sap.ui.require(["sap/ui/core/Core"], async function(Core) {
196
+ Core.ready(() => {
197
+ sap.ui.require(["sap/base/i18n/Localization"], function (Localization) {
198
+ sap.ui.require(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) {
199
+ var oResourceBundle = ResourceBundle.create({
200
+ // Patch (KW): resourceRoot is needed to load the correct ResourceBundles
201
+ url: resourceRoot + "i18n/i18n.properties",
202
+ locale: Localization.getLanguage()
203
+ });
204
+ document.title = oResourceBundle.getText("appTitle");
205
+ });
206
+ });
207
+ });
208
+ });
209
+
210
+ if (componentName && componentName.length > 0) {
211
+ if (useMockserver && useMockserver === "true") {
212
+ sap.ui.require(["sap/ui/core/Core"], async function(Core) {
213
+ Core.ready(() => {
214
+ registerSAPFonts();
215
+ sap.ui.require([componentName.replace(/\./g, "/") + "/localService/mockserver"], function (server) {
216
+ // set up test service for local testing
217
+ server.init();
218
+ // initialize the ushell sandbox component
219
+ sap.ui.require(["sap/ushell/Container"], async function (Container) {
220
+ Container.createRenderer(true).then(function (component) {
221
+ component.placeAt("content");
222
+ });
223
+ });
224
+ });
225
+ });
226
+ });
227
+ } else {
228
+ // Requiring the ComponentSupport module automatically executes the component initialisation for all declaratively defined components
229
+ sap.ui.require(["sap/ui/core/ComponentSupport"]);
230
+
231
+ // setting the app title with the i18n text
232
+ sap.ui.require(["sap/ui/core/Core"], async function(Core) {
233
+ Core.ready(() => {
234
+ registerSAPFonts();
235
+ sap.ui.require(["sap/base/i18n/Localization"], function (Localization) {
236
+ sap.ui.require(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) {
237
+ var oResourceBundle = ResourceBundle.create({
238
+ // Patch (KW): resourceRoot is needed to load the correct ResourceBundles
239
+ url: resourceRoot + "i18n/i18n.properties",
240
+ locale: Localization.getLanguage()
241
+ });
242
+ document.title = oResourceBundle.getText("appTitle");
243
+ });
244
+ });
245
+ });
246
+ });
247
+ }
248
+ } else {
249
+ sap.ui.require(["sap/ui/core/Core"], async function(Core) {
250
+ Core.ready(() => {
251
+ registerSAPFonts();
252
+ // initialize the ushell sandbox component
253
+ sap.ui.require(["sap/ushell/Container"], async function (Container) {
254
+ try {
255
+ Container.createRenderer(true).then(function (component) {
256
+ component.placeAt("content");
257
+ });
258
+ } catch (error) {
259
+ // support older versions of ui5
260
+ Container.createRenderer().placeAt("content");
261
+ }
262
+ });
263
+ });
264
+ });
265
+ }
266
+ });
267
+ })(sap);