@ui5/task-adaptation 1.0.15 → 1.0.16
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/CHANGELOG.md +4 -4
- package/README.md +1 -1
- package/dist/annotationManager.d.ts +32 -0
- package/dist/annotationManager.js +276 -0
- package/dist/appVariantManager.js +18 -32
- package/dist/baseAppManager.d.ts +8 -4
- package/dist/baseAppManager.js +37 -62
- package/dist/buildStrategy.js +3 -0
- package/dist/bundle-resourceBundle.js +692 -0
- package/dist/bundle.js +245 -102
- package/dist/cache/annotationsCacheManager.d.ts +8 -0
- package/dist/cache/annotationsCacheManager.js +18 -0
- package/dist/cache/baseAppFilesCacheManager.d.ts +6 -0
- package/dist/cache/baseAppFilesCacheManager.js +15 -0
- package/dist/cache/cacheManager.d.ts +16 -0
- package/dist/cache/cacheManager.js +67 -0
- package/dist/index.js +10 -18
- package/dist/model/noAuthorizationProvidedError.d.ts +3 -0
- package/dist/model/noAuthorizationProvidedError.js +9 -0
- package/dist/model/types.d.ts +12 -0
- package/dist/processors/abapProcessor.d.ts +21 -0
- package/dist/processors/abapProcessor.js +36 -0
- package/dist/processors/cfProcessor.d.ts +17 -0
- package/dist/processors/cfProcessor.js +46 -0
- package/dist/processors/processor.d.ts +7 -0
- package/dist/processors/processor.js +36 -0
- package/dist/repositories/abapRepoManager.d.ts +13 -0
- package/dist/repositories/abapRepoManager.js +81 -0
- package/dist/{html5RepoManager.d.ts → repositories/html5RepoManager.d.ts} +2 -2
- package/dist/repositories/html5RepoManager.js +89 -0
- package/dist/util/cfUtil.js +109 -138
- package/dist/util/commonUtil.js +1 -1
- package/dist/util/requestUtil.d.ts +6 -3
- package/dist/util/requestUtil.js +43 -24
- package/dist/util/resourceUtil.d.ts +2 -10
- package/dist/util/resourceUtil.js +6 -49
- package/dist/util/zipUtil.d.ts +2 -0
- package/dist/util/zipUtil.js +20 -0
- package/package.json +8 -3
- package/scripts/bundler.ts +75 -0
- package/scripts/rollup/bundleDefinition-resourceBundle.js +5 -0
- package/scripts/rollup/overrides/sap/base/i18n/Localization.js +1 -0
- package/scripts/rollup/overrides/sap/base/string/formatMessage.js +1 -0
- package/scripts/rollup/overrides/sap/base/util/Properties.js +1 -0
- package/scripts/rollup/overrides/sap/base/util/merge.js +1 -0
- package/scripts/rollup/project/ui5.yaml +1 -1
- package/scripts/rollup.ts +26 -50
- package/dist/html5RepoManager.js +0 -113
- package/dist/updateCache.d.ts +0 -5
- package/dist/updateCache.js +0 -36
package/dist/util/cfUtil.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const CFLocal = require("@sap/cf-tools/out/src/cf-local");
|
|
13
4
|
const CFToolsCli = require("@sap/cf-tools/out/src/cli");
|
|
@@ -22,58 +13,51 @@ class CFUtil {
|
|
|
22
13
|
* @return {Promise<IServiceKeys>} promise with service keys
|
|
23
14
|
* @memberof CFUtil
|
|
24
15
|
*/
|
|
25
|
-
static getServiceInstanceKeys(getServiceInstanceParams, createServiceInstanceParams) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
serviceInstance: serviceInstances[0]
|
|
45
|
-
};
|
|
46
|
-
});
|
|
16
|
+
static async getServiceInstanceKeys(getServiceInstanceParams, createServiceInstanceParams) {
|
|
17
|
+
let serviceInstances = await this.getServiceInstance(getServiceInstanceParams);
|
|
18
|
+
if (!(serviceInstances?.length > 0) && createServiceInstanceParams) {
|
|
19
|
+
await this.createService(createServiceInstanceParams);
|
|
20
|
+
serviceInstances = await this.getServiceInstance(getServiceInstanceParams);
|
|
21
|
+
}
|
|
22
|
+
if (!(serviceInstances?.length > 0)) {
|
|
23
|
+
throw new Error(`Cannot find '${getServiceInstanceParams.names?.join(", ")}' service in current space: ${getServiceInstanceParams.spaceGuids?.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
// we can use any instance in the list to connect to HTML5 Repo
|
|
26
|
+
log.verbose(`Use '${serviceInstances[0].name}' HTML5 Repo Runtime service instance`);
|
|
27
|
+
const serviceKeys = await this.getOrCreateServiceKeys(serviceInstances[0]);
|
|
28
|
+
if (!(serviceKeys?.length > 0)) {
|
|
29
|
+
throw new Error(`Cannot get service keys for '${getServiceInstanceParams.names?.join(", ")}' service in current space: ${getServiceInstanceParams.spaceGuids?.join(", ")}`);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
credentials: serviceKeys[0].credentials,
|
|
33
|
+
serviceInstance: serviceInstances[0]
|
|
34
|
+
};
|
|
47
35
|
}
|
|
48
|
-
static createService(params) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
});
|
|
36
|
+
static async createService(params) {
|
|
37
|
+
log.verbose(`Creating a service instance with parameters: ${JSON.stringify(params)}`);
|
|
38
|
+
const resources = await this.requestCfApi(`/v3/service_plans?names=${params.planName}&space_guids=${params.spaceGuid}`);
|
|
39
|
+
const publicPlan = resources.find(resource => resource.visibility_type === "public");
|
|
40
|
+
if (!publicPlan) {
|
|
41
|
+
throw new Error(`Cannot find a public plan by name '${params.serviceName}' in space '${params.spaceGuid}'`);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await CFLocal.cfCreateService(publicPlan.guid, params.serviceName, params.parameters, params.tags);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error(`Cannot create a service instance '${params.serviceName}' in space '${params.spaceGuid}': ${error.message}`);
|
|
48
|
+
}
|
|
63
49
|
}
|
|
64
|
-
static getOrCreateServiceKeys(serviceInstance) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return this.getServiceKeys(serviceInstance.guid);
|
|
76
|
-
});
|
|
50
|
+
static async getOrCreateServiceKeys(serviceInstance) {
|
|
51
|
+
const credentials = await this.getServiceKeys(serviceInstance.guid);
|
|
52
|
+
if (credentials.length === 0) {
|
|
53
|
+
const serviceKeyName = serviceInstance.name + "_key";
|
|
54
|
+
log.info(`Creating service key '${serviceKeyName}' for service instance '${serviceInstance.name}'`);
|
|
55
|
+
await this.createServiceKey(serviceInstance.name, serviceKeyName);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return credentials;
|
|
59
|
+
}
|
|
60
|
+
return this.getServiceKeys(serviceInstance.guid);
|
|
77
61
|
}
|
|
78
62
|
static getServiceKeys(serviceInstanceGuid) {
|
|
79
63
|
return CFLocal.cfGetInstanceCredentials({
|
|
@@ -85,78 +69,68 @@ class CFUtil {
|
|
|
85
69
|
throw Error("Failed to get service credentials: " + error.message);
|
|
86
70
|
});
|
|
87
71
|
}
|
|
88
|
-
static createServiceKey(serviceInstanceName, serviceKeyName) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
});
|
|
72
|
+
static async createServiceKey(serviceInstanceName, serviceKeyName) {
|
|
73
|
+
try {
|
|
74
|
+
return this.cfExecute(["create-service-key", serviceInstanceName, serviceKeyName]);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new Error(`Couldn't create a service key for instance: ${serviceInstanceName}`);
|
|
78
|
+
}
|
|
97
79
|
}
|
|
98
|
-
static getServiceInstance(params) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}));
|
|
114
|
-
});
|
|
80
|
+
static async getServiceInstance(params) {
|
|
81
|
+
const PARAM_MAP = {
|
|
82
|
+
spaceGuids: "space_guids",
|
|
83
|
+
planNames: "service_plan_names",
|
|
84
|
+
names: "names"
|
|
85
|
+
};
|
|
86
|
+
const parameters = Object.entries(params)
|
|
87
|
+
.filter(([_, value]) => value?.length && value?.length > 0)
|
|
88
|
+
.map(([key, value]) => `${PARAM_MAP[key]}=${value?.join(",")}`);
|
|
89
|
+
const uri = `/v3/service_instances` + (parameters.length > 0 ? `?${parameters.join("&")}` : "");
|
|
90
|
+
const resources = await this.requestCfApi(uri);
|
|
91
|
+
return resources.map((service) => ({
|
|
92
|
+
name: service.name,
|
|
93
|
+
guid: service.guid
|
|
94
|
+
}));
|
|
115
95
|
}
|
|
116
|
-
static requestCfApi(url) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}))).then(resources => [].concat(...resources)));
|
|
131
|
-
}
|
|
132
|
-
return resources;
|
|
133
|
-
});
|
|
96
|
+
static async requestCfApi(url) {
|
|
97
|
+
const response = await this.cfExecute(["curl", url]);
|
|
98
|
+
const json = this.parseJson(response);
|
|
99
|
+
const resources = json?.resources;
|
|
100
|
+
const totalPages = json?.pagination?.total_pages;
|
|
101
|
+
if (totalPages > 1) {
|
|
102
|
+
const pages = Array.from({ length: totalPages - 1 }, (_, i) => i + 2);
|
|
103
|
+
return resources.concat(await Promise.all(pages.map(async (page) => {
|
|
104
|
+
const uri = `${url}${url.includes("?") ? "&" : "?"}page=${page}`;
|
|
105
|
+
const response = await this.cfExecute(["curl", uri]);
|
|
106
|
+
return this.parseJson(response)?.resources || [];
|
|
107
|
+
})).then(resources => [].concat(...resources)));
|
|
108
|
+
}
|
|
109
|
+
return resources;
|
|
134
110
|
}
|
|
135
111
|
static getOAuthToken() {
|
|
136
112
|
return this.cfExecute(["oauth-token"]);
|
|
137
113
|
}
|
|
138
|
-
static cfExecute(params) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
log.verbose(this.errorsToString(errorValues));
|
|
149
|
-
}
|
|
150
|
-
return response.stdout;
|
|
114
|
+
static async cfExecute(params) {
|
|
115
|
+
const MAX_ATTEMPTS = 3;
|
|
116
|
+
const errors = new Set();
|
|
117
|
+
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
118
|
+
try {
|
|
119
|
+
const response = await CFToolsCli.Cli.execute(params, { env: { "CF_COLOR": "false" } });
|
|
120
|
+
if (response.exitCode === 0) {
|
|
121
|
+
const errorValues = [...errors.values()];
|
|
122
|
+
if (errorValues?.length > 0) {
|
|
123
|
+
log.verbose(this.errorsToString(errorValues));
|
|
151
124
|
}
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
errors.add(error.message);
|
|
125
|
+
return response.stdout;
|
|
156
126
|
}
|
|
127
|
+
errors.add(response.error || response.stderr);
|
|
157
128
|
}
|
|
158
|
-
|
|
159
|
-
|
|
129
|
+
catch (error) {
|
|
130
|
+
errors.add(error.message);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
throw new Error(`Failed to send request with parameters '${JSON.stringify(params)}': ${this.errorsToString([...errors.values()])}`);
|
|
160
134
|
}
|
|
161
135
|
static errorsToString(errors) {
|
|
162
136
|
return errors.length > 1
|
|
@@ -178,24 +152,21 @@ class CFUtil {
|
|
|
178
152
|
* @return {Promise<string>} promise with space guid
|
|
179
153
|
* @memberof CFUtil
|
|
180
154
|
*/
|
|
181
|
-
static getSpaceGuid(spaceGuid) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
spaceGuid = resource.guid;
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
155
|
+
static async getSpaceGuid(spaceGuid) {
|
|
156
|
+
if (spaceGuid == null) {
|
|
157
|
+
const spaceName = (await CFLocal.cfGetTarget())?.space;
|
|
158
|
+
if (spaceName) {
|
|
159
|
+
const resources = await this.requestCfApi(`/v3/spaces?names=${spaceName}`);
|
|
160
|
+
for (const resource of resources) {
|
|
161
|
+
spaceGuid = resource.guid;
|
|
162
|
+
break;
|
|
192
163
|
}
|
|
193
164
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
165
|
+
}
|
|
166
|
+
if (spaceGuid == null) {
|
|
167
|
+
throw new Error("Please login to Cloud Foundry with 'cf login' and try again");
|
|
168
|
+
}
|
|
169
|
+
return spaceGuid;
|
|
199
170
|
}
|
|
200
171
|
}
|
|
201
172
|
exports.default = CFUtil;
|
package/dist/util/commonUtil.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.replaceDots = replaceDots;
|
|
|
8
8
|
function validateObject(options, properties, message) {
|
|
9
9
|
for (const property of properties) {
|
|
10
10
|
if (!options[property]) {
|
|
11
|
-
throw new Error(`'${property}' ${message}`);
|
|
11
|
+
throw new Error(`'${String(property)}' ${message}`);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { IAuth } from "../model/types";
|
|
2
2
|
export default class RequestUtil {
|
|
3
|
-
static
|
|
4
|
-
static
|
|
3
|
+
static head(url: string, auth?: IAuth): Promise<any>;
|
|
4
|
+
static get(url: string, options?: any, auth?: IAuth): Promise<any>;
|
|
5
|
+
static request(url: string, method: Function, auth?: IAuth, options?: any): Promise<any>;
|
|
6
|
+
private static handleError;
|
|
7
|
+
static retryWithAuth<T>(requestWithoutAuth: Function, requestWithAuth: Function): Promise<T>;
|
|
5
8
|
}
|
package/dist/util/requestUtil.js
CHANGED
|
@@ -1,33 +1,52 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const axios_1 = require("axios");
|
|
4
|
+
const noAuthorizationProvidedError_1 = require("../model/noAuthorizationProvidedError");
|
|
13
5
|
class RequestUtil {
|
|
14
|
-
static
|
|
15
|
-
return axios_1.default.
|
|
6
|
+
static async head(url, auth) {
|
|
7
|
+
return this.request(url, axios_1.default.head, auth);
|
|
16
8
|
}
|
|
17
|
-
static
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
static async get(url, options, auth) {
|
|
10
|
+
return this.request(url, axios_1.default.get, auth, options);
|
|
11
|
+
}
|
|
12
|
+
static async request(url, method, auth, options) {
|
|
13
|
+
try {
|
|
14
|
+
return await method(url, { auth, ...options })
|
|
15
|
+
.then((response) => response.data);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
this.handleError(error, url);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
static handleError(error, uri) {
|
|
22
|
+
if (error.response) {
|
|
23
|
+
// HTTP Status Code > 2xx
|
|
24
|
+
if (error.response.status === 401) {
|
|
25
|
+
throw new noAuthorizationProvidedError_1.default(uri);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`Unexpected response received from '${uri}': ${error.response.status} ${error.response.data ?? ""}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (error.request) {
|
|
32
|
+
throw new Error(`No response was received from '${uri}': ${error.code}`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error(`Error sending request to '${uri}': ${error.code}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static async retryWithAuth(requestWithoutAuth, requestWithAuth) {
|
|
39
|
+
try {
|
|
40
|
+
return await requestWithoutAuth();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error instanceof noAuthorizationProvidedError_1.default) {
|
|
44
|
+
return await requestWithAuth();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw error;
|
|
21
48
|
}
|
|
22
|
-
|
|
23
|
-
responseType: "arraybuffer",
|
|
24
|
-
headers: {
|
|
25
|
-
"Content-Type": "application/json",
|
|
26
|
-
"Authorization": "Bearer " + token,
|
|
27
|
-
"x-app-host-id": appHostId
|
|
28
|
-
}
|
|
29
|
-
}).then(response => response.data);
|
|
30
|
-
});
|
|
49
|
+
}
|
|
31
50
|
}
|
|
32
51
|
}
|
|
33
52
|
exports.default = RequestUtil;
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { IConfiguration } from "../model/types";
|
|
2
1
|
export default class ResourceUtil {
|
|
3
|
-
static METADATA_FILENAME: string;
|
|
4
|
-
static readTempMetadata(configuration: IConfiguration): any;
|
|
5
2
|
static getRootFolder(projectNamespace?: string): string;
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
private static getBaseAppTempFolder;
|
|
9
|
-
private static getTempId;
|
|
10
|
-
static deleteTemp(configuration: IConfiguration): void;
|
|
11
|
-
private static normalizeId;
|
|
12
|
-
static fetchFiles(rootFolder: string, folder: string, baseAppFiles: Map<string, string>): void;
|
|
3
|
+
static write(dir: string, files: Map<string, string>): Promise<void[]>;
|
|
4
|
+
static read(rootFolder: string, folder: string, files: Map<string, string>, exclude?: string[]): void;
|
|
13
5
|
}
|
|
@@ -1,27 +1,9 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const fs = require("fs");
|
|
13
4
|
const path = require("path");
|
|
14
|
-
const rimraf = require("rimraf");
|
|
15
|
-
const tempFolder = require('temp-dir');
|
|
16
5
|
const resourceFactory = require("@ui5/fs/lib/resourceFactory");
|
|
17
6
|
class ResourceUtil {
|
|
18
|
-
static readTempMetadata(configuration) {
|
|
19
|
-
const baseAppTempFolder = this.getBaseAppTempFolder(configuration);
|
|
20
|
-
const metadataPath = path.resolve(baseAppTempFolder, this.METADATA_FILENAME);
|
|
21
|
-
if (fs.existsSync(metadataPath)) {
|
|
22
|
-
return JSON.parse(fs.readFileSync(metadataPath, { encoding: "utf-8" }));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
7
|
static getRootFolder(projectNamespace) {
|
|
26
8
|
const newPath = ["/resources"];
|
|
27
9
|
if (projectNamespace) {
|
|
@@ -29,11 +11,9 @@ class ResourceUtil {
|
|
|
29
11
|
}
|
|
30
12
|
return path.join(...newPath);
|
|
31
13
|
}
|
|
32
|
-
static
|
|
33
|
-
const distTempFolder = this.getBaseAppTempFolder(configuration);
|
|
34
|
-
rimraf.sync(distTempFolder);
|
|
14
|
+
static write(dir, files) {
|
|
35
15
|
const fsTarget = resourceFactory.createAdapter({
|
|
36
|
-
fsBasePath:
|
|
16
|
+
fsBasePath: dir,
|
|
37
17
|
virBasePath: "/"
|
|
38
18
|
});
|
|
39
19
|
const promises = [];
|
|
@@ -43,43 +23,20 @@ class ResourceUtil {
|
|
|
43
23
|
});
|
|
44
24
|
return Promise.all(promises);
|
|
45
25
|
}
|
|
46
|
-
static
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const baseAppTempFolder = this.getBaseAppTempFolder(configuration);
|
|
49
|
-
const baseAppFiles = new Map();
|
|
50
|
-
if (fs.existsSync(baseAppTempFolder)) {
|
|
51
|
-
this.fetchFiles(baseAppTempFolder, baseAppTempFolder, baseAppFiles);
|
|
52
|
-
}
|
|
53
|
-
return baseAppFiles;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
static getBaseAppTempFolder(configuration) {
|
|
57
|
-
return path.join(tempFolder, this.getTempId(configuration));
|
|
58
|
-
}
|
|
59
|
-
static getTempId({ appHostId, appName, appVersion }) {
|
|
60
|
-
return this.normalizeId(`ui5-task-adaptation-${appHostId}-${appName}-${appVersion}`);
|
|
61
|
-
}
|
|
62
|
-
static deleteTemp(configuration) {
|
|
63
|
-
rimraf.sync(this.getBaseAppTempFolder(configuration));
|
|
64
|
-
}
|
|
65
|
-
static normalizeId(id) {
|
|
66
|
-
return id.replace(/\/\\/g, "_");
|
|
67
|
-
}
|
|
68
|
-
static fetchFiles(rootFolder, folder, baseAppFiles) {
|
|
26
|
+
static read(rootFolder, folder, files, exclude = []) {
|
|
69
27
|
const entries = fs.readdirSync(folder);
|
|
70
28
|
for (let entry of entries) {
|
|
71
29
|
const entryPath = path.join(folder, entry);
|
|
72
30
|
const stats = fs.lstatSync(entryPath);
|
|
73
|
-
if (stats.isFile() && !entryPath.endsWith(
|
|
31
|
+
if (stats.isFile() && !exclude.some(filepath => entryPath.endsWith(filepath))) {
|
|
74
32
|
const normalized = entryPath.substring(rootFolder.length);
|
|
75
|
-
|
|
33
|
+
files.set(normalized, fs.readFileSync(entryPath, { encoding: "utf-8" }));
|
|
76
34
|
}
|
|
77
35
|
else if (stats.isDirectory()) {
|
|
78
|
-
this.
|
|
36
|
+
this.read(rootFolder, entryPath, files, exclude);
|
|
79
37
|
}
|
|
80
38
|
}
|
|
81
39
|
}
|
|
82
40
|
}
|
|
83
41
|
exports.default = ResourceUtil;
|
|
84
|
-
ResourceUtil.METADATA_FILENAME = "html5metadata.json";
|
|
85
42
|
//# sourceMappingURL=resourceUtil.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unzipZipEntries = void 0;
|
|
4
|
+
const AdmZip = require("adm-zip");
|
|
5
|
+
async function unzipZipEntries(zip) {
|
|
6
|
+
let admZip;
|
|
7
|
+
try {
|
|
8
|
+
admZip = new AdmZip(zip);
|
|
9
|
+
const entries = admZip.getEntries();
|
|
10
|
+
return mapEntries(entries);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
throw new Error("Failed to parse zip content from HTML5 Repository: " + error.message);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.unzipZipEntries = unzipZipEntries;
|
|
17
|
+
function mapEntries(entries) {
|
|
18
|
+
return new Map(entries.filter(entry => !entry.isDirectory).map(entry => [entry.entryName, entry.getData().toString("utf8")]));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=zipUtil.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/task-adaptation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"version": "git-chglog --next-tag v$npm_package_version -o CHANGELOG.md && git add CHANGELOG.md",
|
|
14
14
|
"postversion": "git push --follow-tags",
|
|
15
15
|
"release-note": "git-chglog -c .chglog/release-config.yml v$npm_package_version",
|
|
16
|
-
"rollup": "ts-node scripts/rollup.ts
|
|
16
|
+
"rollup": "ts-node scripts/rollup.ts",
|
|
17
17
|
"build": "npm run rollup && tsc -p ./"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -42,11 +42,14 @@
|
|
|
42
42
|
"amdextract": "^3.0.0",
|
|
43
43
|
"axios": "^0.25.0",
|
|
44
44
|
"builtin-modules": "^3.2.0",
|
|
45
|
+
"dotenv": "^16.0.3",
|
|
45
46
|
"js-yaml": "^4.1.0",
|
|
47
|
+
"json-diff": "^1.0.6",
|
|
46
48
|
"rimraf": "^3.0.2",
|
|
47
49
|
"rollup": "^2.56.3",
|
|
48
50
|
"semver": "^7.3.5",
|
|
49
|
-
"temp-dir": "^2.0.0"
|
|
51
|
+
"temp-dir": "^2.0.0",
|
|
52
|
+
"xml-js": "^1.6.11"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
55
|
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
@@ -54,6 +57,8 @@
|
|
|
54
57
|
"@types/chai": "^4.2.21",
|
|
55
58
|
"@types/chai-as-promised": "^7.1.4",
|
|
56
59
|
"@types/js-yaml": "^4.0.3",
|
|
60
|
+
"@types/json-diff": "^0.9.1",
|
|
61
|
+
"@types/lodash": "^4.14.196",
|
|
57
62
|
"@types/mocha": "^9.1.0",
|
|
58
63
|
"@types/rimraf": "^3.0.2",
|
|
59
64
|
"@types/semver": "^7.3.8",
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import * as semver from "semver";
|
|
4
|
+
import * as rollup from "rollup";
|
|
5
|
+
import * as builtins from "builtin-modules";
|
|
6
|
+
import ui5 from "./rollup/ui5Resolve";
|
|
7
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
8
|
+
|
|
9
|
+
const log = require("@ui5/logger").getLogger("rollup-plugin-ui5-resolve-task-adaptation");
|
|
10
|
+
|
|
11
|
+
export default abstract class Bundler {
|
|
12
|
+
|
|
13
|
+
static async run(project: any, input: string, output: string, namespace: string,
|
|
14
|
+
assets: string[], skipTransformation?: string[]): Promise<void> {
|
|
15
|
+
if (skipTransformation == null) {
|
|
16
|
+
skipTransformation = [];
|
|
17
|
+
}
|
|
18
|
+
if (skipTransformation.includes(input) === false) {
|
|
19
|
+
skipTransformation.push(input);
|
|
20
|
+
}
|
|
21
|
+
const bundledUI5Version = this.getBundledUI5Version(output);
|
|
22
|
+
const ui5version = this.getVersion(project, namespace);
|
|
23
|
+
if (bundledUI5Version == null || ui5version && semver.neq(bundledUI5Version, ui5version)) {
|
|
24
|
+
if (ui5version) {
|
|
25
|
+
log.info(`Using UI5 version ${ui5version.toString()} to bundle`);
|
|
26
|
+
}
|
|
27
|
+
await this.bundle(project, input, output, assets, skipTransformation, ui5version);
|
|
28
|
+
} else {
|
|
29
|
+
log.info(`UI5 version ${bundledUI5Version!.toString()} is already bundled`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private static async bundle(project: any, input: string, output: string,
|
|
34
|
+
assets: string[], skipTransformation: string[], ui5version: string): Promise<void> {
|
|
35
|
+
const inputOptions = <rollup.RollupOptions>{
|
|
36
|
+
input,
|
|
37
|
+
plugins: [
|
|
38
|
+
ui5({
|
|
39
|
+
assets,
|
|
40
|
+
skipTransformation,
|
|
41
|
+
output,
|
|
42
|
+
project,
|
|
43
|
+
ui5version
|
|
44
|
+
}),
|
|
45
|
+
nodeResolve({
|
|
46
|
+
preferBuiltins: true
|
|
47
|
+
})
|
|
48
|
+
],
|
|
49
|
+
external: builtins
|
|
50
|
+
};
|
|
51
|
+
const bundle = await rollup.rollup(inputOptions);
|
|
52
|
+
|
|
53
|
+
const outputOptions = <rollup.RollupOptions>{
|
|
54
|
+
file: output,
|
|
55
|
+
format: "commonjs"
|
|
56
|
+
};
|
|
57
|
+
await bundle.write(outputOptions);
|
|
58
|
+
await bundle.close();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private static getBundledUI5Version(output: string) {
|
|
62
|
+
const bundleFilePath = path.join(process.cwd(), output);
|
|
63
|
+
if (fs.existsSync(bundleFilePath)) {
|
|
64
|
+
const bundle = fs.readFileSync(bundleFilePath, { encoding: "utf-8" });
|
|
65
|
+
const version = bundle.substring(2, bundle.indexOf("\n"));
|
|
66
|
+
return semver.coerce(version);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private static getVersion(project: any, namespace: string): string {
|
|
71
|
+
const isModule = (dependency: any) => dependency.id.endsWith(namespace);
|
|
72
|
+
const sapUiFlDependency = project.dependencies.find(isModule);
|
|
73
|
+
return sapUiFlDependency && sapUiFlDependency.version;
|
|
74
|
+
}
|
|
75
|
+
}
|