@sap-ux/project-access 1.21.2 → 1.22.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.
@@ -1,4 +1,5 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
+ import type { Manifest, Package } from '../types';
2
3
  /**
3
4
  * Read file asynchronously. Throws error if file does not exist.
4
5
  *
@@ -32,4 +33,20 @@ export declare function writeFile(path: string, content: string, memFs?: Editor)
32
33
  * @returns - true if the file exists; false otherwise.
33
34
  */
34
35
  export declare function fileExists(path: string, memFs?: Editor): Promise<boolean>;
36
+ /**
37
+ * Updates package.json file asynchronously by keeping the previous indentation.
38
+ *
39
+ * @param path - path to file
40
+ * @param packageJson - updated package.json file content
41
+ * @param memFs - optional mem-fs-editor instance
42
+ */
43
+ export declare function updatePackageJSON(path: string, packageJson: Package, memFs?: Editor): Promise<void>;
44
+ /**
45
+ * Updates manifest.json file asynchronously by keeping the previous indentation.
46
+ *
47
+ * @param path - path to file
48
+ * @param manifest - updated manifest.json file content
49
+ * @param memFs - optional mem-fs-editor instance
50
+ */
51
+ export declare function updateManifestJSON(path: string, manifest: Manifest, memFs?: Editor): Promise<void>;
35
52
  //# sourceMappingURL=file-access.d.ts.map
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fileExists = exports.writeFile = exports.readJSON = exports.readFile = void 0;
15
+ exports.updateManifestJSON = exports.updatePackageJSON = exports.fileExists = exports.writeFile = exports.readJSON = exports.readFile = void 0;
13
16
  const fs_1 = require("fs");
17
+ const json_parse_even_better_errors_1 = __importDefault(require("json-parse-even-better-errors"));
14
18
  /**
15
19
  * Read file asynchronously. Throws error if file does not exist.
16
20
  *
@@ -88,4 +92,48 @@ function fileExists(path, memFs) {
88
92
  });
89
93
  }
90
94
  exports.fileExists = fileExists;
95
+ /**
96
+ * Updates package.json file asynchronously by keeping the previous indentation.
97
+ *
98
+ * @param path - path to file
99
+ * @param packageJson - updated package.json file content
100
+ * @param memFs - optional mem-fs-editor instance
101
+ */
102
+ function updatePackageJSON(path, packageJson, memFs) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ yield updateJSON(path, packageJson, memFs);
105
+ });
106
+ }
107
+ exports.updatePackageJSON = updatePackageJSON;
108
+ /**
109
+ * Updates manifest.json file asynchronously by keeping the previous indentation.
110
+ *
111
+ * @param path - path to file
112
+ * @param manifest - updated manifest.json file content
113
+ * @param memFs - optional mem-fs-editor instance
114
+ */
115
+ function updateManifestJSON(path, manifest, memFs) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ yield updateJSON(path, manifest, memFs);
118
+ });
119
+ }
120
+ exports.updateManifestJSON = updateManifestJSON;
121
+ /**
122
+ * Updates JSON file asynchronously by keeping the indentation from previous content with new content for given path.
123
+ *
124
+ * @param path - path to file
125
+ * @param content - updated JSON file content
126
+ * @param memFs - optional mem-fs-editor instance
127
+ */
128
+ function updateJSON(path, content, memFs) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ // read old contents and indentation of the JSON file
131
+ const oldContentText = yield readFile(path, memFs);
132
+ const oldContentJson = (0, json_parse_even_better_errors_1.default)(oldContentText);
133
+ const indent = Symbol.for('indent');
134
+ // prepare new JSON file content with previous indentation
135
+ const result = JSON.stringify(content, null, oldContentJson[indent]) + '\n';
136
+ yield writeFile(path, result, memFs);
137
+ });
138
+ }
91
139
  //# sourceMappingURL=file-access.js.map
@@ -1,3 +1,3 @@
1
- export { fileExists, readFile, readJSON, writeFile } from './file-access';
1
+ export { fileExists, readFile, readJSON, updatePackageJSON, updateManifestJSON, writeFile } from './file-access';
2
2
  export { findBy, findFiles, findFilesByExtension, findFileUp, getFilePaths } from './file-search';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFilePaths = exports.findFileUp = exports.findFilesByExtension = exports.findFiles = exports.findBy = exports.writeFile = exports.readJSON = exports.readFile = exports.fileExists = void 0;
3
+ exports.getFilePaths = exports.findFileUp = exports.findFilesByExtension = exports.findFiles = exports.findBy = exports.writeFile = exports.updateManifestJSON = exports.updatePackageJSON = exports.readJSON = exports.readFile = exports.fileExists = void 0;
4
4
  var file_access_1 = require("./file-access");
