@sap-ux/odata-service-writer 0.14.16 → 0.14.18

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.
@@ -47,7 +47,7 @@ function xmlToJson(xml) {
47
47
  return parser.parse(xml, true);
48
48
  }
49
49
  catch (error) {
50
- throw new Error(i18n_1.t('error.unparseableXML', { error }));
50
+ throw new Error((0, i18n_1.t)('error.unparseableXML', { error }));
51
51
  }
52
52
  }
53
53
  /**
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/index.js CHANGED
@@ -32,8 +32,8 @@ Object.defineProperty(exports, "OdataVersion", { enumerable: true, get: function
32
32
  */
33
33
  function ensureExists(basePath, files, fs) {
34
34
  files.forEach((path) => {
35
- if (!fs.exists(path_1.join(basePath, path))) {
36
- throw new Error(i18n_1.t('error.requiredProjectFileNotFound', { path }));
35
+ if (!fs.exists((0, path_1.join)(basePath, path))) {
36
+ throw new Error((0, i18n_1.t)('error.requiredProjectFileNotFound', { path }));
37
37
  }
38
38
  });
39
39
  }
@@ -50,11 +50,11 @@ function findProjectFiles(basePath, fs) {
50
50
  const parts = basePath.split(path_1.sep);
51
51
  while (parts.length > 0 && (!files.packageJson || !files.ui5Yaml)) {
52
52
  const path = parts.join(path_1.sep);
53
- if (!files.packageJson && fs.exists(path_1.join(path, 'package.json'))) {
54
- files.packageJson = path_1.join(path, 'package.json');
53
+ if (!files.packageJson && fs.exists((0, path_1.join)(path, 'package.json'))) {
54
+ files.packageJson = (0, path_1.join)(path, 'package.json');
55
55
  }
56
- if (!files.ui5Yaml && fs.exists(path_1.join(path, 'ui5.yaml'))) {
57
- files.ui5Yaml = path_1.join(path, 'ui5.yaml');
56
+ if (!files.ui5Yaml && fs.exists((0, path_1.join)(path, 'ui5.yaml'))) {
57
+ files.ui5Yaml = (0, path_1.join)(path, 'ui5.yaml');
58
58
  }
59
59
  parts.pop();
60
60
  }
@@ -75,15 +75,15 @@ function generate(basePath, service, fs) {
75
75
  var _a;
76
76
  return __awaiter(this, void 0, void 0, function* () {
77
77
  if (!fs) {
78
- fs = mem_fs_editor_1.create(mem_fs_1.create());
78
+ fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
79
79
  }
80
80
  const paths = yield findProjectFiles(basePath, fs);
81
81
  ensureExists(basePath, ['webapp/manifest.json'], fs);
82
- data_1.enhanceData(service);
82
+ (0, data_1.enhanceData)(service);
83
83
  // merge content into existing files
84
- const templateRoot = path_1.join(__dirname, '../templates');
84
+ const templateRoot = (0, path_1.join)(__dirname, '../templates');
85
85
  // manifest.json
86
- updates_1.updateManifest(basePath, service, fs, templateRoot);
86
+ (0, updates_1.updateManifest)(basePath, service, fs, templateRoot);
87
87
  // update ui5.yaml if it exists
88
88
  let ui5Config;
89
89
  let ui5LocalConfig;
@@ -103,7 +103,7 @@ function generate(basePath, service, fs) {
103
103
  }
104
104
  fs.write(paths.ui5Yaml, ui5Config.toString());
105
105
  // ui5-local.yaml
106
- ui5LocalConfigPath = path_1.join(path_1.dirname(paths.ui5Yaml), 'ui5-local.yaml');
106
+ ui5LocalConfigPath = (0, path_1.join)((0, path_1.dirname)(paths.ui5Yaml), 'ui5-local.yaml');
107
107
  if (fs.exists(ui5LocalConfigPath)) {
108
108
  ui5LocalConfig = yield ui5_config_1.UI5Config.newInstance(fs.read(ui5LocalConfigPath));
109
109
  ui5LocalConfig.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
@@ -115,29 +115,29 @@ function generate(basePath, service, fs) {
115
115
  if (paths.ui5Yaml && ui5Config) {
116
116
  const ui5MockConfig = yield ui5_config_1.UI5Config.newInstance(ui5Config.toString());
117
117
  ui5MockConfig.addMockServerMiddleware(service.path);
118
- fs.write(path_1.join(path_1.dirname(paths.ui5Yaml), 'ui5-mock.yaml'), ui5MockConfig.toString());
118
+ fs.write((0, path_1.join)((0, path_1.dirname)(paths.ui5Yaml), 'ui5-mock.yaml'), ui5MockConfig.toString());
119
119
  // also add mockserver middleware to ui5-local.yaml
120
120
  if (ui5LocalConfig) {
121
121
  ui5LocalConfig.addMockServerMiddleware(service.path);
122
122
  }
123
123
  }
124
124
  // create local copy of metadata and annotations
125
- fs.write(path_1.join(basePath, 'webapp', 'localService', 'metadata.xml'), prettify_xml_1.default(service.metadata, { indent: 4 }));
125
+ fs.write((0, path_1.join)(basePath, 'webapp', 'localService', 'metadata.xml'), (0, prettify_xml_1.default)(service.metadata, { indent: 4 }));
126
126
  // Adds local annotations to datasources section of manifest.json and writes the annotations file
127
127
  if (service.localAnnotationsName) {
128
- const namespaces = data_1.getAnnotationNamespaces(service);
129
- fs.copyTpl(path_1.join(templateRoot, 'add', 'annotation.xml'), path_1.join(basePath, 'webapp', 'annotations', `${service.localAnnotationsName}.xml`), Object.assign(Object.assign({}, service), { namespaces }));
128
+ const namespaces = (0, data_1.getAnnotationNamespaces)(service);
129
+ fs.copyTpl((0, path_1.join)(templateRoot, 'add', 'annotation.xml'), (0, path_1.join)(basePath, 'webapp', 'annotations', `${service.localAnnotationsName}.xml`), Object.assign(Object.assign({}, service), { namespaces }));
130
130
  }
131
131
  }
132
132
  // update package.json if required
133
133
  if (paths.packageJson && paths.ui5Yaml) {
134
- updates_1.updatePackageJson(paths.packageJson, fs, !!service.metadata);
134
+ (0, updates_1.updatePackageJson)(paths.packageJson, fs, !!service.metadata);
135
135
  }
136
136
  if (ui5LocalConfigPath && ui5LocalConfig) {
137
137
  fs.write(ui5LocalConfigPath, ui5LocalConfig.toString());
138
138
  }
139
139
  if ((_a = service.annotations) === null || _a === void 0 ? void 0 : _a.xml) {
140
- fs.write(path_1.join(basePath, 'webapp', 'localService', `${service.annotations.technicalName}.xml`), prettify_xml_1.default(service.annotations.xml, { indent: 4 }));
140
+ fs.write((0, path_1.join)(basePath, 'webapp', 'localService', `${service.annotations.technicalName}.xml`), (0, prettify_xml_1.default)(service.annotations.xml, { indent: 4 }));
141
141
  }
142
142
  return fs;
143
143
  });
package/dist/updates.d.ts CHANGED
@@ -17,4 +17,11 @@ export declare function updateManifest(basePath: string, service: OdataService,
17
17
  * @param addMockServer true if the mocksever middleware needs to be added as well
18
18
  */
19
19
  export declare function updatePackageJson(path: string, fs: Editor, addMockServer: boolean): void;
20
+ /**
21
+ * Check if dev dependencies contains @ui5/cli version greater than 2.
22
+ *
23
+ * @param devDependencies dev dependencies from package.json
24
+ * @returns boolean
25
+ */
26
+ export declare function hasUI5CliV3(devDependencies: any): boolean;
20
27
  //# sourceMappingURL=updates.d.ts.map
package/dist/updates.js CHANGED
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updatePackageJson = exports.updateManifest = void 0;
6
+ exports.hasUI5CliV3 = exports.updatePackageJson = exports.updateManifest = void 0;
4
7
  const ejs_1 = require("ejs");
5
8
  const path_1 = require("path");
6
9
  const i18n_1 = require("./i18n");
10
+ const semver_1 = __importDefault(require("semver"));
7
11
  /**
8
12
  * Internal function that updates the manifest.json based on the given service configuration.
9
13
  *
@@ -15,19 +19,19 @@ const i18n_1 = require("./i18n");
15
19
  function updateManifest(basePath, service, fs, templateRoot) {
16
20
  var _a;
17
21
  // manifest.json
18
- const manifestPath = path_1.join(basePath, 'webapp', 'manifest.json');
22
+ const manifestPath = (0, path_1.join)(basePath, 'webapp', 'manifest.json');
19
23
  // Get component app id
20
24
  const manifest = fs.readJSON(manifestPath);
21
25
  const appProp = 'sap.app';
22
26
  const appid = (_a = manifest === null || manifest === void 0 ? void 0 : manifest[appProp]) === null || _a === void 0 ? void 0 : _a.id;
23
27
  // Throw if required property is not found manifest.json
24
28
  if (!appid) {
25
- throw new Error(i18n_1.t('error.requiredProjectPropertyNotFound', { property: `'${appProp}'.id`, path: manifestPath }));
29
+ throw new Error((0, i18n_1.t)('error.requiredProjectPropertyNotFound', { property: `'${appProp}'.id`, path: manifestPath }));
26
30
  }
27
- const manifestJsonExt = fs.read(path_1.join(templateRoot, 'extend', `manifest.json`));
31
+ const manifestJsonExt = fs.read((0, path_1.join)(templateRoot, 'extend', `manifest.json`));
28
32
  // If the service object includes ejs options, for example 'client' (see: https://ejs.co/#docs),
29
33
  // resulting in unexpected behaviour and problems when webpacking. Passing an empty options object prevents this.
30
- fs.extendJSON(manifestPath, JSON.parse(ejs_1.render(manifestJsonExt, service, {})));
34
+ fs.extendJSON(manifestPath, JSON.parse((0, ejs_1.render)(manifestJsonExt, service, {})));
31
35
  }
32
36
  exports.updateManifest = updateManifest;
33
37
  /**
@@ -41,25 +45,43 @@ function updatePackageJson(path, fs, addMockServer) {
41
45
  var _a, _b, _c;
42
46
  const packageJson = JSON.parse(fs.read(path));
43
47
  packageJson.devDependencies = (_a = packageJson.devDependencies) !== null && _a !== void 0 ? _a : {};
44
- packageJson.ui5 = (_b = packageJson.ui5) !== null && _b !== void 0 ? _b : {};
45
- packageJson.ui5.dependencies = (_c = packageJson.ui5.dependencies) !== null && _c !== void 0 ? _c : [];
48
+ if (!hasUI5CliV3(packageJson.devDependencies)) {
49
+ packageJson.ui5 = (_b = packageJson.ui5) !== null && _b !== void 0 ? _b : {};
50
+ packageJson.ui5.dependencies = (_c = packageJson.ui5.dependencies) !== null && _c !== void 0 ? _c : [];
51
+ if (!packageJson.ui5.dependencies.includes('@sap/ux-ui5-tooling')) {
52
+ packageJson.ui5.dependencies.push('@sap/ux-ui5-tooling');
53
+ }
54
+ if (addMockServer &&
55
+ !packageJson.ui5.dependencies.includes('@sap/ux-ui5-fe-mockserver-middleware') &&
56
+ !packageJson.ui5.dependencies.includes('@sap-ux/ui5-middleware-fe-mockserver')) {
57
+ packageJson.ui5.dependencies.push('@sap-ux/ui5-middleware-fe-mockserver');
58
+ }
59
+ }
46
60
  if (!packageJson.devDependencies['@sap/ux-ui5-tooling']) {
47
61
  packageJson.devDependencies['@sap/ux-ui5-tooling'] = '1';
48
62
  }
49
- if (!packageJson.ui5.dependencies.includes('@sap/ux-ui5-tooling')) {
50
- packageJson.ui5.dependencies.push('@sap/ux-ui5-tooling');
51
- }
52
63
  if (addMockServer) {
53
64
  if (!packageJson.devDependencies['@sap/ux-ui5-fe-mockserver-middleware'] &&
54
65
  !packageJson.devDependencies['@sap-ux/ui5-middleware-fe-mockserver']) {
55
66
  packageJson.devDependencies['@sap-ux/ui5-middleware-fe-mockserver'] = '2';
56
67
  }
57
- if (!packageJson.ui5.dependencies.includes('@sap/ux-ui5-fe-mockserver-middleware') &&
58
- !packageJson.ui5.dependencies.includes('@sap-ux/ui5-middleware-fe-mockserver')) {
59
- packageJson.ui5.dependencies.push('@sap-ux/ui5-middleware-fe-mockserver');
60
- }
61
68
  }
62
69
  fs.writeJSON(path, packageJson);
63
70
  }
64
71
  exports.updatePackageJson = updatePackageJson;
72
+ /**
73
+ * Check if dev dependencies contains @ui5/cli version greater than 2.
74
+ *
75
+ * @param devDependencies dev dependencies from package.json
76
+ * @returns boolean
77
+ */
78
+ function hasUI5CliV3(devDependencies) {
79
+ let isV3 = false;
80
+ const ui5CliSemver = semver_1.default.coerce(devDependencies['@ui5/cli']);
81
+ if (ui5CliSemver && semver_1.default.gte(ui5CliSemver, '3.0.0')) {
82
+ isV3 = true;
83
+ }
84
+ return isV3;
85
+ }
86
+ exports.hasUI5CliV3 = hasUI5CliV3;
65
87
  //# sourceMappingURL=updates.js.map
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%3Aodata-service-writer"
11
11
  },
12
- "version": "0.14.16",
12
+ "version": "0.14.18",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -20,19 +20,22 @@
20
20
  "!dist/**/*.map"
21
21
  ],
22
22
  "dependencies": {
23
- "@sap-ux/ui5-config": "0.16.3",
23
+ "@sap-ux/ui5-config": "0.16.4",
24
24
  "ejs": "3.1.7",
25
25
  "fast-xml-parser": "4.0.1",
26
26
  "i18next": "20.3.2",
27
27
  "mem-fs": "2.1.0",
28
28
  "mem-fs-editor": "9.4.0",
29
- "prettify-xml": "1.2.0"
29
+ "prettify-xml": "1.2.0",
30
+ "semver": "7.3.5"
30
31
  },
31
32
  "devDependencies": {
33
+ "@sap-ux/project-access": "1.1.3",
32
34
  "@types/ejs": "3.1.0",
33
35
  "@types/fs-extra": "9.0.13",
34
36
  "@types/mem-fs": "1.1.2",
35
37
  "@types/mem-fs-editor": "7.0.1",
38
+ "@types/semver": "7.3.9",
36
39
  "fs-extra": "10.0.0",
37
40
  "lodash": "4.17.21"
38
41
  },