@sap-ux/odata-service-writer 0.12.1 → 0.14.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.
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +80 -52
- package/dist/index.js.map +1 -1
- package/dist/updates.d.ts +20 -0
- package/dist/updates.d.ts.map +1 -0
- package/dist/updates.js +61 -0
- package/dist/updates.js.map +1 -0
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { Editor } from 'mem-fs-editor';
|
|
2
2
|
import { OdataService, OdataVersion } from './types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Try finding a package.json and a ui5.yaml for the given project by looking upwards in the folder hierachy.
|
|
5
5
|
*
|
|
6
|
+
* @param {string} basePath - the root path of an existing UI5 application
|
|
7
|
+
* @param {Editor} [fs] - the memfs editor instance
|
|
8
|
+
* @returns an object with the optional locations of the package.json and ui5.yaml
|
|
9
|
+
*/
|
|
10
|
+
export declare function findProjectFiles(basePath: string, fs: Editor): Promise<{
|
|
11
|
+
packageJson?: string;
|
|
12
|
+
ui5Yaml?: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Writes the odata service related file updates to an existing UI5 project specified by the base path.
|
|
6
16
|
*
|
|
7
17
|
* @param {string} basePath - the root path of an existing UI5 application
|
|
8
18
|
* @param {OdataService} service - the OData service instance
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAQ5C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAiBrD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAQ5C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAiBrD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAClC,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBrD;AAED;;;;;;;;GAQG;AACH,iBAAe,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwF7F;AAED,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,11 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.OdataVersion = exports.generate = void 0;
|
|
15
|
+
exports.OdataVersion = exports.generate = exports.findProjectFiles = void 0;
|
|
16
16
|
const path_1 = require("path");
|
|
17
17
|
const mem_fs_1 = require("mem-fs");
|
|
18
18
|
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
19
|
-
const
|
|
19
|
+
const updates_1 = require("./updates");
|
|
20
20
|
const ui5_config_1 = require("@sap-ux/ui5-config");
|
|
21
21
|
const prettify_xml_1 = __importDefault(require("prettify-xml"));
|
|
22
22
|
const data_1 = require("./data");
|
|
@@ -24,21 +24,46 @@ const i18n_1 = require("./i18n");
|
|
|
24
24
|
const types_1 = require("./types");
|
|
25
25
|
Object.defineProperty(exports, "OdataVersion", { enumerable: true, get: function () { return types_1.OdataVersion; } });
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Ensures the existence of the given files in the provided base path. If a file in the provided list does not exit, an error would be thrown.
|
|
28
28
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
29
|
+
* @param basePath - the root path of an existing UI5 application
|
|
30
|
+
* @param files - list of files that need to exist
|
|
31
|
+
* @param fs - the memfs editor instance
|
|
31
32
|
*/
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
if (!fs.exists(path)) {
|
|
33
|
+
function ensureExists(basePath, files, fs) {
|
|
34
|
+
files.forEach((path) => {
|
|
35
|
+
if (!fs.exists(path_1.join(basePath, path))) {
|
|
35
36
|
throw new Error(i18n_1.t('error.requiredProjectFileNotFound', { path }));
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
+
* Try finding a package.json and a ui5.yaml for the given project by looking upwards in the folder hierachy.
|
|
41
42
|
*
|
|
43
|
+
* @param {string} basePath - the root path of an existing UI5 application
|
|
44
|
+
* @param {Editor} [fs] - the memfs editor instance
|
|
45
|
+
* @returns an object with the optional locations of the package.json and ui5.yaml
|
|
46
|
+
*/
|
|
47
|
+
function findProjectFiles(basePath, fs) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const files = {};
|
|
50
|
+
const parts = basePath.split(path_1.sep);
|
|
51
|
+
while (parts.length > 0 && (!files.packageJson || !files.ui5Yaml)) {
|
|
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');
|
|
55
|
+
}
|
|
56
|
+
if (!files.ui5Yaml && fs.exists(path_1.join(path, 'ui5.yaml'))) {
|
|
57
|
+
files.ui5Yaml = path_1.join(path, 'ui5.yaml');
|
|
58
|
+
}
|
|
59
|
+
parts.pop();
|
|
60
|
+
}
|
|
61
|
+
return files;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.findProjectFiles = findProjectFiles;
|
|
65
|
+
/**
|
|
66
|
+
* Writes the odata service related file updates to an existing UI5 project specified by the base path.
|
|
42
67
|
*
|
|
43
68
|
* @param {string} basePath - the root path of an existing UI5 application
|
|
44
69
|
* @param {OdataService} service - the OData service instance
|
|
@@ -47,56 +72,55 @@ function validateBasePath(basePath, fs) {
|
|
|
47
72
|
* @returns {Promise<Editor>} the updated memfs editor instance
|
|
48
73
|
*/
|
|
49
74
|
function generate(basePath, service, fs) {
|
|
50
|
-
var _a
|
|
75
|
+
var _a;
|
|
51
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
77
|
if (!fs) {
|
|
53
78
|
fs = mem_fs_editor_1.create(mem_fs_1.create());
|
|
54
79
|
}
|
|
55
|
-
|
|
80
|
+
const paths = yield findProjectFiles(basePath, fs);
|
|
81
|
+
ensureExists(basePath, ['webapp/manifest.json'], fs);
|
|
56
82
|
data_1.enhanceData(service);
|
|
57
83
|
// merge content into existing files
|
|
58
|
-
const templateRoot = path_1.join(__dirname, '
|
|
59
|
-
const extRoot = path_1.join(templateRoot, 'extend');
|
|
84
|
+
const templateRoot = path_1.join(__dirname, '../templates');
|
|
60
85
|
// manifest.json
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
updates_1.updateManifest(basePath, service, fs, templateRoot);
|
|
87
|
+
// update ui5.yaml if it exists
|
|
88
|
+
let ui5Config;
|
|
89
|
+
let ui5LocalConfig;
|
|
90
|
+
let ui5LocalConfigPath;
|
|
91
|
+
if (paths.ui5Yaml) {
|
|
92
|
+
ui5Config = yield ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5Yaml));
|
|
93
|
+
try {
|
|
94
|
+
ui5Config.addBackendToFioriToolsProxydMiddleware(service.previewSettings);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error.message === 'error.nodeNotFound') {
|
|
98
|
+
ui5Config.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
fs.write(paths.ui5Yaml, ui5Config.toString());
|
|
105
|
+
// ui5-local.yaml
|
|
106
|
+
ui5LocalConfigPath = path_1.join(path_1.dirname(paths.ui5Yaml), 'ui5-local.yaml');
|
|
107
|
+
if (fs.exists(ui5LocalConfigPath)) {
|
|
108
|
+
ui5LocalConfig = yield ui5_config_1.UI5Config.newInstance(fs.read(ui5LocalConfigPath));
|
|
109
|
+
ui5LocalConfig.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
|
|
110
|
+
}
|
|
69
111
|
}
|
|
70
|
-
const manifestJsonExt = fs.read(path_1.join(extRoot, `manifest.json`));
|
|
71
|
-
fs.extendJSON(manifestPath, JSON.parse(ejs_1.render(manifestJsonExt, service)));
|
|
72
|
-
// ui5.yaml
|
|
73
|
-
const ui5ConfigPath = path_1.join(basePath, 'ui5.yaml');
|
|
74
|
-
const ui5Config = yield ui5_config_1.UI5Config.newInstance(fs.read(ui5ConfigPath));
|
|
75
|
-
ui5Config.addBackendToFioriToolsProxydMiddleware(service.previewSettings);
|
|
76
|
-
// ui5-local.yaml
|
|
77
|
-
const ui5LocalConfigPath = path_1.join(basePath, 'ui5-local.yaml');
|
|
78
|
-
const ui5LocalConfig = yield ui5_config_1.UI5Config.newInstance(fs.read(ui5LocalConfigPath));
|
|
79
|
-
ui5LocalConfig.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
|
|
80
112
|
// Add mockserver entries
|
|
81
113
|
if (service.metadata) {
|
|
82
|
-
// package.json updates
|
|
83
|
-
const mockDevDeps = {
|
|
84
|
-
devDependencies: {
|
|
85
|
-
'@sap/ux-ui5-fe-mockserver-middleware': '1'
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const packagePath = path_1.join(basePath, 'package.json');
|
|
89
|
-
fs.extendJSON(packagePath, mockDevDeps);
|
|
90
|
-
// Extending here would overwrite existing array entries so we have to parse and push
|
|
91
|
-
const packageJson = JSON.parse(fs.read(packagePath));
|
|
92
|
-
packageJson.ui5.dependencies.push('@sap/ux-ui5-fe-mockserver-middleware');
|
|
93
|
-
fs.writeJSON(packagePath, packageJson);
|
|
94
114
|
// copy existing `ui5.yaml` as starting point for ui5-mock.yaml
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
if (ui5Config) {
|
|
116
|
+
const ui5MockConfig = yield ui5_config_1.UI5Config.newInstance(ui5Config.toString());
|
|
117
|
+
ui5MockConfig.addMockServerMiddleware(service.path);
|
|
118
|
+
fs.write(path_1.join(path_1.dirname(paths.ui5Yaml), 'ui5-mock.yaml'), ui5MockConfig.toString());
|
|
119
|
+
// also add mockserver middleware to ui5-local.yaml
|
|
120
|
+
if (ui5LocalConfig) {
|
|
121
|
+
ui5LocalConfig.addMockServerMiddleware(service.path);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
100
124
|
// create local copy of metadata and annotations
|
|
101
125
|
fs.write(path_1.join(basePath, 'webapp', 'localService', 'metadata.xml'), prettify_xml_1.default(service.metadata, { indent: 4 }));
|
|
102
126
|
// Adds local annotations to datasources section of manifest.json and writes the annotations file
|
|
@@ -105,10 +129,14 @@ function generate(basePath, service, fs) {
|
|
|
105
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 }));
|
|
106
130
|
}
|
|
107
131
|
}
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
132
|
+
// update package.json if required
|
|
133
|
+
if (paths.packageJson && paths.ui5Yaml) {
|
|
134
|
+
updates_1.updatePackageJson(paths.packageJson, fs, !!service.metadata);
|
|
135
|
+
}
|
|
136
|
+
if (ui5LocalConfig) {
|
|
137
|
+
fs.write(ui5LocalConfigPath, ui5LocalConfig.toString());
|
|
138
|
+
}
|
|
139
|
+
if ((_a = service.annotations) === null || _a === void 0 ? void 0 : _a.xml) {
|
|
112
140
|
fs.write(path_1.join(basePath, 'webapp', 'localService', `${service.annotations.technicalName}.xml`), prettify_xml_1.default(service.annotations.xml, { indent: 4 }));
|
|
113
141
|
}
|
|
114
142
|
return fs;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAA0C;AAC1C,mCAAiD;AAEjD,iDAAuC;AACvC,uCAA8D;AAE9D,mDAA+C;AAC/C,gEAAuC;AACvC,iCAA8D;AAC9D,iCAA2B;AAC3B,mCAAqD;AAgJlC,6FAhJI,oBAAY,OAgJJ;AA9I/B;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,QAAgB,EAAE,KAAe,EAAE,EAAU;IAC/D,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,WAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,QAAC,CAAC,mCAAmC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;SACrE;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;GAMG;AACH,SAAsB,gBAAgB,CAClC,QAAgB,EAChB,EAAU;;QAEV,MAAM,KAAK,GAA+C,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,UAAG,CAAC,CAAC;QAElC,OAAO,KAAK,CAAC,MAAM,G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MAAM,CAAC,EACpF,sBAAW,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CACtD,CAAC;SACL;QAED,OAAO,EAAE,CAAC;;CACb;AAEQ,4BAAQ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { OdataService } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Internal function that updates the manifest.json based on the given service configuration.
|
|
5
|
+
*
|
|
6
|
+
* @param basePath - the root path of an existing UI5 application
|
|
7
|
+
* @param service - the OData service instance
|
|
8
|
+
* @param fs - the memfs editor instance
|
|
9
|
+
* @param templateRoot - root folder contain the ejs templates
|
|
10
|
+
*/
|
|
11
|
+
export declare function updateManifest(basePath: string, service: OdataService, fs: Editor, templateRoot: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Update the package.json with the required middlewares.
|
|
14
|
+
*
|
|
15
|
+
* @param path path to the package.json
|
|
16
|
+
* @param fs - the memfs editor instance
|
|
17
|
+
* @param addMockServer true if the mocksever middleware needs to be added as well
|
|
18
|
+
*/
|
|
19
|
+
export declare function updatePackageJson(path: string, fs: Editor, addMockServer: boolean): void;
|
|
20
|
+
//# sourceMappingURL=updates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updates.d.ts","sourceRoot":"","sources":["../src/updates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAgBvG;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,QAsBjF"}
|
package/dist/updates.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updatePackageJson = exports.updateManifest = void 0;
|
|
4
|
+
const ejs_1 = require("ejs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const i18n_1 = require("./i18n");
|
|
7
|
+
/**
|
|
8
|
+
* Internal function that updates the manifest.json based on the given service configuration.
|
|
9
|
+
*
|
|
10
|
+
* @param basePath - the root path of an existing UI5 application
|
|
11
|
+
* @param service - the OData service instance
|
|
12
|
+
* @param fs - the memfs editor instance
|
|
13
|
+
* @param templateRoot - root folder contain the ejs templates
|
|
14
|
+
*/
|
|
15
|
+
function updateManifest(basePath, service, fs, templateRoot) {
|
|
16
|
+
var _a;
|
|
17
|
+
// manifest.json
|
|
18
|
+
const manifestPath = path_1.join(basePath, 'webapp', 'manifest.json');
|
|
19
|
+
// Get component app id
|
|
20
|
+
const manifest = fs.readJSON(manifestPath);
|
|
21
|
+
const appProp = 'sap.app';
|
|
22
|
+
const appid = (_a = manifest === null || manifest === void 0 ? void 0 : manifest[appProp]) === null || _a === void 0 ? void 0 : _a.id;
|
|
23
|
+
// Throw if required property is not found manifest.json
|
|
24
|
+
if (!appid) {
|
|
25
|
+
throw new Error(i18n_1.t('error.requiredProjectPropertyNotFound', { property: `'${appProp}'.id`, path: manifestPath }));
|
|
26
|
+
}
|
|
27
|
+
const manifestJsonExt = fs.read(path_1.join(templateRoot, 'extend', `manifest.json`));
|
|
28
|
+
fs.extendJSON(manifestPath, JSON.parse(ejs_1.render(manifestJsonExt, service)));
|
|
29
|
+
}
|
|
30
|
+
exports.updateManifest = updateManifest;
|
|
31
|
+
/**
|
|
32
|
+
* Update the package.json with the required middlewares.
|
|
33
|
+
*
|
|
34
|
+
* @param path path to the package.json
|
|
35
|
+
* @param fs - the memfs editor instance
|
|
36
|
+
* @param addMockServer true if the mocksever middleware needs to be added as well
|
|
37
|
+
*/
|
|
38
|
+
function updatePackageJson(path, fs, addMockServer) {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
const packageJson = JSON.parse(fs.read(path));
|
|
41
|
+
packageJson.devDependencies = (_a = packageJson.devDependencies) !== null && _a !== void 0 ? _a : {};
|
|
42
|
+
packageJson.ui5 = (_b = packageJson.ui5) !== null && _b !== void 0 ? _b : {};
|
|
43
|
+
packageJson.ui5.dependencies = (_c = packageJson.ui5.dependencies) !== null && _c !== void 0 ? _c : [];
|
|
44
|
+
if (!packageJson.devDependencies['@sap/ux-ui5-tooling']) {
|
|
45
|
+
packageJson.devDependencies['@sap/ux-ui5-tooling'] = '1';
|
|
46
|
+
}
|
|
47
|
+
if (!packageJson.ui5.dependencies.includes('@sap/ux-ui5-tooling')) {
|
|
48
|
+
packageJson.ui5.dependencies.push('@sap/ux-ui5-tooling');
|
|
49
|
+
}
|
|
50
|
+
if (addMockServer) {
|
|
51
|
+
if (!packageJson.devDependencies['@sap/ux-ui5-fe-mockserver-middleware']) {
|
|
52
|
+
packageJson.devDependencies['@sap/ux-ui5-fe-mockserver-middleware'] = '1';
|
|
53
|
+
}
|
|
54
|
+
if (!packageJson.ui5.dependencies.includes('@sap/ux-ui5-fe-mockserver-middleware')) {
|
|
55
|
+
packageJson.ui5.dependencies.push('@sap/ux-ui5-fe-mockserver-middleware');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
fs.writeJSON(path, packageJson);
|
|
59
|
+
}
|
|
60
|
+
exports.updatePackageJson = updatePackageJson;
|
|
61
|
+
//# sourceMappingURL=updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updates.js","sourceRoot":"","sources":["../src/updates.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,+BAA4B;AAC5B,iCAA2B;AAG3B;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,QAAgB,EAA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C,qBAAqB,CAAC,EAAE;QACrD,WAAW,CAAC,eAAe,CAAC,qBAAqB,CAAC,GAAG,GAAG,CAAC;KAC5D;IACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE;QAC/D,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;KAC5D;IAED,IAAI,aAAa,EAAE;QACf,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,sCAAsC,CAAC,EAAE;YACtE,WAAW,CAAC,eAAe,CAAC,sCAAsC,CAAC,GAAG,GAAG,CAAC;SAC7E;QACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,sCAAsC,CAAC,EAAE;YAChF,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;SAC7E;KACJ;IACD,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACpC,CAAC;AAtBD,8CAsBC"}
|
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.
|
|
12
|
+
"version": "0.14.0",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"files": [
|
|
@@ -18,24 +18,25 @@
|
|
|
18
18
|
"templates"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@sap-ux/ui5-config": "0.14.0",
|
|
21
22
|
"ejs": "3.1.7",
|
|
23
|
+
"fast-xml-parser": "4.0.1",
|
|
22
24
|
"i18next": "20.3.2",
|
|
23
25
|
"mem-fs": "2.1.0",
|
|
24
26
|
"mem-fs-editor": "9.4.0",
|
|
25
|
-
"
|
|
26
|
-
"prettify-xml": "1.2.0",
|
|
27
|
-
"fast-xml-parser": "4.0.1"
|
|
27
|
+
"prettify-xml": "1.2.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/ejs": "3.1.0",
|
|
31
31
|
"@types/fs-extra": "9.0.13",
|
|
32
|
-
"@types/mem-fs
|
|
32
|
+
"@types/mem-fs": "1.1.2",
|
|
33
|
+
"@types/mem-fs-editor": "7.0.1",
|
|
33
34
|
"fs-extra": "10.0.0",
|
|
34
35
|
"lodash": "4.17.21"
|
|
35
36
|
},
|
|
36
37
|
"engines": {
|
|
37
|
-
"pnpm": ">=6.26.1",
|
|
38
|
-
"node": ">=
|
|
38
|
+
"pnpm": ">=6.26.1 < 7.0.0 || >=7.1.0",
|
|
39
|
+
"node": ">= 14.16.0 < 15.0.0 || >=16.1.0 < 17.0.0 || >=18.0.0 < 19.0.0"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "pnpm clean && tsc",
|
|
@@ -49,6 +50,5 @@
|
|
|
49
50
|
"watch": "tsc --watch",
|
|
50
51
|
"link": "pnpm link --global",
|
|
51
52
|
"unlink": "pnpm unlink --global"
|
|
52
|
-
}
|
|
53
|
-
"readme": "# @sap-ux/odata-service-writer\n\nWrites the odata service related file updates to an existing UI5 project specified by the base path.\n\n\n## Installation\nNpm\n`npm install --save @sap-ux/odata-service-writer`\n\nYarn\n`yarn add @sap-ux/odata-service-writer`\n\nPnpm\n`pnpm add @sap-ux/odata-service-writer`\n\n## Usage\n\n```Typescript\nimport { OdataVersion, OdataService, generate } from '@sap-ux/odata-service-writer';\nimport { create, Editor } from 'mem-fs-editor';\nimport { create as createStorage } from 'mem-fs';\n\n...\n\nfs = create(createStorage()); // Or use fs from Yeoman\n\n const config: OdataService = {\n url: 'http://localhost',\n path: '/sap/odata/testme',\n version: OdataVersion.v4,\n destination: {\n name: 'test'\n }\n };\nconst testDir = '/tmp';\n\nawait generate(testDir, config, fs);\n \n```\n\n## Keywords\nSAP Fiori Freestyle\n"
|
|
53
|
+
}
|
|
54
54
|
}
|