5
5
  Object.defineProperty(exports, "fileExists", { enumerable: true, get: function () { return file_access_1.fileExists; } });
6
6
  Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return file_access_1.readFile; } });
7
7
  Object.defineProperty(exports, "readJSON", { enumerable: true, get: function () { return file_access_1.readJSON; } });
8
+ Object.defineProperty(exports, "updatePackageJSON", { enumerable: true, get: function () { return file_access_1.updatePackageJSON; } });
9
+ Object.defineProperty(exports, "updateManifestJSON", { enumerable: true, get: function () { return file_access_1.updateManifestJSON; } });
8
10
  Object.defineProperty(exports, "writeFile", { enumerable: true, get: function () { return file_access_1.writeFile; } });
9
11
  var file_search_1 = require("./file-search");
10
12
  Object.defineProperty(exports, "findBy", { enumerable: true, get: function () { return file_search_1.findBy; } });
@@ -14,6 +14,8 @@ const path_1 = require("path");
14
14
  const i18n_1 = require("./i18n");
15
15
  const info_1 = require("./info");
16
16
  const search_1 = require("./search");
17
+ const file_1 = require("../file");
18
+ const constants_1 = require("../constants");
17
19
  /**
18
20
  *
19
21
  */
@@ -138,6 +140,28 @@ class ApplicationAccessImp {
138
140
  getI18nPropertiesPaths() {
139
141
  return (0, i18n_1.getI18nPropertiesPaths)(this.app.manifest);
140
142
  }
143
+ /**
144
+ * Updates package.json file asynchronously by keeping the previous indentation.
145
+ *
146
+ * @param packageJson - updated package.json file content
147
+ * @param memFs - optional mem-fs-editor instance
148
+ */
149
+ updatePackageJSON(packageJson, memFs) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ yield (0, file_1.updatePackageJSON)((0, path_1.join)(this.app.appRoot, constants_1.FileName.Package), packageJson, memFs);
152
+ });
153
+ }
154
+ /**
155
+ * Updates manifest.json file asynchronously by keeping the previous indentation.
156
+ *
157
+ * @param manifest - updated manifest.json file content
158
+ * @param memFs - optional mem-fs-editor instance
159
+ */
160
+ updateManifestJSON(manifest, memFs) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ yield (0, file_1.updateManifestJSON)(this.app.manifest, manifest, memFs);
163
+ });
164
+ }
141
165
  /**
142
166
  * Project structure.
143
167
  *
@@ -1,6 +1,9 @@
1
1
  import type { I18nBundles } from '../i18n';
2
2
  import type { NewI18nEntry } from '@sap-ux/i18n';
3
3
  import type { ApplicationStructure, I18nPropertiesPaths, Project, ProjectType } from '../info';
4
+ import type { Editor } from 'mem-fs-editor';
5
+ import type { Package } from '../package';
6
+ import type { Manifest } from '../webapp';
4
7
  interface BaseAccess {
5
8
  readonly project: Project;
6
9
  readonly root: string;
@@ -92,6 +95,20 @@ export interface ApplicationAccess extends BaseAccess {
92
95
  * @returns absolute paths to i18n.properties
93
96
  */
94
97
  getI18nPropertiesPaths(): Promise<I18nPropertiesPaths>;
98
+ /**
99
+ * Updates package.json file asynchronously by keeping the previous indentation.
100
+ *
101
+ * @param packageJson - updated package.json file content
102
+ * @param memFs - optional mem-fs-editor instance
103
+ */
104
+ updatePackageJSON(packageJson: Package, memFs?: Editor): Promise<void>;
105
+ /**
106
+ * Updates manifest.json file asynchronously by keeping the previous indentation.
107
+ *
108
+ * @param manifest - updated manifest.json file content
109
+ * @param memFs - optional mem-fs-editor instance
110
+ */
111
+ updateManifestJSON(manifest: Manifest, memFs?: Editor): Promise<void>;
95
112
  }
96
113
  export interface ProjectAccess extends BaseAccess {
97
114
  getApplicationIds: () => string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/project-access",
3
- "version": "1.21.2",
3
+ "version": "1.22.0",
4
4
  "description": "Library to access SAP Fiori tools projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,6 +25,7 @@
25
25
  "dependencies": {
26
26
  "fast-xml-parser": "4.2.7",
27
27
  "findit2": "2.2.3",
28
+ "json-parse-even-better-errors": "3.0.2",
28
29
  "mem-fs": "2.1.0",
29
30
  "mem-fs-editor": "9.4.0",
30
31
  "semver": "7.5.4",