@sap-ux/fe-fpm-writer 0.13.6 → 0.14.2

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.
@@ -77,7 +77,7 @@ function generateCustomAction(basePath, actionConfig, fs) {
77
77
  const root = path_1.join(__dirname, '../../templates');
78
78
  // Apply event handler
79
79
  if (config.eventHandler) {
80
- config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler);
80
+ config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler, false, config.typescript);
81
81
  }
82
82
  // enhance manifest with action definition and controller reference
83
83
  const actions = enhanceManifestAndGetActionsElementReference(manifest, config.target);
@@ -13,6 +13,7 @@ export interface FPMConfig {
13
13
  * (Note: if set to false, nothing will be done i.e. FCL is not disabled)
14
14
  */
15
15
  fcl?: boolean;
16
+ typescript?: boolean;
16
17
  }
17
18
  export declare const MIN_VERSION = "1.94.0";
18
19
  /**
package/dist/app/index.js CHANGED
@@ -68,8 +68,9 @@ function enableFPM(basePath, config = {}, fs) {
68
68
  }
69
69
  // replace Component.js
70
70
  if (config.replaceAppComponent) {
71
- const componentTemplate = path_1.join(__dirname, '../../templates/app/Component.js');
72
- fs.copyTpl(componentTemplate, path_1.join(basePath, 'webapp/Component.js'), manifest['sap.app']);
71
+ const ext = config.typescript ? 'ts' : 'js';
72
+ const componentTemplate = path_1.join(__dirname, `../../templates/app/Component.${ext}`);
73
+ fs.copyTpl(componentTemplate, path_1.join(basePath, `webapp/Component.${ext}`), manifest['sap.app']);
73
74
  }
74
75
  return fs;
75
76
  }
@@ -42,7 +42,7 @@ function enhanceConfig(fs, root, data, manifestPath, manifest) {
42
42
  defaults_1.setCommonDefaults(config, manifestPath, manifest);
43
43
  // Apply event handler
44
44
  if (config.eventHandler) {
45
- config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler);
45
+ config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler, false, config.typescript);
46
46
  }
47
47
  // generate column content
48
48
  const content = config.properties && config.properties.length > 0
@@ -8,7 +8,8 @@ import type { EventHandlerConfiguration, InternalCustomElement } from '../common
8
8
  * @param {InternalCustomElement} config - configuration
9
9
  * @param {EventHandlerConfiguration | true | string} [eventHandler] - eventHandler for creation
10
10
  * @param {boolean} [controllerSuffix=false] - append controller suffix to new file
11
+ * @param {boolean} typescript - create Typescript file instead of Javascript
11
12
  * @returns {string} full namespace path to method
12
13
  */
13
- export declare function applyEventHandlerConfiguration(fs: Editor, root: string, config: Partial<InternalCustomElement>, eventHandler: EventHandlerConfiguration | true | string, controllerSuffix?: boolean): string;
14
+ export declare function applyEventHandlerConfiguration(fs: Editor, root: string, config: Partial<InternalCustomElement>, eventHandler: EventHandlerConfiguration | true | string, controllerSuffix?: boolean, typescript?: boolean): string;
14
15
  //# sourceMappingURL=event-handler.d.ts.map
@@ -11,9 +11,10 @@ const utils_1 = require("../common/utils");
11
11
  * @param {InternalCustomElement} config - configuration
12
12
  * @param {EventHandlerConfiguration | true | string} [eventHandler] - eventHandler for creation
13
13
  * @param {boolean} [controllerSuffix=false] - append controller suffix to new file
14
+ * @param {boolean} typescript - create Typescript file instead of Javascript
14
15
  * @returns {string} full namespace path to method
15
16
  */
