@sap-ux/adp-tooling 0.9.18 → 0.9.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preview/adp-preview.d.ts +13 -2
- package/dist/preview/adp-preview.js +29 -1
- package/dist/preview/change-handler.d.ts +41 -0
- package/dist/preview/change-handler.js +72 -0
- package/dist/preview/routes-handler.d.ts +0 -8
- package/dist/preview/routes-handler.js +0 -41
- package/dist/types.d.ts +2 -1
- package/package.json +2 -2
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import type { ReaderCollection } from '@ui5/fs';
|
|
3
3
|
import type { MiddlewareUtils } from '@ui5/server';
|
|
4
4
|
import type { NextFunction, Request, Response, Router } from 'express';
|
|
5
|
-
import type { ToolsLogger } from '@sap-ux/logger';
|
|
5
|
+
import type { Logger, ToolsLogger } from '@sap-ux/logger';
|
|
6
6
|
import type { UI5FlexLayer } from '@sap-ux/project-access';
|
|
7
7
|
import type { MergedAppDescriptor } from '@sap-ux/axios-extension';
|
|
8
|
-
import type { AdpPreviewConfig, DescriptorVariant } from '../types';
|
|
8
|
+
import type { AdpPreviewConfig, CommonChangeProperties, DescriptorVariant, OperationType } from '../types';
|
|
9
|
+
import type { Editor } from 'mem-fs-editor';
|
|
9
10
|
export declare const enum ApiRoutes {
|
|
10
11
|
FRAGMENT = "/adp/api/fragment",
|
|
11
12
|
CONTROLLER = "/adp/api/controller",
|
|
@@ -89,5 +90,15 @@ export declare class AdpPreview {
|
|
|
89
90
|
* @returns {void} A promise that resolves when the APIs have been added.
|
|
90
91
|
*/
|
|
91
92
|
addApis(router: Router): void;
|
|
93
|
+
/**
|
|
94
|
+
* Handles different types of change requests to project files.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} type - The type of change request.
|
|
97
|
+
* @param {CommonChangeProperties} change - An object containing properties common to all change types.
|
|
98
|
+
* @param {Editor} fs - An instance of an editor interface for file system operations.
|
|
99
|
+
* @param {Logger} logger - An instance of a logging interface for message logging.
|
|
100
|
+
* @returns {Promise<void>} A promise that resolves when the change request has been processed.
|
|
101
|
+
*/
|
|
102
|
+
onChangeRequest(type: OperationType, change: CommonChangeProperties, fs: Editor, logger: Logger): Promise<void>;
|
|
92
103
|
}
|
|
93
104
|
//# sourceMappingURL=adp-preview.d.ts.map
|
|
@@ -16,6 +16,7 @@ exports.AdpPreview = void 0;
|
|
|
16
16
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
17
17
|
const system_access_1 = require("@sap-ux/system-access");
|
|
18
18
|
const routes_handler_1 = __importDefault(require("./routes-handler"));
|
|
19
|
+
const change_handler_1 = require("./change-handler");
|
|
19
20
|
/**
|
|
20
21
|
* Instance of an adaptation project handling requests and data transformation.
|
|
21
22
|
*/
|
|
@@ -146,11 +147,38 @@ class AdpPreview {
|
|
|
146
147
|
*/
|
|
147
148
|
addApis(router) {
|
|
148
149
|
router.get("/adp/api/fragment" /* ApiRoutes.FRAGMENT */, this.routesHandler.handleReadAllFragments);
|
|
149
|
-
router.post("/adp/api/fragment" /* ApiRoutes.FRAGMENT */, this.routesHandler.handleWriteFragment);
|
|
150
150
|
router.get("/adp/api/controller" /* ApiRoutes.CONTROLLER */, this.routesHandler.handleReadAllControllers);
|
|
151
151
|
router.post("/adp/api/controller" /* ApiRoutes.CONTROLLER */, this.routesHandler.handleWriteControllerExt);
|
|
152
152
|
router.get("/adp/api/code_ext/:controllerName" /* ApiRoutes.CODE_EXT */, this.routesHandler.handleGetControllerExtensionData);
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Handles different types of change requests to project files.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} type - The type of change request.
|
|
158
|
+
* @param {CommonChangeProperties} change - An object containing properties common to all change types.
|
|
159
|
+
* @param {Editor} fs - An instance of an editor interface for file system operations.
|
|
160
|
+
* @param {Logger} logger - An instance of a logging interface for message logging.
|
|
161
|
+
* @returns {Promise<void>} A promise that resolves when the change request has been processed.
|
|
162
|
+
*/
|
|
163
|
+
onChangeRequest(type, change, fs, logger) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
switch (type) {
|
|
166
|
+
case 'read':
|
|
167
|
+
if (change_handler_1.moduleNameContentMap[change.changeType] && !change.moduleName) {
|
|
168
|
+
(0, change_handler_1.tryFixChange)(change, logger);
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case 'write':
|
|
172
|
+
if ((0, change_handler_1.isAddXMLChange)(change)) {
|
|
173
|
+
(0, change_handler_1.addXmlFragment)(this.util.getProject().getSourcePath(), change, fs, logger);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
// no need to handle delete changes
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
154
182
|
}
|
|
155
183
|
exports.AdpPreview = AdpPreview;
|
|
156
184
|
//# sourceMappingURL=adp-preview.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { AddXMLChange, CommonChangeProperties } from '../types';
|
|
3
|
+
import type { Logger } from '@sap-ux/logger';
|
|
4
|
+
/**
|
|
5
|
+
* A mapping object that defines how to extract change content data from changes based on their type.
|
|
6
|
+
*/
|
|
7
|
+
export declare const moduleNameContentMap: {
|
|
8
|
+
[key: string]: (change: CommonChangeProperties) => string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Sets the moduleName property of the provided change to also support old changes with newer UI5 versions.
|
|
12
|
+
*
|
|
13
|
+
* @param change change to be fixed
|
|
14
|
+
* @param logger logger instance
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Attempts to fix a change object by setting its moduleName based on its reference and changeType
|
|
18
|
+
* to also support old changes with newer UI5 versions.
|
|
19
|
+
*
|
|
20
|
+
* @param {CommonChangeProperties} change - The change object to be fixed.
|
|
21
|
+
* @param {Logger} logger - An instance for logging warnings, errors, or informational messages.
|
|
22
|
+
*/
|
|
23
|
+
export declare function tryFixChange(change: CommonChangeProperties, logger: Logger): void;
|
|
24
|
+
/**
|
|
25
|
+
* Determines whether a given change is of type `AddXMLChange`.
|
|
26
|
+
*
|
|
27
|
+
* @param {CommonChangeProperties} change - The change object to check.
|
|
28
|
+
* @returns {boolean} `true` if the `changeType` is either 'addXML' or 'addXMLAtExtensionPoint',
|
|
29
|
+
* indicating the change is of type `AddXMLChange`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isAddXMLChange(change: CommonChangeProperties): change is AddXMLChange;
|
|
32
|
+
/**
|
|
33
|
+
* Asynchronously adds an XML fragment to the project if it doesn't already exist.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} basePath - The base path of the project.
|
|
36
|
+
* @param {AddXMLChange} change - The change data, including the fragment path.
|
|
37
|
+
* @param {Editor} fs - The mem-fs-editor instance.
|
|
38
|
+
* @param {Logger} logger - The logging instance.
|
|
39
|
+
*/
|
|
40
|
+
export declare function addXmlFragment(basePath: string, change: AddXMLChange, fs: Editor, logger: Logger): void;
|
|
41
|
+
//# sourceMappingURL=change-handler.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addXmlFragment = exports.isAddXMLChange = exports.tryFixChange = exports.moduleNameContentMap = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
6
|
+
/**
|
|
7
|
+
* A mapping object that defines how to extract change content data from changes based on their type.
|
|
8
|
+
*/
|
|
9
|
+
exports.moduleNameContentMap = {
|
|
10
|
+
codeExt: (change) => { var _a, _b; return ((_b = (_a = change.content) === null || _a === void 0 ? void 0 : _a.codeRef) !== null && _b !== void 0 ? _b : '').replace('.js', ''); },
|
|
11
|
+
addXML: (change) => { var _a, _b; return (_b = (_a = change.content) === null || _a === void 0 ? void 0 : _a.fragmentPath) !== null && _b !== void 0 ? _b : ''; }
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Sets the moduleName property of the provided change to also support old changes with newer UI5 versions.
|
|
15
|
+
*
|
|
16
|
+
* @param change change to be fixed
|
|
17
|
+
* @param logger logger instance
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Attempts to fix a change object by setting its moduleName based on its reference and changeType
|
|
21
|
+
* to also support old changes with newer UI5 versions.
|
|
22
|
+
*
|
|
23
|
+
* @param {CommonChangeProperties} change - The change object to be fixed.
|
|
24
|
+
* @param {Logger} logger - An instance for logging warnings, errors, or informational messages.
|
|
25
|
+
*/
|
|
26
|
+
function tryFixChange(change, logger) {
|
|
27
|
+
try {
|
|
28
|
+
const prefix = change.reference.replace(/\./g, '/');
|
|
29
|
+
change.moduleName = `${prefix}/changes/${exports.moduleNameContentMap[change.changeType](change)}`;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logger.warn('Could not fix missing module name.');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.tryFixChange = tryFixChange;
|
|
36
|
+
/**
|
|
37
|
+
* Determines whether a given change is of type `AddXMLChange`.
|
|
38
|
+
*
|
|
39
|
+
* @param {CommonChangeProperties} change - The change object to check.
|
|
40
|
+
* @returns {boolean} `true` if the `changeType` is either 'addXML' or 'addXMLAtExtensionPoint',
|
|
41
|
+
* indicating the change is of type `AddXMLChange`.
|
|
42
|
+
*/
|
|
43
|
+
function isAddXMLChange(change) {
|
|
44
|
+
return change.changeType === 'addXML' || change.changeType === 'addXMLAtExtensionPoint';
|
|
45
|
+
}
|
|
46
|
+
exports.isAddXMLChange = isAddXMLChange;
|
|
47
|
+
/**
|
|
48
|
+
* Asynchronously adds an XML fragment to the project if it doesn't already exist.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} basePath - The base path of the project.
|
|
51
|
+
* @param {AddXMLChange} change - The change data, including the fragment path.
|
|
52
|
+
* @param {Editor} fs - The mem-fs-editor instance.
|
|
53
|
+
* @param {Logger} logger - The logging instance.
|
|
54
|
+
*/
|
|
55
|
+
function addXmlFragment(basePath, change, fs, logger) {
|
|
56
|
+
const { fragmentPath } = change.content;
|
|
57
|
+
const fullPath = (0, path_1.join)(basePath, project_access_1.DirName.Changes, fragmentPath);
|
|
58
|
+
try {
|
|
59
|
+
if (fs.exists(fullPath)) {
|
|
60
|
+
logger.info(`XML Fragment "${fragmentPath}" already exists.`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const fragmentTemplatePath = (0, path_1.join)(__dirname, '../../templates/rta', "fragment.xml" /* TemplateFileName.Fragment */);
|
|
64
|
+
fs.copy(fragmentTemplatePath, fullPath);
|
|
65
|
+
logger.info(`XML Fragment "${fragmentPath}" was created`);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
logger.error(`Failed to create XML Fragment "${fragmentPath}": ${error}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.addXmlFragment = addXmlFragment;
|
|
72
|
+
//# sourceMappingURL=change-handler.js.map
|
|
@@ -50,14 +50,6 @@ export default class RoutesHandler {
|
|
|
50
50
|
* @param next Next Function
|
|
51
51
|
*/
|
|
52
52
|
handleReadAllFragments: (_: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Handler for writing a fragment file to the workspace.
|
|
55
|
-
*
|
|
56
|
-
* @param req Request
|
|
57
|
-
* @param res Response
|
|
58
|
-
* @param next Next Function
|
|
59
|
-
*/
|
|
60
|
-
handleWriteFragment: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
61
53
|
/**
|
|
62
54
|
* Handler for reading all controller extension files from the workspace.
|
|
63
55
|
*
|
|
@@ -80,47 +80,6 @@ class RoutesHandler {
|
|
|
80
80
|
this.handleErrorMessage(res, next, e);
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
/**
|
|
84
|
-
* Handler for writing a fragment file to the workspace.
|
|
85
|
-
*
|
|
86
|
-
* @param req Request
|
|
87
|
-
* @param res Response
|
|
88
|
-
* @param next Next Function
|
|
89
|
-
*/
|
|
90
|
-
this.handleWriteFragment = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
try {
|
|
92
|
-
const data = req.body;
|
|
93
|
-
const fragmentName = (0, sanitize_filename_1.default)(data.fragmentName);
|
|
94
|
-
const sourcePath = this.util.getProject().getSourcePath();
|
|
95
|
-
if (!fragmentName) {
|
|
96
|
-
res.status(400 /* HttpStatusCodes.BAD_REQUEST */).send('Fragment name was not provided!');
|
|
97
|
-
this.logger.debug('Bad request. Fragment name was not provided!');
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const fullPath = path.join(sourcePath, project_access_1.DirName.Changes, project_access_1.DirName.Fragments);
|
|
101
|
-
const filePath = path.join(fullPath, `${fragmentName}.fragment.xml`);
|
|
102
|
-
if (!fs.existsSync(fullPath)) {
|
|
103
|
-
fs.mkdirSync(fullPath, { recursive: true });
|
|
104
|
-
}
|
|
105
|
-
if (fs.existsSync(filePath)) {
|
|
106
|
-
res.status(409 /* HttpStatusCodes.CONFLICT */).send(`Fragment with name "${fragmentName}" already exists`);
|
|
107
|
-
this.logger.debug(`XML Fragment with name "${fragmentName}" was created`);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
// Copy the template XML Fragment to the project's workspace
|
|
111
|
-
const fragmentTemplatePath = path.join(__dirname, '../../templates/rta', "fragment.xml" /* TemplateFileName.Fragment */);
|
|
112
|
-
fs.copyFileSync(fragmentTemplatePath, filePath);
|
|
113
|
-
const message = 'XML Fragment created';
|
|
114
|
-
res.status(201 /* HttpStatusCodes.CREATED */).send(message);
|
|
115
|
-
this.logger.debug(`XML Fragment with name "${fragmentName}" was created`);
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
const sanitizedMsg = (0, sanitize_filename_1.default)(e.message);
|
|
119
|
-
this.logger.error(sanitizedMsg);
|
|
120
|
-
res.status(500 /* HttpStatusCodes.INTERNAL_SERVER_ERROR */).send(sanitizedMsg);
|
|
121
|
-
next(e);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
83
|
/**
|
|
125
84
|
* Handler for reading all controller extension files from the workspace.
|
|
126
85
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export interface Content {
|
|
|
61
61
|
content: object;
|
|
62
62
|
texts?: object;
|
|
63
63
|
}
|
|
64
|
-
interface CommonChangeProperties {
|
|
64
|
+
export interface CommonChangeProperties {
|
|
65
65
|
changeType: string;
|
|
66
66
|
reference: string;
|
|
67
67
|
namespace: string;
|
|
@@ -135,6 +135,7 @@ export declare const enum HttpStatusCodes {
|
|
|
135
135
|
NOT_IMPLEMETED = 501,
|
|
136
136
|
SERVICE_UNAVAILABLE = 503
|
|
137
137
|
}
|
|
138
|
+
export type OperationType = 'read' | 'write' | 'delete';
|
|
138
139
|
/**
|
|
139
140
|
* Represents a constructor type that creates an instance of IWriter.
|
|
140
141
|
*
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aadp-tooling"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.9.
|
|
12
|
+
"version": "0.9.20",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"prompts": "2.4.2",
|
|
31
31
|
"adm-zip": "0.5.10",
|
|
32
32
|
"@sap-ux/axios-extension": "1.11.7",
|
|
33
|
-
"@sap-ux/project-access": "1.19.
|
|
33
|
+
"@sap-ux/project-access": "1.19.11",
|
|
34
34
|
"@sap-ux/logger": "0.5.1",
|
|
35
35
|
"@sap-ux/system-access": "0.3.21",
|
|
36
36
|
"@sap-ux/ui5-config": "0.22.1",
|