@sap-ux/ui5-application-writer 0.16.1 → 0.17.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.
@@ -17,14 +17,7 @@ export declare function packageDefaults(version?: string, description?: string):
17
17
  * @returns - a merged package defintion
18
18
  */
19
19
  export declare function mergePackages(packageA: Partial<Package>, packageB: Partial<Package>): Package;
20
- /**
21
- * Returns an app instance merged with default properties.
22
- *
23
- * @param {App} app - specifies the application properties
24
- * @returns {Partial<App>} the App instance
25
- */
26
- export declare function mergeApp(app: App): App;
27
- export declare enum UI5_DEFAULT {
20
+ export declare const enum UI5_DEFAULT {
28
21
  DEFAULT_UI5_VERSION = "",
29
22
  DEFAULT_LOCAL_UI5_VERSION = "1.95.0",
30
23
  MIN_UI5_VERSION = "1.60.0",
@@ -34,8 +27,16 @@ export declare enum UI5_DEFAULT {
34
27
  OPENUI5_CDN = "https://openui5.hana.ondemand.com",
35
28
  TYPES_VERSION_SINCE = "1.76.0",
36
29
  TYPES_VERSION_PREVIOUS = "1.71.18",
37
- MANIFEST_VERSION = "1.12.0"
30
+ MANIFEST_VERSION = "1.12.0",
31
+ BASE_COMPONENT = "sap/ui/core/UIComponent"
38
32
  }
33
+ /**
34
+ * Returns an app instance merged with default properties.
35
+ *
36
+ * @param {App} app - specifies the application properties
37
+ * @returns {Partial<App>} the App instance
38
+ */
39
+ export declare function mergeApp(app: App): App;
39
40
  export declare const defaultUI5Libs: string[];
40
41
  /**
41
42
  * Merges version properties with the provided UI5 instance.
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSpecTagVersion = exports.mergeUi5 = exports.defaultUI5Libs = exports.UI5_DEFAULT = exports.mergeApp = exports.mergePackages = exports.packageDefaults = void 0;
6
+ exports.getSpecTagVersion = exports.mergeUi5 = exports.defaultUI5Libs = exports.mergeApp = exports.mergePackages = exports.packageDefaults = void 0;
7
7
  const version_to_descriptor_mapping_json_1 = __importDefault(require("./version-to-descriptor-mapping.json")); // from https://github.com/SAP/ui5-manifest/blob/master/mapping.json
8
8
  const ui5Libs_1 = require("./ui5Libs");
9
9
  const semver_1 = __importDefault(require("semver"));
@@ -69,7 +69,7 @@ function mergeApp(app) {
69
69
  version: '0.0.1',
70
70
  title: i18n_1.t('text.defaultAppTitle', { id: app.id }),
71
71
  description: i18n_1.t('text.defaultAppDescription', { id: app.id }),
72
- baseComponent: 'sap/ui/core/UIComponent',
72
+ baseComponent: "sap/ui/core/UIComponent" /* BASE_COMPONENT */,
73
73
  sourceTemplate: {
74
74
  id: (_b = (_a = app.sourceTemplate) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '',
75
75
  version: (_d = (_c = app.sourceTemplate) === null || _c === void 0 ? void 0 : _c.version) !== null && _d !== void 0 ? _d : '',
@@ -80,19 +80,6 @@ function mergeApp(app) {
80
80
  ]);
81
81
  }
82
82
  exports.mergeApp = mergeApp;
83
- var UI5_DEFAULT;
84
- (function (UI5_DEFAULT) {
85
- UI5_DEFAULT["DEFAULT_UI5_VERSION"] = "";
86
- UI5_DEFAULT["DEFAULT_LOCAL_UI5_VERSION"] = "1.95.0";
87
- UI5_DEFAULT["MIN_UI5_VERSION"] = "1.60.0";
88
- UI5_DEFAULT["MIN_LOCAL_SAPUI5_VERSION"] = "1.76.0";
89
- UI5_DEFAULT["MIN_LOCAL_OPENUI5_VERSION"] = "1.52.5";
90
- UI5_DEFAULT["SAPUI5_CDN"] = "https://ui5.sap.com";
91
- UI5_DEFAULT["OPENUI5_CDN"] = "https://openui5.hana.ondemand.com";
92
- UI5_DEFAULT["TYPES_VERSION_SINCE"] = "1.76.0";
93
- UI5_DEFAULT["TYPES_VERSION_PREVIOUS"] = "1.71.18";
94
- UI5_DEFAULT["MANIFEST_VERSION"] = "1.12.0";
95
- })(UI5_DEFAULT = exports.UI5_DEFAULT || (exports.UI5_DEFAULT = {}));
96
83
  // Required default libs
97
84
  exports.defaultUI5Libs = ['sap.m', 'sap.ui.core'];
98
85
  /**
@@ -104,9 +91,9 @@ exports.defaultUI5Libs = ['sap.m', 'sap.ui.core'];
104
91
  */
105
92
  function mergeUi5(ui5) {
106
93
  var _a, _b, _c, _d, _e;
107
- const version = (_a = ui5.version) !== null && _a !== void 0 ? _a : UI5_DEFAULT.DEFAULT_UI5_VERSION; // Undefined or null indicates the latest available should be used
94
+ const version = (_a = ui5.version) !== null && _a !== void 0 ? _a : "" /* DEFAULT_UI5_VERSION */; // Undefined or null indicates the latest available should be used
108
95
  const framework = (_b = ui5.framework) !== null && _b !== void 0 ? _b : 'SAPUI5';
109
- const defaultFrameworkUrl = framework === 'SAPUI5' ? UI5_DEFAULT.SAPUI5_CDN : UI5_DEFAULT.OPENUI5_CDN;
96
+ const defaultFrameworkUrl = framework === 'SAPUI5' ? "https://ui5.sap.com" /* SAPUI5_CDN */ : "https://openui5.hana.ondemand.com" /* OPENUI5_CDN */;
110
97
  const merged = {
111
98
  minUI5Version: getMinUI5Version(version, ui5.minUI5Version),
112
99
  localVersion: getLocalVersion({ framework, version, localVersion: ui5.localVersion }),
@@ -116,9 +103,9 @@ function mergeUi5(ui5) {
116
103
  };
117
104
  // typesVersion must be a valid npm semantic version, we know they cannot be null as already validated
118
105
  const localSemVer = semver_1.default.valid(semver_1.default.coerce(merged.localVersion));
119
- const typesVersion = semver_1.default.gte(localSemVer, UI5_DEFAULT.TYPES_VERSION_SINCE)
106
+ const typesVersion = semver_1.default.gte(localSemVer, "1.76.0" /* TYPES_VERSION_SINCE */)
120
107
  ? localSemVer
121
- : UI5_DEFAULT.TYPES_VERSION_PREVIOUS;
108
+ : "1.71.18" /* TYPES_VERSION_PREVIOUS */;
122
109
  merged.descriptorVersion = getManifestVersion(merged.minUI5Version, ui5.descriptorVersion);
123
110
  merged.typesVersion = (_d = ui5.typesVersion) !== null && _d !== void 0 ? _d : typesVersion;
124
111
  merged.ui5Theme = (_e = ui5.ui5Theme) !== null && _e !== void 0 ? _e : 'sap_fiori_3';
@@ -134,7 +121,7 @@ exports.mergeUi5 = mergeUi5;
134
121
  * @returns minimum UI5 version for manifest
135
122
  */
136
123
  function getMinUI5Version(ui5Version, minUI5Version) {
137
- return minUI5Version !== null && minUI5Version !== void 0 ? minUI5Version : (ui5Version ? ui5Version : UI5_DEFAULT.MIN_UI5_VERSION);
124
+ return minUI5Version !== null && minUI5Version !== void 0 ? minUI5Version : (ui5Version ? ui5Version : "1.60.0" /* MIN_UI5_VERSION */);
138
125
  }
139
126
  /**
140
127
  * Get the manifest descriptor version from the specified UI5 version.
@@ -188,7 +175,7 @@ function getManifestVersion(ui5Version, manifestVersion) {
188
175
  }
189
176
  return matchVersion;
190
177
  };
191
- return (_a = manifestVersion !== null && manifestVersion !== void 0 ? manifestVersion : (ui5SemVer && getClosestManifestVersion(ui5SemVer))) !== null && _a !== void 0 ? _a : UI5_DEFAULT.MANIFEST_VERSION;
178
+ return (_a = manifestVersion !== null && manifestVersion !== void 0 ? manifestVersion : (ui5SemVer && getClosestManifestVersion(ui5SemVer))) !== null && _a !== void 0 ? _a : "1.12.0" /* MANIFEST_VERSION */;
192
179
  }
193
180
  /**
194
181
  * If a specific local version is provided, use it, otherwise, sync with version but keep minimum versions in mind.
@@ -204,10 +191,10 @@ function getLocalVersion({ framework, version, localVersion }) {
204
191
  if (localVersion) {
205
192
  return localVersion;
206
193
  }
207
- else if (version === UI5_DEFAULT.DEFAULT_UI5_VERSION) {
208
- return UI5_DEFAULT.DEFAULT_LOCAL_UI5_VERSION;
194
+ else if (version === "" /* DEFAULT_UI5_VERSION */) {
195
+ return "1.95.0" /* DEFAULT_LOCAL_UI5_VERSION */;
209
196
  }
210
- let result = framework === 'SAPUI5' ? UI5_DEFAULT.MIN_LOCAL_SAPUI5_VERSION : UI5_DEFAULT.MIN_LOCAL_OPENUI5_VERSION; // minimum version available as local libs
197
+ let result = framework === 'SAPUI5' ? "1.76.0" /* MIN_LOCAL_SAPUI5_VERSION */ : "1.52.5" /* MIN_LOCAL_OPENUI5_VERSION */; // minimum version available as local libs
211
198
  // If the ui5 `version` is higher than the min framework version 'result' then use that as the local version instead
212
199
  // Update to a valid coerced version string e.g. snapshot-1.80 -> 1.80.0. Cannot be null as previously validated.
213
200
  const versionSemVer = semver_1.default.coerce(version);
@@ -17,6 +17,7 @@ function mergeWithDefaults(ui5App) {
17
17
  ui5App.ui5 = defaults_1.mergeUi5(ui5App.ui5 || {});
18
18
  ui5App.package = defaults_1.mergePackages(defaults_1.packageDefaults(ui5App.package.version, ui5App.app.description), ui5App.package);
19
19
  if (ui5App.appOptions.sapux) {
20
+ ui5App.package.devDependencies = ui5App.package.devDependencies || {};
20
21
  ui5App.package.devDependencies['@sap/ux-specification'] = defaults_1.getSpecTagVersion(ui5App.ui5.version);
21
22
  }
22
23
  return ui5App;
@@ -6,45 +6,42 @@
6
6
  */
7
7
  export declare const getUI5Libs: (ui5Libs?: string | string[] | undefined) => string[];
8
8
  /**
9
- * UI5 tasks configurations required for TypeScript projects
9
+ * UI5 task and middleware configurations required for TypeScript projects
10
10
  */
11
- export declare const ui5TsTasks: ({
12
- name: string;
13
- afterTask: string;
14
- configuration: {
15
- debug?: undefined;
16
- removeConsoleStatements?: undefined;
17
- transpileAsync?: undefined;
18
- transpileTypeScript?: undefined;
11
+ export declare const ui5TSSupport: {
12
+ task: {
13
+ name: string;
14
+ afterTask: string;
15
+ configuration: {
16
+ debug: boolean;
17
+ removeConsoleStatements: boolean;
18
+ transpileAsync: boolean;
19
+ transpileTypeScript: boolean;
20
+ };
19
21
  };
20
- } | {
21
- name: string;
22
- afterTask: string;
23
- configuration: {
24
- debug: boolean;
25
- removeConsoleStatements: boolean;
26
- transpileAsync: boolean;
27
- transpileTypeScript: boolean;
22
+ middleware: {
23
+ name: string;
24
+ afterMiddleware: string;
25
+ configuration: {
26
+ debug: boolean;
27
+ transpileAsync: boolean;
28
+ transpileTypeScript: boolean;
29
+ };
28
30
  };
29
- })[];
31
+ };
30
32
  /**
31
- * UI5 middleware configurations required for TypeScript projects
33
+ * UI5 tasks and middleware configurations required for including npm modules
32
34
  */
33
- export declare const ui5TsMiddlewares: ({
34
- name: string;
35
- afterMiddleware: string;
36
- configuration: {
37
- debug?: undefined;
38
- transpileAsync?: undefined;
39
- transpileTypeScript?: undefined;
35
+ export declare const ui5NPMSupport: {
36
+ task: {
37
+ name: string;
38
+ afterTask: string;
39
+ configuration: {};
40
40
  };
41
- } | {
42
- name: string;
43
- afterMiddleware: string;
44
- configuration: {
45
- debug: boolean;
46
- transpileAsync: boolean;
47
- transpileTypeScript: boolean;
41
+ middleware: {
42
+ name: string;
43
+ afterMiddleware: string;
44
+ configuration: {};
48
45
  };
49
- })[];
46
+ };
50
47
  //# sourceMappingURL=ui5Libs.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ui5TsMiddlewares = exports.ui5TsTasks = exports.getUI5Libs = void 0;
3
+ exports.ui5NPMSupport = exports.ui5TSSupport = exports.getUI5Libs = void 0;
4
4
  const defaults_1 = require("./defaults");
5
5
  /**
6
6
  * Merges the specified ui5 libs with the defaults.
@@ -15,15 +15,10 @@ exports.getUI5Libs = (ui5Libs) => {
15
15
  });
16
16
  };
17
17
  /**
18
- * UI5 tasks configurations required for TypeScript projects
18
+ * UI5 task and middleware configurations required for TypeScript projects
19
19
  */
20
- exports.ui5TsTasks = [
21
- {
22
- name: 'ui5-tooling-modules-task',
23
- afterTask: 'replaceVersion',
24
- configuration: {}
25
- },
26
- {
20
+ exports.ui5TSSupport = {
21
+ task: {
27
22
  name: 'ui5-tooling-transpile-task',
28
23
  afterTask: 'replaceVersion',
29
24
  configuration: {
@@ -32,18 +27,8 @@ exports.ui5TsTasks = [
32
27
  transpileAsync: true,
33
28
  transpileTypeScript: true
34
29
  }
35
- }
36
- ];
37
- /**
38
- * UI5 middleware configurations required for TypeScript projects
39
- */
40
- exports.ui5TsMiddlewares = [
41
- {
42
- name: 'ui5-tooling-modules-middleware',
43
- afterMiddleware: 'compression',
44
- configuration: {}
45
30
  },
46
- {
31
+ middleware: {
47
32
  name: 'ui5-tooling-transpile-middleware',
48
33
  afterMiddleware: 'compression',
49
34
  configuration: {
@@ -52,5 +37,20 @@ exports.ui5TsMiddlewares = [
52
37
  transpileTypeScript: true
53
38
  }
54
39
  }
55
- ];
40
+ };
41
+ /**
42
+ * UI5 tasks and middleware configurations required for including npm modules
43
+ */
44
+ exports.ui5NPMSupport = {
45
+ task: {
46
+ name: 'ui5-tooling-modules-task',
47
+ afterTask: 'replaceVersion',
48
+ configuration: {}
49
+ },
50
+ middleware: {
51
+ name: 'ui5-tooling-modules-middleware',
52
+ afterMiddleware: 'compression',
53
+ configuration: {}
54
+ }
55
+ };
56
56
  //# sourceMappingURL=ui5Libs.js.map
package/dist/index.d.ts CHANGED
@@ -4,12 +4,28 @@ import { Ui5App } from './types';
4
4
  /**
5
5
  * Writes the template to the memfs editor instance.
6
6
  *
7
- * @param {string} basePath - the base path
8
- * @param {Ui5App} ui5AppConfig - the Ui5App instance
9
- * @param {Editor} [fs] - the memfs editor instance
10
- * @returns {*} {Promise<Editor>} the updated memfs editor instance
7
+ * @param basePath - the base path
8
+ * @param ui5AppConfig - the Ui5App instance
9
+ * @param fs - the memfs editor instance
10
+ * @returns the updated memfs editor instance
11
11
  */
12
12
  declare function generate(basePath: string, ui5AppConfig: Ui5App, fs?: Editor): Promise<Editor>;
13
- export { Ui5App, generate };
13
+ /**
14
+ * Check if Typescript is enabled for the given path.
15
+ *
16
+ * @param basePath - the base path
17
+ * @param fs - the memfs editor instance
18
+ * @returns true is the project is ready for typescript code
19
+ */
20
+ declare function isTypescriptEnabled(basePath: string, fs?: Editor): Promise<boolean>;
21
+ /**
22
+ * Enable typescript in an existing valid UI5 project.
23
+ *
24
+ * @param basePath - the base path
25
+ * @param fs - the memfs editor instance
26
+ * @returns the updated memfs editor instance
27
+ */
28
+ declare function enableTypescript(basePath: string, fs?: Editor): Promise<Editor>;
29
+ export { Ui5App, generate, enableTypescript, isTypescriptEnabled };
14
30
  export { App, Package, UI5, AppOptions };
15
31
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -9,23 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.generate = void 0;
12
+ exports.isTypescriptEnabled = exports.enableTypescript = exports.generate = void 0;
13
13
  const path_1 = require("path");
14
- const data_1 = require("./data");
15
14
  const mem_fs_1 = require("mem-fs");
16
15
  const mem_fs_editor_1 = require("mem-fs-editor");
17
- const json_merger_1 = require("json-merger");
18
- const ejs_1 = require("ejs");
19
- const files_1 = require("./files");
20
16
  const ui5_config_1 = require("@sap-ux/ui5-config");
17
+ const data_1 = require("./data");
21
18
  const ui5Libs_1 = require("./data/ui5Libs");
19
+ const options_1 = require("./options");
22
20
  /**
23
21
  * Writes the template to the memfs editor instance.
24
22
  *
25
- * @param {string} basePath - the base path
26
- * @param {Ui5App} ui5AppConfig - the Ui5App instance
27
- * @param {Editor} [fs] - the memfs editor instance
28
- * @returns {*} {Promise<Editor>} the updated memfs editor instance
23
+ * @param basePath - the base path
24
+ * @param ui5AppConfig - the Ui5App instance
25
+ * @param fs - the memfs editor instance
26
+ * @returns the updated memfs editor instance
29
27
  */
30
28
  function generate(basePath, ui5AppConfig, fs) {
31
29
  var _a, _b;
@@ -55,36 +53,7 @@ function generate(basePath, ui5AppConfig, fs) {
55
53
  ui5LocalConfig.addUI5Framework(ui5App.ui5.framework, ui5App.ui5.localVersion, ui5App.ui5.ui5Libs, ui5App.ui5.ui5Theme);
56
54
  ui5LocalConfig.addFioriToolsAppReloadMiddleware();
57
55
  // Add optional features
58
- if (ui5App.appOptions) {
59
- Object.entries(ui5App.appOptions).forEach(([key, value]) => {
60
- if (value === true) {
61
- const optTmplDirPath = path_1.join(tmplPath, 'optional', `${key}`);
62
- const optTmplFilePaths = files_1.getFilePaths(optTmplDirPath);
63
- optTmplFilePaths.forEach((optTmplFilePath) => {
64
- const relPath = optTmplFilePath.replace(optTmplDirPath, '');
65
- const outPath = path_1.join(basePath, relPath);
66
- // Extend or add
67
- if (!(fs === null || fs === void 0 ? void 0 : fs.exists(outPath))) {
68
- fs === null || fs === void 0 ? void 0 : fs.copyTpl(optTmplFilePath, outPath, ui5App, undefined, {
69
- globOptions: { dot: true }
70
- });
71
- }
72
- else {
73
- const add = JSON.parse(ejs_1.render(fs === null || fs === void 0 ? void 0 : fs.read(optTmplFilePath), ui5App, {}));
74
- const existingFile = JSON.parse(fs === null || fs === void 0 ? void 0 : fs.read(outPath));
75
- const merged = json_merger_1.mergeObjects([existingFile, add], { defaultArrayMergeOperation: 'concat' });
76
- fs === null || fs === void 0 ? void 0 : fs.writeJSON(outPath, merged);
77
- }
78
- });
79
- }
80
- });
81
- if (ui5App.appOptions.typescript) {
82
- ui5Config.addCustomMiddleware(ui5Libs_1.ui5TsMiddlewares);
83
- ui5Config.addCustomTasks(ui5Libs_1.ui5TsTasks);
84
- ui5LocalConfig.addCustomMiddleware(ui5Libs_1.ui5TsMiddlewares);
85
- ui5LocalConfig.addCustomTasks(ui5Libs_1.ui5TsTasks);
86
- }
87
- }
56
+ options_1.applyOptionalFeatures(ui5App, fs, basePath, tmplPath, [ui5Config, ui5LocalConfig]);
88
57
  // write ui5 yamls
89
58
  fs.write(ui5ConfigPath, ui5Config.toString());
90
59
  fs.write(ui5LocalConfigPath, ui5LocalConfig.toString());
@@ -92,4 +61,57 @@ function generate(basePath, ui5AppConfig, fs) {
92
61
  });
93
62
  }
94
63
  exports.generate = generate;
64
+ /**
65
+ * Check if Typescript is enabled for the given path.
66
+ *
67
+ * @param basePath - the base path
68
+ * @param fs - the memfs editor instance
69
+ * @returns true is the project is ready for typescript code
70
+ */
71
+ function isTypescriptEnabled(basePath, fs) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ if (!fs) {
74
+ fs = mem_fs_editor_1.create(mem_fs_1.create());
75
+ }
76
+ // check middlewares and tasks
77
+ const ui5Config = yield ui5_config_1.UI5Config.newInstance(fs.read(path_1.join(basePath, 'ui5.yaml')));
78
+ if (!ui5Config.findCustomMiddleware(ui5Libs_1.ui5TSSupport.middleware.name)) {
79
+ return false;
80
+ }
81
+ if (!ui5Config.findCustomTask(ui5Libs_1.ui5TSSupport.task.name)) {
82
+ return false;
83
+ }
84
+ return true;
85
+ });
86
+ }
87
+ exports.isTypescriptEnabled = isTypescriptEnabled;
88
+ /**
89
+ * Enable typescript in an existing valid UI5 project.
90
+ *
91
+ * @param basePath - the base path
92
+ * @param fs - the memfs editor instance
93
+ * @returns the updated memfs editor instance
94
+ */
95
+ function enableTypescript(basePath, fs) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ if (!fs) {
98
+ fs = mem_fs_editor_1.create(mem_fs_1.create());
99
+ }
100
+ const manifestPath = path_1.join(basePath, 'webapp/manifest.json');
101
+ const ui5ConfigPath = path_1.join(basePath, 'ui5.yaml');
102
+ if (!fs.exists(manifestPath)) {
103
+ throw new Error(`Invalid project folder. Cannot find required file ${manifestPath}`);
104
+ }
105
+ if (!fs.exists(ui5ConfigPath)) {
106
+ throw new Error(`Invalid project folder. Cannot find required file ${ui5ConfigPath}`);
107
+ }
108
+ const manifest = fs.readJSON(manifestPath);
109
+ const ui5Config = yield ui5_config_1.UI5Config.newInstance(fs.read(ui5ConfigPath));
110
+ const tmplPath = path_1.join(__dirname, '..', 'templates');
111
+ options_1.enableTypescript({ basePath, fs, ui5Configs: [ui5Config], tmplPath, ui5App: { app: manifest['sap.app'] } }, true);
112
+ fs.write(ui5ConfigPath, ui5Config.toString());
113
+ return fs;
114
+ });
115
+ }
116
+ exports.enableTypescript = enableTypescript;
95
117
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,42 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { Ui5App } from './types';
3
+ import type { UI5Config } from '@sap-ux/ui5-config';
4
+ /**
5
+ * Input required to enable optional features.
6
+ */
7
+ export interface FeatureInput {
8
+ ui5App: {
9
+ app: {
10
+ id: string;
11
+ baseComponent?: string;
12
+ };
13
+ };
14
+ fs: Editor;
15
+ basePath: string;
16
+ tmplPath: string;
17
+ ui5Configs: UI5Config[];
18
+ }
19
+ /**
20
+ * Enable typescript for the given input.
21
+ *
22
+ * @param input Input required to enable the optional typescript features
23
+ * @param keepOldComponent if set to true then the old Component.js will be renamed but kept.
24
+ */
25
+ export declare function enableTypescript(input: FeatureInput, keepOldComponent?: boolean): void;
26
+ /**
27
+ * Enable npm module import for the given input.
28
+ *
29
+ * @param input Input required to enable the optional npm modules import
30
+ */
31
+ export declare function enableNpmPackageConsumption(input: FeatureInput): void;
32
+ /**
33
+ * Check if the ui5 app config requires optional features to be enabled and if yes, enable them.
34
+ *
35
+ * @param ui5App ui5 app config
36
+ * @param fs reference to the mem-fs instance
37
+ * @param basePath project base path
38
+ * @param tmplPath template basepath
39
+ * @param ui5Configs available UI5 configs
40
+ */
41
+ export declare function applyOptionalFeatures(ui5App: Ui5App, fs: Editor, basePath: string, tmplPath: string, ui5Configs: UI5Config[]): void;
42
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyOptionalFeatures = exports.enableNpmPackageConsumption = exports.enableTypescript = void 0;
4
+ const path_1 = require("path");
5
+ const ejs_1 = require("ejs");
6
+ const json_merger_1 = require("json-merger");
7
+ const files_1 = require("./files");
8
+ const ui5Libs_1 = require("./data/ui5Libs");
9
+ /**
10
+ * Copy all template files into the target project.
11
+ *
12
+ * @param name the name of the optional feature
13
+ * @param input collection of input properties
14
+ * @param input.ui5App ui5 app config
15
+ * @param input.fs reference to the mem-fs instance
16
+ * @param input.basePath project base path
17
+ * @param input.tmplPath template basepath
18
+ */
19
+ function copyTemplates(name, { ui5App, fs, basePath, tmplPath }) {
20
+ const optTmplDirPath = path_1.join(tmplPath, 'optional', `${name}`);
21
+ const optTmplFilePaths = files_1.getFilePaths(optTmplDirPath);
22
+ optTmplFilePaths.forEach((optTmplFilePath) => {
23
+ const relPath = optTmplFilePath.replace(optTmplDirPath, '');
24
+ const outPath = path_1.join(basePath, relPath);
25
+ // Extend or add
26
+ if (!(fs === null || fs === void 0 ? void 0 : fs.exists(outPath))) {
27
+ fs === null || fs === void 0 ? void 0 : fs.copyTpl(optTmplFilePath, outPath, ui5App, undefined, {
28
+ globOptions: { dot: true }
29
+ });
30
+ }
31
+ else {
32
+ const add = JSON.parse(ejs_1.render(fs === null || fs === void 0 ? void 0 : fs.read(optTmplFilePath), ui5App, {}));
33
+ const existingFile = JSON.parse(fs === null || fs === void 0 ? void 0 : fs.read(outPath));
34
+ const merged = json_merger_1.mergeObjects([existingFile, add], { defaultArrayMergeOperation: 'concat' });
35
+ fs === null || fs === void 0 ? void 0 : fs.writeJSON(outPath, merged);
36
+ }
37
+ });
38
+ }
39
+ /**
40
+ * Factory functions for applying optional features.
41
+ */
42
+ const factories = {
43
+ codeAssist: (input) => copyTemplates('codeAssist', input),
44
+ eslint: (input) => copyTemplates('eslint', input),
45
+ loadReuseLibs: (input) => copyTemplates('loadReuseLibs', input),
46
+ sapux: (input) => copyTemplates('sapux', input),
47
+ typescript: enableTypescript,
48
+ npmPackageConsumption: enableNpmPackageConsumption
49
+ };
50
+ /**
51
+ * Enable typescript for the given input.
52
+ *
53
+ * @param input Input required to enable the optional typescript features
54
+ * @param keepOldComponent if set to true then the old Component.js will be renamed but kept.
55
+ */
56
+ function enableTypescript(input, keepOldComponent = false) {
57
+ var _a;
58
+ input.ui5App.app.baseComponent = (_a = input.ui5App.app.baseComponent) !== null && _a !== void 0 ? _a : "sap/ui/core/UIComponent" /* BASE_COMPONENT */;
59
+ copyTemplates('typescript', input);
60
+ input.ui5Configs.forEach((ui5Config) => {
61
+ ui5Config.addCustomMiddleware([ui5Libs_1.ui5TSSupport.middleware]);
62
+ ui5Config.addCustomTasks([ui5Libs_1.ui5TSSupport.task]);
63
+ });
64
+ const compPath = path_1.join(input.basePath, 'webapp/Component.js');
65
+ if (keepOldComponent) {
66
+ input.fs.move(compPath, `${compPath}.old`);
67
+ }
68
+ else {
69
+ input.fs.delete(compPath);
70
+ }
71
+ }
72
+ exports.enableTypescript = enableTypescript;
73
+ /**
74
+ * Enable npm module import for the given input.
75
+ *
76
+ * @param input Input required to enable the optional npm modules import
77
+ */
78
+ function enableNpmPackageConsumption(input) {
79
+ copyTemplates('npmPackageConsumption', input);
80
+ input.ui5Configs.forEach((ui5Config) => {
81
+ ui5Config.addCustomMiddleware([ui5Libs_1.ui5NPMSupport.middleware]);
82
+ ui5Config.addCustomTasks([ui5Libs_1.ui5NPMSupport.task]);
83
+ });
84
+ }
85
+ exports.enableNpmPackageConsumption = enableNpmPackageConsumption;
86
+ /**
87
+ * Check if the ui5 app config requires optional features to be enabled and if yes, enable them.
88
+ *
89
+ * @param ui5App ui5 app config
90
+ * @param fs reference to the mem-fs instance
91
+ * @param basePath project base path
92
+ * @param tmplPath template basepath
93
+ * @param ui5Configs available UI5 configs
94
+ */
95
+ function applyOptionalFeatures(ui5App, fs, basePath, tmplPath, ui5Configs) {
96
+ if (ui5App.appOptions) {
97
+ Object.entries(ui5App.appOptions).forEach(([key, value]) => {
98
+ if (value === true) {
99
+ factories[key]({ ui5App, fs, basePath, tmplPath, ui5Configs });
100
+ }
101
+ });
102
+ }
103
+ }
104
+ exports.applyOptionalFeatures = applyOptionalFeatures;
105
+ //# sourceMappingURL=options.js.map
package/dist/types.d.ts CHANGED
@@ -59,6 +59,10 @@ export interface AppOptions {
59
59
  * Enable Typescript support and generate all files in Typescript instead of Javascript
60
60
  */
61
61
  typescript: boolean;
62
+ /**
63
+ * Enable support for importing functionality from npm packages in UI5 applications
64
+ */
65
+ npmPackageConsumption: boolean;
62
66
  }
63
67
  export interface Ui5App {
64
68
  app: App;
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%3Aui5-application-writer"
11
11
  },
12
- "version": "0.16.1",
12
+ "version": "0.17.0",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -20,7 +20,7 @@
20
20
  "!dist/**/*.map"
21
21
  ],
22
22
  "dependencies": {
23
- "@sap-ux/ui5-config": "0.14.5",
23
+ "@sap-ux/ui5-config": "0.15.0",
24
24
  "ejs": "3.1.7",
25
25
  "mem-fs": "2.1.0",
26
26
  "mem-fs-editor": "9.4.0",
@@ -2,6 +2,6 @@
2
2
  "devDependencies": {
3
3
  "eslint": "7.32.0",
4
4
  "@sap/eslint-plugin-ui5-jsdocs": "2.0.5",
5
- "@sapui5/ts-types": "1.92.2"
5
+ "@sapui5/ts-types": "1.102.x"
6
6
  }
7
7
  }
@@ -6,7 +6,7 @@
6
6
  "./node_modules/eslint-plugin-fiori-custom/configure.eslintrc"
7
7
  ],
8
8
  "ignorePatterns": [
9
- "webapp/localservice/**",
9
+ "webapp/localService/**",
10
10
  "webapp/test/**",
11
11
  "dist/**"
12
12
  ]
@@ -0,0 +1,10 @@
1
+ {
2
+ "devDependencies": {
3
+ "ui5-tooling-modules": "^0.6.0"
4
+ },
5
+ "ui5": {
6
+ "dependencies": [
7
+ "ui5-tooling-modules"
8
+ ]
9
+ }
10
+ }
@@ -3,8 +3,7 @@
3
3
  "ts-typecheck": "tsc --noEmit"
4
4
  },
5
5
  "devDependencies": {
6
- "@sapui5/ts-types-esm": "latest",
7
- "ui5-tooling-modules": "^0.6.0",
6
+ "@sapui5/ts-types-esm": "1.102.x",
8
7
  "ui5-tooling-transpile": "^0.2.0",
9
8
  "typescript": "^4.6.3",
10
9
  "@typescript-eslint/eslint-plugin": "^5.17.0",
@@ -12,7 +11,6 @@
12
11
  },
13
12
  "ui5": {
14
13
  "dependencies": [
15
- "ui5-tooling-modules",
16
14
  "ui5-tooling-transpile"
17
15
  ]
18
16
  }