@sap-ux/preview-middleware 0.1.0
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/LICENSE +201 -0
- package/README.md +61 -0
- package/dist/base/flex.d.ts +43 -0
- package/dist/base/flex.js +96 -0
- package/dist/base/flp.d.ts +79 -0
- package/dist/base/flp.js +215 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.js +3 -0
- package/dist/ui5/middleware.d.ts +2 -0
- package/dist/ui5/middleware.js +63 -0
- package/package.json +56 -0
- package/templates/flp/sandbox.html +90 -0
- package/templates/flp/workspaceConnector.js +76 -0
- package/ui5.yaml +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# `@sap-ux/preview-middleware`
|
|
2
|
+
|
|
3
|
+
The `@sap-ux/preview-middleware` is a [Custom UI5 Server Middleware](https://sap.github.io/ui5-tooling/pages/extensibility/CustomServerMiddleware) for previewing an application in a local Fiori launchpad . It can be used either with the `ui5 serve` or the `fiori run` commands.
|
|
4
|
+
|
|
5
|
+
## Configuration Options
|
|
6
|
+
| Option | Type | Default Value | Description |
|
|
7
|
+
| ------------ | ------| ------------- | ----------- |
|
|
8
|
+
| `flp` | | |Optional configuration object for the local Fiori launchpad |
|
|
9
|
+
| `flp.path` | `string` | `/test/flp.html` | The mount point of the local Fiori launchpad. |
|
|
10
|
+
| `flp.apps` | `array` | `[]` | Optional additional local apps that are available in local Fiori launchpad |
|
|
11
|
+
| `debug` | `boolean` | false | Enables debug output |
|
|
12
|
+
|
|
13
|
+
### `flp.apps`
|
|
14
|
+
Array of additional application configurations:
|
|
15
|
+
| Option | Type | Default Value | Description |
|
|
16
|
+
| ------------ | ------| ------------- | ----------- |
|
|
17
|
+
| `target` | `string` | | Target path of the additional application |
|
|
18
|
+
| `local` | `string` | | Local path to the folder containing the application |
|
|
19
|
+
| `intent` | | | Optional intent to be used for the application |
|
|
20
|
+
| `intent.object` | `string` | `(calculated)`| Optional intent object, if it is not provided then it will be calculated based on the application id |
|
|
21
|
+
| `intent.action` | `string` | `preview` | Optional intent action |
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
The middleware can be used without configuration. However, since the middleware intercepts a few requests that might otherwise be handled by a different middleware, it is strongly recommended to run other file serving middlewares after the `preview-middleware` e.g. `backend-proxy-middleware` and `ui5-proxy-middleware` (and the corresponding middlewares in the `@sap/ux-ui5-tooling`).
|
|
25
|
+
Example: [./test/fixtures/simple-app/ui5.yaml](./test/fixtures/simple-app/ui5.yaml)
|
|
26
|
+
|
|
27
|
+
### Minimal Configuration
|
|
28
|
+
With no configuration provided, the app will be local FLP will be available at `/test/flp.html` and the log level is `info`.
|
|
29
|
+
```Yaml
|
|
30
|
+
server:
|
|
31
|
+
customMiddleware:
|
|
32
|
+
- name: preview-middleware
|
|
33
|
+
afterMiddleware: compression
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Different Path and Debugging enabled
|
|
37
|
+
With this configuration, the app will be local FLP will be available at `/preview.html` and the log level is `debug`.
|
|
38
|
+
```Yaml
|
|
39
|
+
server:
|
|
40
|
+
customMiddleware:
|
|
41
|
+
- name: preview-middleware
|
|
42
|
+
afterMiddleware: compression
|
|
43
|
+
configuration:
|
|
44
|
+
flp:
|
|
45
|
+
path: /preview.html
|
|
46
|
+
debug: true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Additional Applications
|
|
50
|
+
If you want to test cross application navigation, then you can add additional applications into the local FLP.
|
|
51
|
+
With this configuration, an application that is locally available in `../local-folder` will be available at `/apps/other-app` and will also be added as tile to the local FLP.
|
|
52
|
+
```Yaml
|
|
53
|
+
server:
|
|
54
|
+
customMiddleware:
|
|
55
|
+
- name: preview-middleware
|
|
56
|
+
afterMiddleware: compression
|
|
57
|
+
configuration:
|
|
58
|
+
apps:
|
|
59
|
+
- local: ../local-folder
|
|
60
|
+
target: /apps/other-app
|
|
61
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Logger } from '@sap-ux/logger';
|
|
2
|
+
import type { ReaderCollection } from '@ui5/fs';
|
|
3
|
+
/**
|
|
4
|
+
* Read changes from the file system and return them.
|
|
5
|
+
*
|
|
6
|
+
* @param project reference to the UI5 project
|
|
7
|
+
* @param logger logger instance
|
|
8
|
+
* @returns object with the file name as key and the file content as value
|
|
9
|
+
*/
|
|
10
|
+
export declare function readChanges(project: ReaderCollection, logger: Logger): Promise<Record<string, unknown>>;
|
|
11
|
+
/**
|
|
12
|
+
* Writes flex changes to the user's workspace.
|
|
13
|
+
*
|
|
14
|
+
* @param data JS object to be stored as change
|
|
15
|
+
* @param data.fileName file name that is required for a valid change
|
|
16
|
+
* @param data.fileType file type that is required
|
|
17
|
+
* @param webappPath path to the webapp folder
|
|
18
|
+
* @param logger logger instance
|
|
19
|
+
* @returns object with success flag and optional message
|
|
20
|
+
*/
|
|
21
|
+
export declare function writeChange(data: object & {
|
|
22
|
+
fileName?: string;
|
|
23
|
+
fileType?: string;
|
|
24
|
+
}, webappPath: string, logger: Logger): {
|
|
25
|
+
success: boolean;
|
|
26
|
+
message?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Deletes an existing flex change from the file system if it exists.
|
|
30
|
+
*
|
|
31
|
+
* @param data JS object of the change to be deleted
|
|
32
|
+
* @param data.fileName file name that is required for a valid change
|
|
33
|
+
* @param webappPath path to the webapp folder
|
|
34
|
+
* @param logger logger instance
|
|
35
|
+
* @returns object with success flag and optional message
|
|
36
|
+
*/
|
|
37
|
+
export declare function deleteChange(data: object & {
|
|
38
|
+
fileName?: string;
|
|
39
|
+
}, webappPath: string, logger: Logger): {
|
|
40
|
+
success: boolean;
|
|
41
|
+
message?: string;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=flex.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.deleteChange = exports.writeChange = exports.readChanges = void 0;
|
|
13
|
+
const fs_1 = require("fs");
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
/**
|
|
16
|
+
* Read changes from the file system and return them.
|
|
17
|
+
*
|
|
18
|
+
* @param project reference to the UI5 project
|
|
19
|
+
* @param logger logger instance
|
|
20
|
+
* @returns object with the file name as key and the file content as value
|
|
21
|
+
*/
|
|
22
|
+
function readChanges(project, logger) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const changes = {};
|
|
25
|
+
const files = yield project.byGlob('/**/changes/*.*');
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
try {
|
|
28
|
+
changes[`sap.ui.fl.${(0, path_1.parse)(file.getName()).name}`] = JSON.parse(yield file.getString());
|
|
29
|
+
logger.debug(`Read change from ${file.getPath()}`);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logger.warn(error.message);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return changes;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.readChanges = readChanges;
|
|
39
|
+
/**
|
|
40
|
+
* Writes flex changes to the user's workspace.
|
|
41
|
+
*
|
|
42
|
+
* @param data JS object to be stored as change
|
|
43
|
+
* @param data.fileName file name that is required for a valid change
|
|
44
|
+
* @param data.fileType file type that is required
|
|
45
|
+
* @param webappPath path to the webapp folder
|
|
46
|
+
* @param logger logger instance
|
|
47
|
+
* @returns object with success flag and optional message
|
|
48
|
+
*/
|
|
49
|
+
function writeChange(data, webappPath, logger) {
|
|
50
|
+
const fileName = data.fileName;
|
|
51
|
+
const fileType = data.fileType;
|
|
52
|
+
if (fileName && fileType) {
|
|
53
|
+
logger.debug(`Write change ${fileName}.${fileType}`);
|
|
54
|
+
const path = (0, path_1.join)(webappPath, 'changes');
|
|
55
|
+
if (!(0, fs_1.existsSync)(path)) {
|
|
56
|
+
(0, fs_1.mkdirSync)(path);
|
|
57
|
+
}
|
|
58
|
+
const filePath = (0, path_1.join)(path, fileName + '.' + fileType);
|
|
59
|
+
(0, fs_1.writeFileSync)(filePath, JSON.stringify(data, null, 2));
|
|
60
|
+
const message = `FILE_CREATED ${fileName}.${fileType}`;
|
|
61
|
+
return { success: true, message };
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return { success: false };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.writeChange = writeChange;
|
|
68
|
+
/**
|
|
69
|
+
* Deletes an existing flex change from the file system if it exists.
|
|
70
|
+
*
|
|
71
|
+
* @param data JS object of the change to be deleted
|
|
72
|
+
* @param data.fileName file name that is required for a valid change
|
|
73
|
+
* @param webappPath path to the webapp folder
|
|
74
|
+
* @param logger logger instance
|
|
75
|
+
* @returns object with success flag and optional message
|
|
76
|
+
*/
|
|
77
|
+
function deleteChange(data, webappPath, logger) {
|
|
78
|
+
var _a;
|
|
79
|
+
const fileName = (_a = data.fileName) === null || _a === void 0 ? void 0 : _a.replace('sap.ui.fl.', '');
|
|
80
|
+
if (fileName) {
|
|
81
|
+
const path = (0, path_1.join)(webappPath, 'changes');
|
|
82
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
83
|
+
const files = (0, fs_1.readdirSync)(path);
|
|
84
|
+
const file = files.find((element) => element.includes(fileName));
|
|
85
|
+
if (file) {
|
|
86
|
+
logger.debug(`Write change ${file}`);
|
|
87
|
+
const filePath = (0, path_1.join)(path, file);
|
|
88
|
+
(0, fs_1.unlinkSync)(filePath);
|
|
89
|
+
return { success: true, message: `FILE_DELETED ${file}` };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { success: false };
|
|
94
|
+
}
|
|
95
|
+
exports.deleteChange = deleteChange;
|
|
96
|
+
//# sourceMappingURL=flex.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ReaderCollection } from '@ui5/fs';
|
|
2
|
+
import type { App, FlpConfig } from '../types';
|
|
3
|
+
import type { Logger } from '@sap-ux/logger';
|
|
4
|
+
import type { MiddlewareUtils } from '@ui5/server';
|
|
5
|
+
import type { Manifest, UI5FlexLayer } from '@sap-ux/project-access';
|
|
6
|
+
/**
|
|
7
|
+
* Internal structure used to fill the sandbox.html template
|
|
8
|
+
*/
|
|
9
|
+
export interface TemplateConfig {
|
|
10
|
+
apps: Record<string, {
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
additionalInformation: string;
|
|
14
|
+
applicationType: 'URL';
|
|
15
|
+
url: string;
|
|
16
|
+
}>;
|
|
17
|
+
ui5: {
|
|
18
|
+
libs: string;
|
|
19
|
+
theme: string;
|
|
20
|
+
flex: {
|
|
21
|
+
applyConnector: string;
|
|
22
|
+
writeConnector: string;
|
|
23
|
+
custom: boolean;
|
|
24
|
+
}[];
|
|
25
|
+
resources: Record<string, string>;
|
|
26
|
+
};
|
|
27
|
+
flex?: {
|
|
28
|
+
layer: UI5FlexLayer;
|
|
29
|
+
developerMode: boolean;
|
|
30
|
+
};
|
|
31
|
+
locateReuseLibsScript?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Class handling preview of a sandbox FLP.
|
|
35
|
+
*/
|
|
36
|
+
export declare class FlpSandbox {
|
|
37
|
+
private readonly project;
|
|
38
|
+
private readonly utils;
|
|
39
|
+
private readonly logger;
|
|
40
|
+
protected templateConfig: TemplateConfig;
|
|
41
|
+
protected readonly config: FlpConfig;
|
|
42
|
+
readonly router: any;
|
|
43
|
+
/**
|
|
44
|
+
* Constructor setting defaults and keeping reference to workspace resources.
|
|
45
|
+
*
|
|
46
|
+
* @param config configuration from the ui5.yaml
|
|
47
|
+
* @param project reference to the project provided by the UI5 CLI
|
|
48
|
+
* @param utils middleware utilities provided by the UI5 CLI
|
|
49
|
+
* @param logger logger instance
|
|
50
|
+
*/
|
|
51
|
+
constructor(config: Partial<FlpConfig>, project: ReaderCollection, utils: MiddlewareUtils, logger: Logger);
|
|
52
|
+
/**
|
|
53
|
+
* Initialize the FLP sandbox router.
|
|
54
|
+
*
|
|
55
|
+
* @param manifest application manifest
|
|
56
|
+
*/
|
|
57
|
+
init(manifest: Manifest): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Try finding the locate-reuse-libs script.
|
|
60
|
+
*
|
|
61
|
+
* @returns the location of the locate-reuse-libs script or undefined.
|
|
62
|
+
*/
|
|
63
|
+
private findLocateReuseLibsScript;
|
|
64
|
+
private addRoutesForAdditionalApps;
|
|
65
|
+
/**
|
|
66
|
+
* Create required routes for flex.
|
|
67
|
+
*
|
|
68
|
+
* @returns template configuration for flex.
|
|
69
|
+
*/
|
|
70
|
+
private createFlexHandler;
|
|
71
|
+
/**
|
|
72
|
+
* Add an application to the local FLP preview.
|
|
73
|
+
*
|
|
74
|
+
* @param manifest manifest of the additional target app
|
|
75
|
+
* @param app configuration for the preview
|
|
76
|
+
*/
|
|
77
|
+
addApp(manifest: Manifest, app: App): void;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=flp.d.ts.map
|
package/dist/base/flp.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FlpSandbox = void 0;
|
|
13
|
+
const ejs_1 = require("ejs");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const express_1 = require("express");
|
|
17
|
+
const flex_1 = require("./flex");
|
|
18
|
+
/**
|
|
19
|
+
* Default theme
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_THEME = 'sap_horizon';
|
|
22
|
+
/**
|
|
23
|
+
* Default path for mounting the local FLP.
|
|
24
|
+
*/
|
|
25
|
+
const DEFAULT_PATH = '/test/flp.html';
|
|
26
|
+
/**
|
|
27
|
+
* Class handling preview of a sandbox FLP.
|
|
28
|
+
*/
|
|
29
|
+
class FlpSandbox {
|
|
30
|
+
/**
|
|
31
|
+
* Constructor setting defaults and keeping reference to workspace resources.
|
|
32
|
+
*
|
|
33
|
+
* @param config configuration from the ui5.yaml
|
|
34
|
+
* @param project reference to the project provided by the UI5 CLI
|
|
35
|
+
* @param utils middleware utilities provided by the UI5 CLI
|
|
36
|
+
* @param logger logger instance
|
|
37
|
+
*/
|
|
38
|
+
constructor(config, project, utils, logger) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
this.project = project;
|
|
41
|
+
this.utils = utils;
|
|
42
|
+
this.logger = logger;
|
|
43
|
+
this.config = {
|
|
44
|
+
path: (_a = config.path) !== null && _a !== void 0 ? _a : DEFAULT_PATH,
|
|
45
|
+
apps: (_b = config.apps) !== null && _b !== void 0 ? _b : [],
|
|
46
|
+
rta: config.rta
|
|
47
|
+
};
|
|
48
|
+
logger.debug(`Config: ${JSON.stringify(this.config)}`);
|
|
49
|
+
this.router = (0, express_1.Router)();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Initialize the FLP sandbox router.
|
|
53
|
+
*
|
|
54
|
+
* @param manifest application manifest
|
|
55
|
+
*/
|
|
56
|
+
init(manifest) {
|
|
57
|
+
var _a, _b, _c, _d, _e;
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const flex = this.createFlexHandler();
|
|
60
|
+
const supportedThemes = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.supportedThemes) !== null && _b !== void 0 ? _b : [DEFAULT_THEME];
|
|
61
|
+
this.templateConfig = {
|
|
62
|
+
apps: {},
|
|
63
|
+
ui5: {
|
|
64
|
+
libs: Object.keys((_e = (_d = (_c = manifest['sap.ui5']) === null || _c === void 0 ? void 0 : _c.dependencies) === null || _d === void 0 ? void 0 : _d.libs) !== null && _e !== void 0 ? _e : {}).join(','),
|
|
65
|
+
theme: supportedThemes.includes(DEFAULT_THEME) ? DEFAULT_THEME : supportedThemes[0],
|
|
66
|
+
flex,
|
|
67
|
+
resources: {}
|
|
68
|
+
},
|
|
69
|
+
locateReuseLibsScript: yield this.findLocateReuseLibsScript()
|
|
70
|
+
};
|
|
71
|
+
this.addApp(manifest, {
|
|
72
|
+
target: '/',
|
|
73
|
+
local: '.',
|
|
74
|
+
intent: {
|
|
75
|
+
object: 'app',
|
|
76
|
+
action: 'preview'
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// add route for the sandbox.html
|
|
80
|
+
this.router.get(this.config.path, (req, res) => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const config = Object.assign({}, this.templateConfig);
|
|
83
|
+
if (req.query['fiori-tools-rta-mode']) {
|
|
84
|
+
if ((_a = this.config.rta) === null || _a === void 0 ? void 0 : _a.layer) {
|
|
85
|
+
config.flex = {
|
|
86
|
+
layer: (_b = this.config.rta) === null || _b === void 0 ? void 0 : _b.layer,
|
|
87
|
+
developerMode: false
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.logger.error('Fiori tools RTA mode could not be started because the RTA layer is missing.');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const template = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/flp/sandbox.html'), 'utf-8');
|
|
95
|
+
const html = (0, ejs_1.render)(template, config);
|
|
96
|
+
// if livereload is enabled, don't send it but let other middleware modify the content
|
|
97
|
+
if (res._livereload) {
|
|
98
|
+
res.write(html);
|
|
99
|
+
res.end();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
res.status(200).contentType('html').send(html);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
this.addRoutesForAdditionalApps();
|
|
106
|
+
this.logger.info(`Initialized for app ${manifest['sap.app'].id}`);
|
|
107
|
+
this.logger.debug(`Configured apps: ${JSON.stringify(this.templateConfig.apps)}`);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Try finding the locate-reuse-libs script.
|
|
112
|
+
*
|
|
113
|
+
* @returns the location of the locate-reuse-libs script or undefined.
|
|
114
|
+
*/
|
|
115
|
+
findLocateReuseLibsScript() {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const files = yield this.project.byGlob('**/locate-reuse-libs.js');
|
|
118
|
+
if (files.length > 0) {
|
|
119
|
+
return files[0].getPath();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
addRoutesForAdditionalApps() {
|
|
127
|
+
for (const app of this.config.apps) {
|
|
128
|
+
if (app.local) {
|
|
129
|
+
const manifest = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(app.local, 'webapp/manifest.json'), 'utf-8'));
|
|
130
|
+
this.addApp(manifest, app);
|
|
131
|
+
this.router.use(app.target, (0, express_1.static)((0, path_1.join)(app.local, 'webapp')));
|
|
132
|
+
this.logger.info(`Serving additional application at ${app.target} from ${app.local}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create required routes for flex.
|
|
138
|
+
*
|
|
139
|
+
* @returns template configuration for flex.
|
|
140
|
+
*/
|
|
141
|
+
createFlexHandler() {
|
|
142
|
+
const workspaceConnectorPath = '/preview/WorkspaceConnector';
|
|
143
|
+
this.router.get(`/resources${workspaceConnectorPath}.js`, (_req, res) => {
|
|
144
|
+
res.status(200)
|
|
145
|
+
.contentType('text/javascript')
|
|
146
|
+
.send((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/flp/workspaceConnector.js'), 'utf-8'));
|
|
147
|
+
});
|
|
148
|
+
const api = '/preview/api/changes';
|
|
149
|
+
this.router.use(api, (0, express_1.json)());
|
|
150
|
+
this.router.get(api, (_req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
res.status(200)
|
|
152
|
+
.contentType('application/json')
|
|
153
|
+
.send(yield (0, flex_1.readChanges)(this.project, this.logger));
|
|
154
|
+
}));
|
|
155
|
+
this.router.post(api, (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
try {
|
|
157
|
+
const { success, message } = (0, flex_1.writeChange)(req.body, this.utils.getProject().getSourcePath(), this.logger);
|
|
158
|
+
if (success) {
|
|
159
|
+
res.status(200).send(message);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
res.status(400).send('INVALID_DATA');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
res.status(500).send(error.message);
|
|
167
|
+
}
|
|
168
|
+
}));
|
|
169
|
+
this.router.delete(api, (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
try {
|
|
171
|
+
const { success, message } = (0, flex_1.deleteChange)(req.body, this.utils.getProject().getSourcePath(), this.logger);
|
|
172
|
+
if (success) {
|
|
173
|
+
res.status(200).send(message);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
res.status(400).send('INVALID_DATA');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
res.status(500).send(error.message);
|
|
181
|
+
}
|
|
182
|
+
}));
|
|
183
|
+
return [
|
|
184
|
+
{
|
|
185
|
+
applyConnector: workspaceConnectorPath,
|
|
186
|
+
writeConnector: workspaceConnectorPath,
|
|
187
|
+
custom: true
|
|
188
|
+
}
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Add an application to the local FLP preview.
|
|
193
|
+
*
|
|
194
|
+
* @param manifest manifest of the additional target app
|
|
195
|
+
* @param app configuration for the preview
|
|
196
|
+
*/
|
|
197
|
+
addApp(manifest, app) {
|
|
198
|
+
var _a, _b, _c, _d, _e;
|
|
199
|
+
const id = manifest['sap.app'].id;
|
|
200
|
+
(_a = app.intent) !== null && _a !== void 0 ? _a : (app.intent = {
|
|
201
|
+
object: id.replace(/\./g, ''),
|
|
202
|
+
action: 'preview'
|
|
203
|
+
});
|
|
204
|
+
this.templateConfig.ui5.resources[id] = app.target;
|
|
205
|
+
this.templateConfig.apps[`${(_b = app.intent) === null || _b === void 0 ? void 0 : _b.object}-${(_c = app.intent) === null || _c === void 0 ? void 0 : _c.action}`] = {
|
|
206
|
+
title: (_d = manifest['sap.app'].title) !== null && _d !== void 0 ? _d : id,
|
|
207
|
+
description: (_e = manifest['sap.app'].description) !== null && _e !== void 0 ? _e : '',
|
|
208
|
+
additionalInformation: `SAPUI5.Component=${id}`,
|
|
209
|
+
applicationType: 'URL',
|
|
210
|
+
url: app.target
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.FlpSandbox = FlpSandbox;
|
|
215
|
+
//# sourceMappingURL=flp.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ui5/middleware"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { UI5FlexLayer } from '@sap-ux/project-access';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for additional applications
|
|
4
|
+
*/
|
|
5
|
+
export interface App {
|
|
6
|
+
target: string;
|
|
7
|
+
local: string;
|
|
8
|
+
intent?: {
|
|
9
|
+
object: string;
|
|
10
|
+
action: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* FLP preview configuration.
|
|
15
|
+
*/
|
|
16
|
+
export interface FlpConfig {
|
|
17
|
+
path: string;
|
|
18
|
+
rta?: {
|
|
19
|
+
layer?: UI5FlexLayer;
|
|
20
|
+
};
|
|
21
|
+
apps: App[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Middleware configuration.
|
|
25
|
+
*/
|
|
26
|
+
export interface Config {
|
|
27
|
+
flp?: Partial<FlpConfig>;
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const logger_1 = require("@sap-ux/logger");
|
|
13
|
+
const flp_1 = require("../base/flp");
|
|
14
|
+
/**
|
|
15
|
+
* Create the router that is to be exposed as UI5 middleware.
|
|
16
|
+
*
|
|
17
|
+
* @param param0 parameters provider by UI5
|
|
18
|
+
* @param param0.resources reference to resources
|
|
19
|
+
* @param param0.options options and configurations from the ui5.yaml
|
|
20
|
+
* @param param0.middlewareUtil additional UI5 CLI utilities
|
|
21
|
+
* @param logger logger instance
|
|
22
|
+
* @returns a router
|
|
23
|
+
*/
|
|
24
|
+
function createRouter({ resources, options, middlewareUtil }, logger) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
// setting defaults
|
|
28
|
+
const config = (_a = options.configuration) !== null && _a !== void 0 ? _a : {};
|
|
29
|
+
(_b = config.flp) !== null && _b !== void 0 ? _b : (config.flp = {});
|
|
30
|
+
// configure the FLP sandbox based on information from the manifest
|
|
31
|
+
const flp = new flp_1.FlpSandbox(config.flp, resources.rootProject, middlewareUtil, logger);
|
|
32
|
+
const files = yield resources.rootProject.byGlob('/manifest.json');
|
|
33
|
+
if (files.length === 1) {
|
|
34
|
+
yield flp.init(JSON.parse(yield files[0].getString()));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error('No manifest.json found.');
|
|
38
|
+
}
|
|
39
|
+
return flp.router;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Exporting the middleware for usage in the UI5 tooling.
|
|
44
|
+
*
|
|
45
|
+
* @param params middleware configuration
|
|
46
|
+
* @returns a promise for the request handler
|
|
47
|
+
*/
|
|
48
|
+
module.exports = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
var _a;
|
|
50
|
+
const logger = new logger_1.ToolsLogger({
|
|
51
|
+
transports: [new logger_1.UI5ToolingTransport({ moduleName: 'preview-middleware' })],
|
|
52
|
+
logLevel: ((_a = params.options.configuration) === null || _a === void 0 ? void 0 : _a.debug) ? logger_1.LogLevel.Debug : logger_1.LogLevel.Info
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
return yield createRouter(params, logger);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error('Could not start preview-middleware.');
|
|
59
|
+
logger.error(error.message);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=middleware.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sap-ux/preview-middleware",
|
|
3
|
+
"description": "Preview middleware",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
7
|
+
"directory": "packages/preview-middleware"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apreview-middleware"
|
|
11
|
+
},
|
|
12
|
+
"version": "0.1.0",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"author": "@SAP/ux-tools-team",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"dist",
|
|
19
|
+
"templates",
|
|
20
|
+
"ui5.yaml",
|
|
21
|
+
"!dist/*.map",
|
|
22
|
+
"!dist/**/*.map"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"ejs": "3.1.7",
|
|
26
|
+
"@sap-ux/logger": "0.3.7"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/ejs": "3.1.0",
|
|
30
|
+
"@types/express": "4.17.13",
|
|
31
|
+
"@types/supertest": "2.0.12",
|
|
32
|
+
"express": "4.18.2",
|
|
33
|
+
"supertest": "6.3.2",
|
|
34
|
+
"@sap-ux/project-access": "1.10.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"express": "4"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"pnpm": ">=6.26.1 < 7.0.0 || >=7.1.0",
|
|
41
|
+
"node": ">= 14.16.0 < 15.0.0 || >=16.1.0 < 17.0.0 || >=18.0.0 < 19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"start:fixture": "ui5 serve --config test/fixtures/simple-app/ui5.yaml",
|
|
45
|
+
"build": "tsc --build",
|
|
46
|
+
"watch": "tsc --watch",
|
|
47
|
+
"clean": "rimraf dist test/test-output coverage *.tsbuildinfo",
|
|
48
|
+
"format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
|
|
49
|
+
"lint": "eslint . --ext .ts",
|
|
50
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
51
|
+
"test": "jest --ci --forceExit --detectOpenHandles --colors",
|
|
52
|
+
"test-u": "jest --ci --forceExit --detectOpenHandles --colors -u",
|
|
53
|
+
"link": "pnpm link --global",
|
|
54
|
+
"unlink": "pnpm unlink --global"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<!-- Copyright (c) 2015 SAP AG, All Rights Reserved -->
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta charset="UTF-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
9
|
+
<title>Local FLP Sandbox</title>
|
|
10
|
+
|
|
11
|
+
<!-- Bootstrap the unified shell in sandbox mode for standalone usage.
|
|
12
|
+
|
|
13
|
+
The renderer is specified in the global Unified Shell configuration object "sap-ushell-config".
|
|
14
|
+
|
|
15
|
+
The fiori2 renderer will render the shell header allowing, for instance,
|
|
16
|
+
testing of additional application setting buttons.
|
|
17
|
+
|
|
18
|
+
The navigation target resolution service is configured in a way that the empty URL hash is
|
|
19
|
+
resolved to our own application.
|
|
20
|
+
|
|
21
|
+
This example uses relative path references for the SAPUI5 resources and test-resources;
|
|
22
|
+
it might be necessary to adapt them depending on the target runtime platform.
|
|
23
|
+
The sandbox platform is restricted to development or demo use cases and must NOT be used
|
|
24
|
+
for productive scenarios.
|
|
25
|
+
-->
|
|
26
|
+
<script type="text/javascript">
|
|
27
|
+
window["sap-ushell-config"] = {
|
|
28
|
+
defaultRenderer: "fiori2",
|
|
29
|
+
renderers: {
|
|
30
|
+
fiori2: {
|
|
31
|
+
componentData: {
|
|
32
|
+
config: {
|
|
33
|
+
search: "hidden",
|
|
34
|
+
enableSearch: false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
applications: <%- JSON.stringify(apps) %>
|
|
40
|
+
};
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<script src="/test-resources/sap/ushell/bootstrap/sandbox.js" id="sap-ushell-bootstrap"></script>
|
|
44
|
+
<!-- Bootstrap the UI5 core library. 'data-sap-ui-frameOptions="allow"'' is a NON-SECURE setting for test environments -->
|
|
45
|
+
<script id="sap-ui-bootstrap"
|
|
46
|
+
src="/resources/sap-ui-core.js"
|
|
47
|
+
data-sap-ui-libs="<%- ui5.libs %>"
|
|
48
|
+
data-sap-ui-async="true"
|
|
49
|
+
data-sap-ui-preload="async"
|
|
50
|
+
data-sap-ui-theme="<%- ui5.theme %>"
|
|
51
|
+
data-sap-ui-compatVersion="edge"
|
|
52
|
+
data-sap-ui-language="en"
|
|
53
|
+
data-sap-ui-flexibilityServices='<%- JSON.stringify(ui5.flex) %>'
|
|
54
|
+
data-sap-ui-resourceroots='<%- JSON.stringify(ui5.resources) %>'
|
|
55
|
+
data-sap-ui-frameOptions="allow"
|
|
56
|
+
data-sap-ui-xx-componentPreload="off">
|
|
57
|
+
</script><% if (locals.locateReuseLibsScript) { %>
|
|
58
|
+
<script id="locate-reuse-libs" src="<%- locateReuseLibsScript %>" data-sap-ui-manifest-uri="/manifest.json">
|
|
59
|
+
</script><% } %>
|
|
60
|
+
<script>
|
|
61
|
+
sap.ui.getCore().attachInit(function () {<% if (locals.flex) { %>
|
|
62
|
+
sap.ushell.Container.attachRendererCreatedEvent(function () {
|
|
63
|
+
sap.ushell.Container.getServiceAsync('AppLifeCycle').then((serviceInstance) => {
|
|
64
|
+
serviceInstance.attachAppLoaded((event) => {
|
|
65
|
+
var oView = event.getParameter('componentInstance');
|
|
66
|
+
sap.ui.require(["sap/ui/rta/api/startAdaptation"], async function (startAdaptation) {
|
|
67
|
+
var options = {
|
|
68
|
+
rootControl: oView,
|
|
69
|
+
validateAppVersion: false,
|
|
70
|
+
flexSettings: {
|
|
71
|
+
layer: '<%- flex.layer %>',
|
|
72
|
+
developerMode: <%- flex.developerMode %>
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
await startAdaptation(options);
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
});
|
|
79
|
+
});<% } %>
|
|
80
|
+
<% if (!locals.locateReuseLibsScript) { %>
|
|
81
|
+
sap.ushell.Container.createRenderer().placeAt("content");<% } %>
|
|
82
|
+
});
|
|
83
|
+
</script>
|
|
84
|
+
</head>
|
|
85
|
+
|
|
86
|
+
<!-- UI Content -->
|
|
87
|
+
<body class="sapUiBody" id="content">
|
|
88
|
+
</body>
|
|
89
|
+
|
|
90
|
+
</html>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
sap.ui.define(
|
|
2
|
+
[
|
|
3
|
+
'sap/base/util/merge',
|
|
4
|
+
'sap/ui/fl/write/api/connectors/ObjectStorageConnector',
|
|
5
|
+
'sap/ui/fl/Layer',
|
|
6
|
+
'sap/base/util/UriParameters'
|
|
7
|
+
],
|
|
8
|
+
function (merge, ObjectStorageConnector, Layer, UriParameters) {
|
|
9
|
+
'use strict';
|
|
10
|
+
var url = new URL(window.location.toString());
|
|
11
|
+
var uriParameters = UriParameters.fromURL(url.href);
|
|
12
|
+
var rtaMode = uriParameters.get('fiori-tools-rta-mode');
|
|
13
|
+
var generator =
|
|
14
|
+
rtaMode === 'forAdaptation'
|
|
15
|
+
? 'changeUtils: SAPFioriTools-propertyEditor'
|
|
16
|
+
: 'changeUtils: SAPFioriTools-variants';
|
|
17
|
+
var path = '/preview/api/changes';
|
|
18
|
+
var WorkspaceConnector = merge({}, ObjectStorageConnector, {
|
|
19
|
+
layers: [Layer.VENDOR, Layer.CUSTOMER_BASE],
|
|
20
|
+
storage: {
|
|
21
|
+
_itemsStoredAsObjects: true,
|
|
22
|
+
setItem: function (_sKey, vValue) {
|
|
23
|
+
// update generator
|
|
24
|
+
if (vValue && vValue.support) {
|
|
25
|
+
vValue.support.generator = generator;
|
|
26
|
+
}
|
|
27
|
+
$.ajax({
|
|
28
|
+
type: 'POST',
|
|
29
|
+
url: path,
|
|
30
|
+
data: JSON.stringify(vValue, null, 2),
|
|
31
|
+
contentType: 'application/json'
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
removeItem: function (sKey) {
|
|
35
|
+
$.ajax({
|
|
36
|
+
type: 'DELETE',
|
|
37
|
+
url: path,
|
|
38
|
+
data: JSON.stringify({ fileName: sKey }),
|
|
39
|
+
contentType: 'application/json'
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
clear: function () {
|
|
43
|
+
// not implemented
|
|
44
|
+
},
|
|
45
|
+
getItem: function (_sKey) {
|
|
46
|
+
// not implemented
|
|
47
|
+
},
|
|
48
|
+
getItems: async function () {
|
|
49
|
+
const changes = await $.ajax({
|
|
50
|
+
url: path,
|
|
51
|
+
type: 'GET',
|
|
52
|
+
cache: false,
|
|
53
|
+
dataType: 'json'
|
|
54
|
+
});
|
|
55
|
+
return changes;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
loadFeatures: function () {
|
|
59
|
+
return ObjectStorageConnector.loadFeatures().then(function (settings) {
|
|
60
|
+
const [majorVersion, minorVersion] = sap.ui.version.split('.').map((v) => parseInt(v, 10));
|
|
61
|
+
if (majorVersion >= 1 && minorVersion >= 90) {
|
|
62
|
+
settings.isVariantAdaptationEnabled = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (rtaMode === 'forAdaptation') {
|
|
66
|
+
settings.isVariantAdaptationEnabled = false;
|
|
67
|
+
}
|
|
68
|
+
return settings;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return WorkspaceConnector;
|
|
74
|
+
},
|
|
75
|
+
true
|
|
76
|
+
);
|