16
- function applyEventHandlerConfiguration(fs, root, config, eventHandler, controllerSuffix = false) {
17
+ function applyEventHandlerConfiguration(fs, root, config, eventHandler, controllerSuffix = false, typescript) {
17
18
  if (typeof eventHandler === 'string') {
18
19
  // Existing event handler is passed - no need for file creation/update
19
20
  return eventHandler;
@@ -33,9 +34,10 @@ function applyEventHandlerConfiguration(fs, root, config, eventHandler, controll
33
34
  fileName = eventHandler.fileName;
34
35
  }
35
36
  }
36
- const controllerPath = path_1.join(config.path || '', `${fileName}${controllerSuffix ? '.controller' : ''}.js`);
37
+ const ext = typescript ? 'ts' : 'js';
38
+ const controllerPath = path_1.join(config.path || '', `${fileName}${controllerSuffix ? '.controller' : ''}.${ext}`);
37
39
  if (!fs.exists(controllerPath)) {
38
- fs.copyTpl(path_1.join(root, 'common/EventHandler.js'), controllerPath, {
40
+ fs.copyTpl(path_1.join(root, `common/EventHandler.${ext}`), controllerPath, {
39
41
  eventHandlerFnName
40
42
  });
41
43
  }
@@ -21,6 +21,10 @@ export interface CustomElement {
21
21
  * If nothing can be generated for the given version then an exception is thrown.
22
22
  */
23
23
  ui5Version?: number;
24
+ /**
25
+ * If set to true then all code snippets are generated in Typescript instead of Javascript.
26
+ */
27
+ typescript?: boolean;
24
28
  }
25
29
  export interface InternalCustomElement extends CustomElement {
26
30
  ns: string;
@@ -72,9 +72,10 @@ function generate(basePath, data, fs) {
72
72
  if (!fs.exists(viewPath)) {
73
73
  fs.copyTpl(path_1.join(root, 'ext/View.xml'), viewPath, config);
74
74
  }
75
- const controllerPath = path_1.join(config.path, `${config.name}.controller.js`);
75
+ const ext = data.typescript ? 'ts' : 'js';
76
+ const controllerPath = path_1.join(config.path, `${config.name}.controller.${ext}`);
76
77
  if (!fs.exists(controllerPath)) {
77
- fs.copyTpl(path_1.join(root, 'ext/Controller.js'), controllerPath, config);
78
+ fs.copyTpl(path_1.join(root, `ext/Controller.${ext}`), controllerPath, config);
78
79
  }
79
80
  return fs;
80
81
  }
@@ -39,7 +39,7 @@ function enhanceConfig(fs, root, data, manifestPath, manifest) {
39
39
  defaults_1.setCommonDefaults(config, manifestPath, manifest);
40
40
  // Apply event handler
41
41
  if (config.eventHandler) {
42
- config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler);
42
+ config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler, false, config.typescript);
43
43
  }
44
44
  // generate section content
45
45
  config.content = config.control || defaults_1.getDefaultFragmentContent(config.name, config.eventHandler);
@@ -24,7 +24,7 @@ function enhanceConfig(fs, root, data, manifestPath, manifest) {
24
24
  defaults_1.setCommonDefaults(config, manifestPath, manifest);
25
25
  // Apply event handler
26
26
  if (config.eventHandler) {
27
- config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler, true);
27
+ config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, root, config, config.eventHandler, true, config.typescript);
28
28
  }
29
29
  // existing views
30
30
  const existingViews = (_e = (_d = ((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets) === null || _c === void 0 ? void 0 : _c[data.target])
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/fe-fpm-writer",
3
3
  "description": "SAP Fiori elements flexible programming model writer",
4
- "version": "0.13.6",
4
+ "version": "0.14.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -9,14 +9,5 @@ sap.ui.define(
9
9
  metadata: {
10
10
  manifest: "json"
11
11
  }
12
-
13
- /**
14
- * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
15
- * @public
16
- * @override
17
- */
18
- //init: function() {
19
- // AppComponent.prototype.init.apply(this, arguments);
20
- //}
21
12
  });
22
13
  });
@@ -0,0 +1,11 @@
1
+ import AppComponent from 'sap/fe/core/AppComponent';
2
+
3
+ /**
4
+ * @namespace <%- id %>
5
+ */
6
+ export default class Component extends AppComponent {
7
+
8
+ public static metadata = {
9
+ manifest: "json"
10
+ };
11
+ }
@@ -0,0 +1,5 @@
1
+ import MessageToast from 'sap/m/MessageToast';
2
+
3
+ export function <%- (typeof eventHandlerFnName !== 'undefined' && eventHandlerFnName) || 'onPress' %>() {
4
+ MessageToast.show("Custom handler invoked.");
5
+ }
@@ -0,0 +1,42 @@
1
+ import Controller from 'sap/ui/core/mvc/Controller'; /** If UI5 version 1.94 or newer can be used, the change the base controller to sap/fe/core/PageController to get full FEv4 FPM support */
2
+
3
+ /**
4
+ * @namespace <%- ns %>.<%- name %>.controller
5
+ */
6
+ export default class <%- name %> extends Controller {
7
+
8
+ /**
9
+ * Called when a controller is instantiated and its View controls (if available) are already created.
10
+ * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
11
+ * @memberOf <%- ns %>.<%- name %>
12
+ */
13
+ // public onInit(): void {
14
+ //
15
+ //}
16
+
17
+ /**
18
+ * Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
19
+ * (NOT before the first rendering! onInit() is used for that one!).
20
+ * @memberOf <%- ns %>.<%- name %>
21
+ */
22
+ // public onBeforeRendering(): void {
23
+ //
24
+ // },
25
+
26
+ /**
27
+ * Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
28
+ * This hook is the same one that SAPUI5 controls get after being rendered.
29
+ * @memberOf <%- ns %>.<%- name %>
30
+ */
31
+ // public onAfterRendering(): void {
32
+ //
33
+ // },
34
+
35
+ /**
36
+ * Called when the Controller is destroyed. Use this one to free resources and finalize activities.
37
+ * @memberOf <%- ns %>.<%- name %>
38
+ */
39
+ // public onExit(): void {
40
+ //
41
+ // }
42
+ }
@@ -0,0 +1,42 @@
1
+ import Controller from 'sap/fe/core/PageController';
2
+
3
+ /**
4
+ * @namespace <%- ns %>.<%- name %>.controller
5
+ */
6
+ export default class <%- name %> extends Controller {
7
+
8
+ /**
9
+ * Called when a controller is instantiated and its View controls (if available) are already created.
10
+ * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
11
+ * @memberOf <%- ns %>.<%- name %>
12
+ */
13
+ // public onInit(): void {
14
+ //
15
+ //}
16
+
17
+ /**
18
+ * Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
19
+ * (NOT before the first rendering! onInit() is used for that one!).
20
+ * @memberOf <%- ns %>.<%- name %>
21
+ */
22
+ // public onBeforeRendering(): void {
23
+ //
24
+ // },
25
+
26
+ /**
27
+ * Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
28
+ * This hook is the same one that SAPUI5 controls get after being rendered.
29
+ * @memberOf <%- ns %>.<%- name %>
30
+ */
31
+ // public onAfterRendering(): void {
32
+ //
33
+ // },
34
+
35
+ /**
36
+ * Called when the Controller is destroyed. Use this one to free resources and finalize activities.
37
+ * @memberOf <%- ns %>.<%- name %>
38
+ */
39
+ // public onExit(): void {
40
+ //
41
+ // }
42
+ }