@ui5/task-adaptation 1.0.8 → 1.0.11
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 +13 -1
- package/README.md +27 -1
- package/dist/baseAppManager.d.ts +4 -3
- package/dist/baseAppManager.js +32 -18
- package/dist/bundle.js +904 -58
- package/dist/index.js +2 -21
- package/dist/model/types.d.ts +2 -1
- package/dist/updateCache.d.ts +1 -1
- package/dist/updateCache.js +6 -4
- package/dist/util/requestUtil.js +5 -10
- package/package.json +32 -26
- package/scripts/rollup/bundleDefinition.js +11 -0
- package/scripts/rollup/overrides/sap/ui/fl/Change.js +72 -0
- package/scripts/rollup/overrides/sap/ui/thirdparty/URI.js +16 -0
- package/scripts/rollup/project/package.json +3 -0
- package/scripts/rollup/project/ui5.yaml +13 -0
- package/scripts/rollup/project/webapp/manifest.json +5 -0
- package/scripts/rollup/ui5Resolve.ts +134 -0
- package/scripts/rollup.ts +111 -0
package/dist/index.js
CHANGED
|
@@ -11,39 +11,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const appVariantManager_1 = require("./appVariantManager");
|
|
13
13
|
const baseAppManager_1 = require("./baseAppManager");
|
|
14
|
-
const
|
|
15
|
-
const resourceUtil_1 = require("./util/resourceUtil");
|
|
14
|
+
const updateCache_1 = require("./updateCache");
|
|
16
15
|
/**
|
|
17
16
|
* Creates an appVariant bundle from the provided resources.
|
|
18
17
|
*/
|
|
19
18
|
module.exports = ({ workspace, options, taskUtil }) => {
|
|
20
19
|
function process(workspace, taskUtil) {
|
|
21
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const baseAppFiles =
|
|
21
|
+
const baseAppFiles = updateCache_1.default(options.configuration);
|
|
23
22
|
const appVariantResources = yield appVariantManager_1.default.getAppVariantResources(workspace);
|
|
24
23
|
const appVariantInfo = appVariantManager_1.default.process(appVariantResources, options.projectNamespace, taskUtil);
|
|
25
24
|
const baseAppResources = yield baseAppManager_1.default.process(yield baseAppFiles, yield appVariantInfo, options);
|
|
26
25
|
yield Promise.all(appVariantResources.concat(baseAppResources).map(resource => workspace.write(resource)));
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
|
-
function getBaseAppFiles(configuration) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
let result = new Map();
|
|
32
|
-
if (!configuration.ignoreCache) {
|
|
33
|
-
result = yield resourceUtil_1.default.readTemp(configuration);
|
|
34
|
-
}
|
|
35
|
-
if (result.size === 0) {
|
|
36
|
-
const [metadata, baseAppFiles] = yield Promise.all([
|
|
37
|
-
html5RepoManager_1.default.getMetadata(configuration),
|
|
38
|
-
html5RepoManager_1.default.getBaseAppFiles(configuration)
|
|
39
|
-
]);
|
|
40
|
-
const metadataMap = new Map([[resourceUtil_1.default.METADATA_FILENAME, JSON.stringify(metadata)]]);
|
|
41
|
-
yield resourceUtil_1.default.writeTemp(configuration, new Map([...baseAppFiles, ...metadataMap]));
|
|
42
|
-
return baseAppFiles;
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
28
|
return process(workspace, taskUtil);
|
|
48
29
|
};
|
|
49
30
|
//# sourceMappingURL=index.js.map
|
package/dist/model/types.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export interface IConfiguration {
|
|
|
6
6
|
spaceGuid?: string;
|
|
7
7
|
orgGuid?: string;
|
|
8
8
|
sapCloudService?: string;
|
|
9
|
-
ignoreCache?: boolean;
|
|
10
9
|
}
|
|
11
10
|
export interface IProjectOptions {
|
|
12
11
|
configuration: IConfiguration;
|
|
@@ -59,11 +58,13 @@ export interface IAppVariantInfo {
|
|
|
59
58
|
export interface IAppVariantManifest {
|
|
60
59
|
id: string;
|
|
61
60
|
reference: string;
|
|
61
|
+
layer?: string;
|
|
62
62
|
content: IChange[];
|
|
63
63
|
}
|
|
64
64
|
export interface IChange {
|
|
65
65
|
changeType: string;
|
|
66
66
|
texts: IChangeText;
|
|
67
|
+
layer?: string;
|
|
67
68
|
}
|
|
68
69
|
export interface IChangeText {
|
|
69
70
|
i18n: string;
|
package/dist/updateCache.d.ts
CHANGED
package/dist/updateCache.js
CHANGED
|
@@ -23,11 +23,13 @@ function default_1(configuration) {
|
|
|
23
23
|
const metadata = yield metadataPromise;
|
|
24
24
|
if (metadata.changedOn !== (tempMetadata === null || tempMetadata === void 0 ? void 0 : tempMetadata.changedOn)) {
|
|
25
25
|
const baseAppFiles = yield html5RepoManager_1.default.getBaseAppFiles(configuration);
|
|
26
|
-
|
|
27
|
-
yield resourceUtil_1.default.writeTemp(configuration, baseAppFiles);
|
|
28
|
-
return
|
|
26
|
+
const metadataMap = new Map([[resourceUtil_1.default.METADATA_FILENAME, JSON.stringify(metadata)]]);
|
|
27
|
+
yield resourceUtil_1.default.writeTemp(configuration, new Map([...baseAppFiles, ...metadataMap]));
|
|
28
|
+
return baseAppFiles;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return resourceUtil_1.default.readTemp(configuration);
|
|
29
32
|
}
|
|
30
|
-
return false;
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
exports.default = default_1;
|
package/dist/util/requestUtil.js
CHANGED
|
@@ -9,29 +9,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const axios_1 = require("axios");
|
|
13
13
|
class RequestUtil {
|
|
14
14
|
static get(uri, options) {
|
|
15
|
-
return
|
|
15
|
+
return axios_1.default.get(uri, options).then(response => response.data);
|
|
16
16
|
}
|
|
17
17
|
static download(token, appHostId, uri) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
if (!token) {
|
|
20
20
|
throw new Error("HTML5 token is undefined");
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
return axios_1.default.get(uri, {
|
|
23
|
+
responseType: "arraybuffer",
|
|
23
24
|
headers: {
|
|
24
25
|
"Content-Type": "application/json",
|
|
25
26
|
"Authorization": "Bearer " + token,
|
|
26
27
|
"x-app-host-id": appHostId
|
|
27
28
|
}
|
|
28
|
-
});
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
const data = [];
|
|
31
|
-
response.body.on("error", err => reject(err));
|
|
32
|
-
response.body.on("data", block => data.push(block));
|
|
33
|
-
response.body.on("end", () => resolve(Buffer.concat(data)));
|
|
34
|
-
});
|
|
29
|
+
}).then(response => response.data);
|
|
35
30
|
});
|
|
36
31
|
}
|
|
37
32
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/task-adaptation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
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": {
|
|
7
7
|
"test": "npm run build && npm run coverage",
|
|
8
8
|
"dev": "mocha --no-timeouts -r ts-node/register 'test/**/*.spec.ts'",
|
|
9
|
-
"
|
|
10
|
-
"coverage
|
|
9
|
+
"perf": "mocha --no-timeouts -r ts-node/register 'test/**/*.perf.ts'",
|
|
10
|
+
"coverage": "nyc mocha -r ts-node/register 'test/**/*.spec.ts'",
|
|
11
|
+
"coverage-verbose": "nyc --reporter=html --reporter=text mocha -r ts-node/register 'test/**/*.spec.ts'",
|
|
11
12
|
"preversion": "npm test",
|
|
12
13
|
"version": "git-chglog --next-tag v$npm_package_version -o CHANGELOG.md && git add CHANGELOG.md",
|
|
13
14
|
"postversion": "git push --follow-tags",
|
|
14
15
|
"release-note": "git-chglog -c .chglog/release-config.yml v$npm_package_version",
|
|
15
|
-
"
|
|
16
|
+
"rollup": "ts-node scripts/rollup.ts ./dist/bundle.js",
|
|
17
|
+
"build": "npm run rollup && tsc -p ./"
|
|
16
18
|
},
|
|
17
19
|
"repository": {
|
|
18
20
|
"type": "git",
|
|
@@ -30,38 +32,42 @@
|
|
|
30
32
|
"author": "SAP SE",
|
|
31
33
|
"license": "Apache-2.0",
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@
|
|
35
|
+
"@buxlabs/amd-to-es6": "^0.16.1",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
37
|
+
"@sap/cf-tools": "^2.0.1",
|
|
34
38
|
"@ui5/fs": "^2.0.6",
|
|
35
39
|
"@ui5/logger": "^2.0.1",
|
|
40
|
+
"@ui5/project": "^2.6.0",
|
|
36
41
|
"adm-zip": "^0.5.5",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
42
|
+
"amdextract": "^3.0.0",
|
|
43
|
+
"axios": "^0.25.0",
|
|
44
|
+
"builtin-modules": "^3.2.0",
|
|
45
|
+
"js-yaml": "^4.1.0",
|
|
39
46
|
"rimraf": "^3.0.2",
|
|
47
|
+
"rollup": "^2.56.3",
|
|
48
|
+
"semver": "^7.3.5",
|
|
40
49
|
"temp-dir": "^2.0.0"
|
|
41
50
|
},
|
|
42
51
|
"devDependencies": {
|
|
43
|
-
"@buxlabs/amd-to-es6": "^0.16.0",
|
|
44
52
|
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
45
|
-
"@rollup/plugin-node-resolve": "^11.2.1",
|
|
46
53
|
"@types/adm-zip": "^0.4.34",
|
|
47
|
-
"@types/chai": "^4.2.
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/
|
|
51
|
-
"@types/rimraf": "^3.0.
|
|
52
|
-
"@types/
|
|
53
|
-
"@
|
|
54
|
-
"amdextract": "^3.0.0",
|
|
55
|
-
"builtin-modules": "^3.2.0",
|
|
54
|
+
"@types/chai": "^4.2.21",
|
|
55
|
+
"@types/chai-as-promised": "^7.1.4",
|
|
56
|
+
"@types/js-yaml": "^4.0.3",
|
|
57
|
+
"@types/mocha": "^9.1.0",
|
|
58
|
+
"@types/rimraf": "^3.0.2",
|
|
59
|
+
"@types/semver": "^7.3.8",
|
|
60
|
+
"@types/sinon": "^10.0.2",
|
|
56
61
|
"chai": "^4.3.4",
|
|
57
|
-
"
|
|
62
|
+
"chai-as-promised": "^7.1.1",
|
|
63
|
+
"chalk": "^4.1.2",
|
|
64
|
+
"mocha": "^9.2.0",
|
|
58
65
|
"mock-require": "^3.0.3",
|
|
59
66
|
"nyc": "^15.1.0",
|
|
60
|
-
"
|
|
61
|
-
"sinon": "^10.0.0",
|
|
67
|
+
"sinon": "^11.1.2",
|
|
62
68
|
"source-map-support": "^0.5.19",
|
|
63
|
-
"ts-node": "^
|
|
64
|
-
"typescript": "^4.
|
|
69
|
+
"ts-node": "^10.4.0",
|
|
70
|
+
"typescript": "^4.3.5"
|
|
65
71
|
},
|
|
66
72
|
"nyc": {
|
|
67
73
|
"reporter": [
|
|
@@ -77,10 +83,10 @@
|
|
|
77
83
|
"test/**",
|
|
78
84
|
"lib/processors/jsdoc/lib/**",
|
|
79
85
|
"dist/**",
|
|
80
|
-
"rollup.config.js",
|
|
81
|
-
"rollup/**",
|
|
82
86
|
"src/model/types.ts",
|
|
83
|
-
"src/util/requestUtil.ts"
|
|
87
|
+
"src/util/requestUtil.ts",
|
|
88
|
+
"scripts/**/*.js",
|
|
89
|
+
"scripts/git/octokitUtil.ts"
|
|
84
90
|
],
|
|
85
91
|
"check-coverage": true,
|
|
86
92
|
"statements": 85,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Applier from "sap/ui/fl/apply/_internal/changes/descriptor/Applier";
|
|
2
|
+
import ApplyUtil from "sap/ui/fl/apply/_internal/changes/descriptor/ApplyUtil";
|
|
3
|
+
import Change from "sap/ui/fl/Change";
|
|
4
|
+
import RegistrationBuild from "sap/ui/fl/apply/_internal/changes/descriptor/RegistrationBuild";
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
Applier,
|
|
8
|
+
ApplyUtil,
|
|
9
|
+
Change,
|
|
10
|
+
RegistrationBuild
|
|
11
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* OpenUI5
|
|
3
|
+
* (c) Copyright 2009-2020 SAP SE or an SAP affiliate company.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
sap.ui.define([
|
|
8
|
+
|
|
9
|
+
], function (
|
|
10
|
+
|
|
11
|
+
) {
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Flexibility change class. Stores change content and related information.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} oFile - File content and admin data
|
|
18
|
+
*
|
|
19
|
+
* @class sap.ui.fl.Change
|
|
20
|
+
* @private
|
|
21
|
+
* @ui5-restricted
|
|
22
|
+
* @experimental Since 1.25.0
|
|
23
|
+
*/
|
|
24
|
+
var Change = function (oFile) {
|
|
25
|
+
this._oDefinition = oFile;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns the change type.
|
|
30
|
+
*
|
|
31
|
+
* @returns {String} Change type of the file, for example <code>LabelChange</code>
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
Change.prototype.getChangeType = function () {
|
|
35
|
+
if (this._oDefinition) {
|
|
36
|
+
return this._oDefinition.changeType;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets the layer type for the change.
|
|
42
|
+
* @returns {string} Layer of the change file
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
Change.prototype.getLayer = function () {
|
|
47
|
+
return this._oDefinition.layer;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns the content section of the change.
|
|
52
|
+
* @returns {string} Content of the change file. The content structure can be any JSON.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
Change.prototype.getContent = function () {
|
|
57
|
+
return this._oDefinition.content;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns all texts.
|
|
62
|
+
*
|
|
63
|
+
* @returns {object} All texts
|
|
64
|
+
*
|
|
65
|
+
* @function
|
|
66
|
+
*/
|
|
67
|
+
Change.prototype.getTexts = function () {
|
|
68
|
+
return this._oDefinition.texts;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return Change;
|
|
72
|
+
}, true);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as crypto from "crypto";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as stream from "stream";
|
|
5
|
+
|
|
6
|
+
import { promisify } from "util";
|
|
7
|
+
|
|
8
|
+
const convertAMDtoES6 = require("@buxlabs/amd-to-es6");
|
|
9
|
+
const log = require("@ui5/logger").getLogger("rollup-plugin-ui5-resolve-task-adaptation");
|
|
10
|
+
const { resourceFactory } = require("@ui5/fs");
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export default function (options: any) {
|
|
14
|
+
|
|
15
|
+
let dependencies: any;
|
|
16
|
+
|
|
17
|
+
const skipTransformation = (id: string) => !options.skipTransformation?.includes(id);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
|
|
21
|
+
name: "ui5-resolve",
|
|
22
|
+
|
|
23
|
+
buildStart: async (_: any) => {
|
|
24
|
+
|
|
25
|
+
dependencies = resourceFactory.createCollectionsForTree(options.project, {}).dependencies;
|
|
26
|
+
|
|
27
|
+
const pipe = promisify(stream.pipeline);
|
|
28
|
+
const resources: any[] = await Promise.all(options.assets.map((asset: string) => dependencies.byGlob(asset)));
|
|
29
|
+
const writePromises = [].concat(...resources).map((resource: any) => {
|
|
30
|
+
const file = `./dist${resource.getPath()}`;
|
|
31
|
+
const folder = path.dirname(file);
|
|
32
|
+
if (!fs.existsSync(folder)) {
|
|
33
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
if (fs.existsSync(file)) {
|
|
36
|
+
fs.unlinkSync(file);
|
|
37
|
+
}
|
|
38
|
+
return pipe(resource.getStream(), fs.createWriteStream(file));
|
|
39
|
+
});
|
|
40
|
+
await Promise.all(writePromises);
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Right before writing result to dist
|
|
46
|
+
*/
|
|
47
|
+
renderChunk: (code: string) => {
|
|
48
|
+
return `//${options.ui5version}\nvar window = {};\n${code}`;
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
resolveId: (source: string, importer: string) => {
|
|
53
|
+
log.verbose(`resolveId: ${source} from ${importer}`);
|
|
54
|
+
if (importer && source.startsWith(".")) {
|
|
55
|
+
source = path.posix.join(path.dirname(importer), source);
|
|
56
|
+
}
|
|
57
|
+
log.verbose(" --> resolve to: " + source);
|
|
58
|
+
return source;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
load: async (id: string) => {
|
|
63
|
+
log.verbose(`load: ${id}`);
|
|
64
|
+
|
|
65
|
+
if (!dependencies) {
|
|
66
|
+
dependencies = resourceFactory.createCollectionsForTree(options.project, {}).dependencies;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const localFile = path.join(__dirname, id);
|
|
70
|
+
if (fs.existsSync(localFile)) {
|
|
71
|
+
log.info(`Using local file "${id}"`);
|
|
72
|
+
return fs.readFileSync(localFile, {
|
|
73
|
+
encoding: "utf8"
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const localOverride = path.resolve(__dirname, "overrides", id + ".js");
|
|
78
|
+
if (fs.existsSync(localOverride)) {
|
|
79
|
+
log.info(`Using local override for "${id}"`);
|
|
80
|
+
return fs.readFileSync(localOverride, { encoding: "utf8" });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const resource = await dependencies.byPath(`/resources/${id}.js`);
|
|
84
|
+
return resource.getString();
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
transform: (code: string, id: string): string | undefined => {
|
|
89
|
+
const skipped = !skipTransformation(id);
|
|
90
|
+
log.verbose(`transform: ${id} ${skipped ? "skipped" : ""}`);
|
|
91
|
+
if (skipped) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
code = replaceRequireAsync(code);
|
|
96
|
+
|
|
97
|
+
code = code
|
|
98
|
+
.replace(/sap\.ui\.define/g, "define")
|
|
99
|
+
.replace(/\, \/\* bExport\= \*\/ true\)/g, ")")
|
|
100
|
+
.replace(/}, (true|false)\);$/g, "});")
|
|
101
|
+
.replace(/}, (true|false)\);(\n\/\/# sourceMappingURL=)*/g, "});\n//# sourceMappingURL=");
|
|
102
|
+
return convertAMDtoES6(code);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
function replaceRequireAsync(code: string) {
|
|
110
|
+
const requireAsyncPattern = /requireAsync((.bind\(this, ")|(\("))+(?<url>[\/\w]*)"\)/mg;
|
|
111
|
+
let match, defineUrls = [], defineVars = [], matches = new Map();
|
|
112
|
+
while (match = requireAsyncPattern.exec(code)) {
|
|
113
|
+
if (match.groups?.url) {
|
|
114
|
+
const varaibleName = match.groups.url.split("/").pop() + crypto.randomBytes(16).toString("hex");
|
|
115
|
+
defineUrls.push(`"${match.groups.url}"`);
|
|
116
|
+
defineVars.push(varaibleName);
|
|
117
|
+
const value = match[0].includes("requireAsync.bind")
|
|
118
|
+
? `() => Promise.resolve(${varaibleName})`
|
|
119
|
+
: varaibleName;
|
|
120
|
+
matches.set(match[0], value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (defineUrls.length > 0 && defineVars.length > 0) {
|
|
124
|
+
matches.forEach((value, key) => code = code.replace(key, value));
|
|
125
|
+
code = replaceRequireAsyncWith(code, `"sap/ui/fl/requireAsync"`, defineUrls);
|
|
126
|
+
code = replaceRequireAsyncWith(code, "requireAsync", defineVars);
|
|
127
|
+
}
|
|
128
|
+
return code;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
function replaceRequireAsyncWith(code: string, requireAsyncSearchKeyword: string, inserts: string[]) {
|
|
133
|
+
return code.replace(requireAsyncSearchKeyword, inserts.join(",\n\t"));
|
|
134
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
import * as builtins from "builtin-modules";
|
|
5
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
6
|
+
import * as rollup from "rollup";
|
|
7
|
+
import * as semver from "semver";
|
|
8
|
+
import * as yaml from "js-yaml";
|
|
9
|
+
import ui5 from "./rollup/ui5Resolve";
|
|
10
|
+
|
|
11
|
+
const { normalizer } = require("@ui5/project");
|
|
12
|
+
const log = require("@ui5/logger").getLogger("rollup-plugin-ui5-resolve-task-adaptation");
|
|
13
|
+
|
|
14
|
+
const projectPaths = [
|
|
15
|
+
path.resolve(__dirname, "rollup", "project")
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default class Builder {
|
|
19
|
+
|
|
20
|
+
static async getProjectInfo(projectPaths: string[]) {
|
|
21
|
+
for (const cwd of projectPaths) {
|
|
22
|
+
try {
|
|
23
|
+
let options = {
|
|
24
|
+
cwd,
|
|
25
|
+
frameworkOptions: {
|
|
26
|
+
versionOverride: "latest"
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const project = await normalizer.generateProjectTree(options);
|
|
30
|
+
this.validateProjectSettings(cwd);
|
|
31
|
+
return project;
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
log.info(`${error.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static validateProjectSettings(projectPath: string) {
|
|
39
|
+
const FRAMEWORK_TYPES = ["OpenUI5", "SAPUI5"];
|
|
40
|
+
const content = fs.readFileSync(path.join(projectPath, "ui5.yaml"), { encoding: "utf-8" });
|
|
41
|
+
const yamlJson = <any>yaml.load(content);
|
|
42
|
+
const framework = yamlJson["framework"];
|
|
43
|
+
if (!FRAMEWORK_TYPES.includes(framework.name)) {
|
|
44
|
+
throw new Error(`UI5 framework name is incorrect, possible values: ${FRAMEWORK_TYPES.join(" or ")}`);
|
|
45
|
+
}
|
|
46
|
+
if (!semver.valid(framework.version)) {
|
|
47
|
+
throw new Error(`UI5 framework version should correspond semantic version standard, e.g: 1.85.2`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static getBundledUI5Version(destination: string) {
|
|
52
|
+
const bundleFilePath = path.join(process.cwd(), destination);
|
|
53
|
+
if (fs.existsSync(bundleFilePath)) {
|
|
54
|
+
const bundle = fs.readFileSync(bundleFilePath, { encoding: "utf-8" });
|
|
55
|
+
const version = bundle.substring(2, bundle.indexOf("\n"));
|
|
56
|
+
return semver.coerce(version);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static async run(destination: string): Promise<void> {
|
|
61
|
+
const bundledUI5Version = this.getBundledUI5Version(destination);
|
|
62
|
+
const project = await this.getProjectInfo(projectPaths);
|
|
63
|
+
if (!project) {
|
|
64
|
+
throw new Error("ui5.yaml is not found or incorrect");
|
|
65
|
+
}
|
|
66
|
+
const isSapUiFl = (dependency: any) => dependency.id.endsWith("/sap.ui.fl");
|
|
67
|
+
const sapUiFlDependency = project.dependencies.find(isSapUiFl);
|
|
68
|
+
if (bundledUI5Version == null || sapUiFlDependency && semver.lt(bundledUI5Version, sapUiFlDependency.version)) {
|
|
69
|
+
if (sapUiFlDependency.version) {
|
|
70
|
+
log.info(`[ROLLUP] New UI5 version ${sapUiFlDependency.version.toString()} available to bundle`);
|
|
71
|
+
}
|
|
72
|
+
const inputOptions = <rollup.RollupOptions>{
|
|
73
|
+
input: "bundleDefinition.js",
|
|
74
|
+
plugins: [
|
|
75
|
+
ui5({
|
|
76
|
+
assets: [
|
|
77
|
+
"/resources/sap/ui/fl/**",
|
|
78
|
+
"/resources/sap/suite/ui/generic/template/**"
|
|
79
|
+
],
|
|
80
|
+
skipTransformation: [
|
|
81
|
+
"bundleDefinition.js",
|
|
82
|
+
"sap/ui/thirdparty/URI"
|
|
83
|
+
],
|
|
84
|
+
output: destination,
|
|
85
|
+
project: project,
|
|
86
|
+
ui5version: sapUiFlDependency.version
|
|
87
|
+
}),
|
|
88
|
+
nodeResolve({
|
|
89
|
+
preferBuiltins: true
|
|
90
|
+
})
|
|
91
|
+
],
|
|
92
|
+
external: builtins
|
|
93
|
+
}
|
|
94
|
+
const bundle = await rollup.rollup(inputOptions);
|
|
95
|
+
|
|
96
|
+
const outputOptions = <rollup.RollupOptions>{
|
|
97
|
+
file: destination,
|
|
98
|
+
format: "commonjs"
|
|
99
|
+
}
|
|
100
|
+
await bundle.write(outputOptions);
|
|
101
|
+
await bundle.close();
|
|
102
|
+
} else {
|
|
103
|
+
log.info(`[ROLLUP] UI5 version ${bundledUI5Version!.toString()} is already bundled`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (process.argv.length === 3) {
|
|
110
|
+
Builder.run(process.argv[2]);
|
|
111
|
+
}
|