@sap-ux/ui5-application-writer 0.19.1 → 0.19.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/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": "0.19.1",
12
+ "version": "0.19.2",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -1,6 +1,7 @@
1
- /*eslint-disable semi, no-console*/
2
1
  (function (sap) {
3
- var getKeys = function (libOrComp, libOrCompKeysString) {
2
+ var fioriToolsGetManifestLibs = function (manifestPath) {
3
+ var url = manifestPath;
4
+ var result = "";
4
5
  // SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
5
6
  var ui5Libs = [
6
7
  "sap.apf",
@@ -26,72 +27,73 @@
26
27
  "sap.webanalytics",
27
28
  "sap.zen"
28
29
  ];
29
- Object.keys(libOrComp).forEach(function (libOrCompKey) {
30
- // ignore libs or Components that start with SAPUI5 delivered namespaces
31
- if (
32
- !ui5Libs.some(function (substring) {
33
- return libOrCompKey === substring || libOrCompKey.startsWith(substring + ".");
34
- })
35
- ) {
36
- if (libOrCompKeysString.length > 0) {
37
- libOrCompKeysString = libOrCompKeysString + "," + libOrCompKey;
38
- } else {
39
- libOrCompKeysString = libOrCompKey;
40
- }
41
- }
42
- });
43
- return libOrCompKeysString;
44
- };
45
-
46
- var updateManifest = function (manifest) {
47
- var result = "";
48
- if (manifest) {
49
- if (manifest["sap.ui5"] && manifest["sap.ui5"].dependencies) {
50
- if (manifest["sap.ui5"].dependencies.libs) {
51
- result = getKeys(manifest["sap.ui5"].dependencies.libs, result);
52
- }
53
- if (manifest["sap.ui5"].dependencies.components) {
54
- result = getKeys(manifest["sap.ui5"].dependencies.components, result);
30
+ function getKeys(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
+ }
55
40
  }
56
- }
57
- if (manifest["sap.ui5"] && manifest["sap.ui5"].componentUsages) {
58
- result = getKeys(manifest["sap.ui5"].componentUsages, result);
59
- }
41
+ });
42
+ return libOrCompKeysStringTmp;
60
43
  }
61
- return result;
62
- };
63
-
64
- var fioriToolsGetManifestLibs = function (manifestPath) {
65
- var url = manifestPath;
66
44
  return new Promise(function (resolve, reject) {
67
45
  $.ajax(url)
68
46
  .done(function (manifest) {
69
- resolve(updateManifest(manifest));
47
+ if (manifest) {
48
+ if (
49
+ manifest["sap.ui5"] &&
50
+ manifest["sap.ui5"].dependencies
51
+ ) {
52
+ if (manifest["sap.ui5"].dependencies.libs) {
53
+ result = getKeys(manifest["sap.ui5"].dependencies.libs, result);
54
+ }
55
+ if (manifest["sap.ui5"].dependencies.components) {
56
+ result = getKeys(manifest["sap.ui5"].dependencies.components, result);
57
+ }
58
+ }
59
+ if (
60
+ manifest["sap.ui5"] &&
61
+ manifest["sap.ui5"].componentUsages
62
+ ) {
63
+ result = getKeys(manifest["sap.ui5"].componentUsages, result);
64
+ }
65
+ }
66
+ resolve(result);
70
67
  })
71
- .fail(function () {
68
+ .fail(function (error) {
72
69
  reject(new Error("Could not fetch manifest at '" + manifestPath));
73
70
  });
74
71
  });
75
72
  };
76
-
77
- var updateModuleDefinition = function (data) {
78
- if (data) {
79
- Object.keys(data).forEach(function (moduleDefinitionKey) {
80
- var moduleDefinition = data[moduleDefinitionKey];
81
- if (moduleDefinition && moduleDefinition.dependencies) {
82
- moduleDefinition.dependencies.forEach(function (dependency) {
83
- if (dependency.url && dependency.url.length > 0 && dependency.type === "UI5LIB") {
84
- jQuery.sap.log.info(
85
- "Registering Library " + dependency.componentId + " from server " + dependency.url
86
- );
87
- jQuery.sap.registerModulePath(dependency.componentId, dependency.url);
88
- }
89
- });
90
- }
91
- });
92
- }
93
- };
94
-
73
+ function registerModules(dataFromAppIndex) {
74
+ Object.keys(dataFromAppIndex).forEach(function (moduleDefinitionKey) {
75
+ var moduleDefinition = dataFromAppIndex[moduleDefinitionKey];
76
+ if (moduleDefinition && moduleDefinition.dependencies) {
77
+ moduleDefinition.dependencies.forEach(function (dependency) {
78
+ if (dependency.url && dependency.url.length > 0 && dependency.type === "UI5LIB") {
79
+ sap.ui.require(["sap/base/Log"], function (Log) {
80
+ Log.info("Registering Library " +
81
+ dependency.componentId +
82
+ " from server " +
83
+ dependency.url);
84
+ });
85
+ var compId = dependency.componentId.replace(/\./g, "/");
86
+ var config = {
87
+ paths: {
88
+ }
89
+ };
90
+ config.paths[compId] = dependency.url;
91
+ sap.ui.loader.config(config);
92
+ }
93
+ });
94
+ }
95
+ });
96
+ }
95
97
  /**
96
98
  * Registers the module paths for dependencies of the given component.
97
99
  * @param {string} manifestPath The the path to the app manifest path
@@ -100,22 +102,36 @@
100
102
  * the app-index was successful and the module paths were registered.
101
103
  */
102
104
  sap.registerComponentDependencyPaths = function (manifestPath) {
103
- /*eslint-disable semi, consistent-return*/
105
+
104
106
  return fioriToolsGetManifestLibs(manifestPath).then(function (libs) {
105
107
  if (libs && libs.length > 0) {
106
108
  var url = "/sap/bc/ui2/app_index/ui5_app_info?id=" + libs;
107
- var sapClient = jQuery.sap.getUriParameters().get("sap-client");
108
- if (sapClient && sapClient.length === 3) {
109
- url = url + "&sap-client=" + sapClient;
110
- }
111
- return $.ajax(url).done(updateModuleDefinition);
109
+ var sapClient = "";
110
+
111
+ return new Promise(
112
+ function (resolve) {
113
+ sap.ui.require(["sap/base/util/UriParameters"], function (UriParameters) {
114
+ sapClient = UriParameters.fromQuery(window.location.search).get("sap-client");
115
+ if (sapClient && sapClient.length === 3) {
116
+ url = url + "&sap-client=" + sapClient;
117
+ }
118
+ resolve(url);
119
+ });
120
+ }).then(function (url2) {
121
+ return $.ajax(url2).done(function (data) {
122
+ if (data) {
123
+ registerModules(data);
124
+ }
125
+ });
126
+ });
127
+ } else {
128
+ return undefined;
112
129
  }
113
130
  });
114
131
  };
115
132
  })(sap);
116
133
 
117
134
  /*eslint-disable sap-browser-api-warning, sap-no-dom-access*/
118
- var scripts = document.getElementsByTagName("script");
119
135
  var currentScript = document.getElementById("locate-reuse-libs");
120
136
  if (!currentScript) {
121
137
  currentScript = document.currentScript;
@@ -123,22 +139,26 @@ if (!currentScript) {
123
139
  var manifestUri = currentScript.getAttribute("data-sap-ui-manifest-uri");
124
140
  var componentName = currentScript.getAttribute("data-sap-ui-componentName");
125
141
  var useMockserver = currentScript.getAttribute("data-sap-ui-use-mockserver");
126
- var bundleResources = function () {
127
- jQuery.sap.require("jquery.sap.resources");
128
- var sLocale = sap.ui.getCore().getConfiguration().getLanguage();
129
- var oBundle = jQuery.sap.resources({
130
- url: "i18n/i18n.properties",
131
- locale: sLocale
132
- });
133
- document.title = oBundle.getText("appTitle");
134
- };
142
+
135
143
  sap.registerComponentDependencyPaths(manifestUri)
136
144
  .catch(function (error) {
137
- jQuery.sap.log.error(error);
145
+ sap.ui.require(["sap/base/Log"], function (Log) {
146
+ Log.error(error);
147
+ });
138
148
  })
139
149
  .finally(function () {
140
- // setting the app title with internationalization
141
- sap.ui.getCore().attachInit(bundleResources);
150
+
151
+ // setting the app title with internationalization
152
+ sap.ui.getCore().attachInit(function () {
153
+ var sLocale = sap.ui.getCore().getConfiguration().getLanguage();
154
+ sap.ui.require(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) {
155
+ var oResourceBundle = ResourceBundle.create({
156
+ url: "i18n/i18n.properties",
157
+ locale: sLocale
158
+ });
159
+ document.title = oResourceBundle.getText("appTitle");
160
+ });
161
+ });
142
162
 
143
163
  if (componentName && componentName.length > 0) {
144
164
  if (useMockserver && useMockserver === "true") {
@@ -154,8 +174,17 @@ sap.registerComponentDependencyPaths(manifestUri)
154
174
  // Requiring the ComponentSupport module automatically executes the component initialisation for all declaratively defined components
155
175
  sap.ui.require(["sap/ui/core/ComponentSupport"]);
156
176
 
157
- // setting the app title with the i18n text
158
- sap.ui.getCore().attachInit(bundleResources);
177
+ // setting the app title with the i18n text
178
+ sap.ui.getCore().attachInit(function () {
179
+ var sLocale = sap.ui.getCore().getConfiguration().getLanguage();
180
+ sap.ui.require(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) {
181
+ var oResourceBundle = ResourceBundle.create({
182
+ url: "i18n/i18n.properties",
183
+ locale: sLocale
184
+ });
185
+ document.title = oResourceBundle.getText("appTitle");
186
+ });
187
+ });
159
188
  }
160
189
  } else {
161
190
  sap.ui.getCore().attachInit(function () {
@@ -163,6 +192,4 @@ sap.registerComponentDependencyPaths(manifestUri)
163
192
  sap.ushell.Container.createRenderer().placeAt("content");
164
193
  });
165
194
  }
166
- });
167
-
168
- sap.registerComponentDependencyPaths(manifestUri);
195
+ });