@sap-ux/adp-tooling 0.5.5 → 0.6.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.
|
@@ -7,7 +7,8 @@ import type { MergedAppDescriptor } from '@sap-ux/axios-extension';
|
|
|
7
7
|
import type { AdpPreviewConfig, DescriptorVariant } from '../types';
|
|
8
8
|
export declare const enum ApiRoutes {
|
|
9
9
|
FRAGMENT = "/adp/api/fragment",
|
|
10
|
-
CONTROLLER = "/adp/api/controller"
|
|
10
|
+
CONTROLLER = "/adp/api/controller",
|
|
11
|
+
CODE_EXT = "/adp/api/code_ext/:controllerName"
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Instance of an adaptation project handling requests and data transformation.
|
|
@@ -126,6 +126,7 @@ class AdpPreview {
|
|
|
126
126
|
router.post("/adp/api/fragment" /* ApiRoutes.FRAGMENT */, express_1.default.json(), this.routesHandler.handleWriteFragment);
|
|
127
127
|
router.get("/adp/api/controller" /* ApiRoutes.CONTROLLER */, this.routesHandler.handleReadAllControllers);
|
|
128
128
|
router.post("/adp/api/controller" /* ApiRoutes.CONTROLLER */, express_1.default.json(), this.routesHandler.handleWriteControllerExt);
|
|
129
|
+
router.get("/adp/api/code_ext/:controllerName" /* ApiRoutes.CODE_EXT */, this.routesHandler.handleGetControllerExtensionData);
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
exports.AdpPreview = AdpPreview;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ReaderCollection } from '@ui5/fs';
|
|
2
1
|
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
2
|
import type { MiddlewareUtils } from '@ui5/server';
|
|
3
|
+
import type { ReaderCollection } from '@ui5/fs';
|
|
4
4
|
import type { NextFunction, Request, Response } from 'express';
|
|
5
5
|
/**
|
|
6
6
|
* @description Handles API Routes
|
|
@@ -65,6 +65,14 @@ export default class RoutesHandler {
|
|
|
65
65
|
* @param next Next Function
|
|
66
66
|
*/
|
|
67
67
|
handleReadAllControllers: (_: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Handler for retrieving existing controller extension data from the workspace.
|
|
70
|
+
*
|
|
71
|
+
* @param req Request
|
|
72
|
+
* @param res Response
|
|
73
|
+
* @param next Next Function
|
|
74
|
+
*/
|
|
75
|
+
handleGetControllerExtensionData: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
68
76
|
/**
|
|
69
77
|
* Handler for writing a controller extension file to the workspace.
|
|
70
78
|
*
|
|
@@ -36,9 +36,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const fs = __importStar(require("fs"));
|
|
39
|
+
const os = __importStar(require("os"));
|
|
39
40
|
const path = __importStar(require("path"));
|
|
40
|
-
const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
|
|
41
41
|
const ejs_1 = require("ejs");
|
|
42
|
+
const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
|
|
42
43
|
/**
|
|
43
44
|
* @description Handles API Routes
|
|
44
45
|
*/
|
|
@@ -141,6 +142,58 @@ class RoutesHandler {
|
|
|
141
142
|
this.handleErrorMessage(res, next, e);
|
|
142
143
|
}
|
|
143
144
|
});
|
|
145
|
+
/**
|
|
146
|
+
* Handler for retrieving existing controller extension data from the workspace.
|
|
147
|
+
*
|
|
148
|
+
* @param req Request
|
|
149
|
+
* @param res Response
|
|
150
|
+
* @param next Next Function
|
|
151
|
+
*/
|
|
152
|
+
this.handleGetControllerExtensionData = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
try {
|
|
154
|
+
const params = req.params;
|
|
155
|
+
const controllerName = (0, sanitize_filename_1.default)(params.controllerName);
|
|
156
|
+
const codeExtFiles = yield this.readAllFilesByGlob('/**/changes/*_codeExt.change');
|
|
157
|
+
let controllerExists = false;
|
|
158
|
+
let controllerPath = '';
|
|
159
|
+
let controllerPathFromRoot = '';
|
|
160
|
+
const project = this.util.getProject();
|
|
161
|
+
const sourcePath = project.getSourcePath();
|
|
162
|
+
const projectName = project.getName();
|
|
163
|
+
const getPath = (projectPath, fileName) => path
|
|
164
|
+
.join(projectPath, "changes" /* FolderNames.Changes */, "coding" /* FolderNames.Coding */, fileName)
|
|
165
|
+
.split(path.sep)
|
|
166
|
+
.join(path.posix.sep);
|
|
167
|
+
for (const file of codeExtFiles) {
|
|
168
|
+
const fileStr = yield file.getString();
|
|
169
|
+
const change = JSON.parse(fileStr);
|
|
170
|
+
if (change.selector.controllerName === controllerName) {
|
|
171
|
+
const fileName = change.content.codeRef.replace('coding/', '');
|
|
172
|
+
controllerPath = getPath(sourcePath, fileName);
|
|
173
|
+
controllerPathFromRoot = getPath(projectName, fileName);
|
|
174
|
+
controllerExists = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (controllerExists && !fs.existsSync(controllerPath)) {
|
|
179
|
+
const errorMsg = `Controller extension file was not found at ${controllerPath}`;
|
|
180
|
+
this.logger.debug(errorMsg);
|
|
181
|
+
res.status(404 /* HttpStatusCodes.NOT_FOUND */).send({ message: errorMsg });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.sendFilesResponse(res, {
|
|
185
|
+
controllerExists,
|
|
186
|
+
controllerPath: os.platform() === 'win32' ? `/${controllerPath}` : controllerPath,
|
|
187
|
+
controllerPathFromRoot
|
|
188
|
+
});
|
|
189
|
+
this.logger.debug(controllerExists
|
|
190
|
+
? `Controller exists at '${controllerPath}'`
|
|
191
|
+
: `Controller with controllerName '${controllerName}' does not exist`);
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
this.handleErrorMessage(res, next, e);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
144
197
|
/**
|
|
145
198
|
* Handler for writing a controller extension file to the workspace.
|
|
146
199
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -49,6 +49,48 @@ export interface Content {
|
|
|
49
49
|
content: object;
|
|
50
50
|
texts?: object;
|
|
51
51
|
}
|
|
52
|
+
interface CommonChangeProperties {
|
|
53
|
+
changeType: string;
|
|
54
|
+
reference: string;
|
|
55
|
+
namespace: string;
|
|
56
|
+
projectId: string;
|
|
57
|
+
moduleName: string;
|
|
58
|
+
support: {
|
|
59
|
+
generator: string;
|
|
60
|
+
sapui5Version: string;
|
|
61
|
+
command?: string;
|
|
62
|
+
};
|
|
63
|
+
originalLanguage: string;
|
|
64
|
+
layer: string;
|
|
65
|
+
fileType: string;
|
|
66
|
+
fileName: string;
|
|
67
|
+
texts: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
export interface AddXMLChange extends CommonChangeProperties {
|
|
70
|
+
changeType: 'addXML';
|
|
71
|
+
creation: string;
|
|
72
|
+
packageName: string;
|
|
73
|
+
content: {
|
|
74
|
+
targetAggregation: string;
|
|
75
|
+
index: number;
|
|
76
|
+
fragmentPath: string;
|
|
77
|
+
};
|
|
78
|
+
selector: {
|
|
79
|
+
id: string;
|
|
80
|
+
idIsLocal: boolean;
|
|
81
|
+
};
|
|
82
|
+
dependentSelector: Record<string, unknown>;
|
|
83
|
+
jsOnly: boolean;
|
|
84
|
+
}
|
|
85
|
+
export interface CodeExtChange extends CommonChangeProperties {
|
|
86
|
+
changeType: 'codeExt';
|
|
87
|
+
content: {
|
|
88
|
+
codeRef: string;
|
|
89
|
+
};
|
|
90
|
+
selector: {
|
|
91
|
+
controllerName: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
52
94
|
export declare const enum FolderNames {
|
|
53
95
|
Changes = "changes",
|
|
54
96
|
Fragments = "fragments",
|
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.
|
|
12
|
+
"version": "0.6.0",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|