@celonis/content-cli 1.1.1 → 1.1.3

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.
@@ -60,7 +60,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
60
60
  this.exportListOfPackages(packagesToExport);
61
61
  });
62
62
  }
63
- batchExportPackages(packageKeys, packageKeysByVersion, withDependencies, gitBranch) {
63
+ batchExportPackages(packageKeys, packageKeysByVersion, withDependencies, gitBranch, unzip) {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
65
  let exportedPackagesData;
66
66
  if (packageKeys) {
@@ -93,12 +93,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
93
93
  const extractedDirectory = file_service_1.fileService.extractExportedZipWithNestedZips(exportedPackagesZip);
94
94
  yield this.gitService.pushToBranch(extractedDirectory, gitBranch);
95
95
  logger_1.logger.info("Successfully exported packages to branch: " + gitBranch);
96
+ fs.rmSync(extractedDirectory, { recursive: true });
96
97
  }
97
98
  else {
98
- const fileDownloadedMessage = "File downloaded successfully. New filename: ";
99
- const filename = `export_${(0, uuid_1.v4)()}.zip`;
100
- exportedPackagesZip.writeZip(filename);
101
- logger_1.logger.info(fileDownloadedMessage + filename);
99
+ this.downloadZip(exportedPackagesZip, unzip);
102
100
  }
103
101
  });
104
102
  }
@@ -115,17 +113,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
115
113
  }
116
114
  });
117
115
  }
118
- batchImportPackages(file, overwrite, gitBranch) {
116
+ batchImportPackages(sourcePath, overwrite, gitBranch) {
119
117
  return __awaiter(this, void 0, void 0, function* () {
120
- let fileToBeImported;
118
+ let sourceToBeImported;
121
119
  if (gitBranch) {
122
- fileToBeImported = yield this.gitService.pullFromBranch(gitBranch);
123
- fileToBeImported = file_service_1.fileService.zipDirectoryInBatchExportFormat(fileToBeImported);
120
+ sourceToBeImported = yield this.gitService.pullFromBranch(gitBranch);
124
121
  }
125
122
  else {
126
- fileToBeImported = file;
123
+ sourceToBeImported = sourcePath;
124
+ if (file_service_1.fileService.isDirectory(sourcePath)) {
125
+ sourceToBeImported = file_service_1.fileService.zipDirectoryInBatchExportFormat(sourceToBeImported);
126
+ }
127
127
  }
128
- let configs = new AdmZip(fileToBeImported);
128
+ let configs = new AdmZip(sourceToBeImported);
129
129
  const studioManifests = this.parseEntryData(configs, batch_export_import_constants_1.BatchExportImportConstants.STUDIO_FILE_NAME);
130
130
  const variablesManifests = this.parseEntryData(configs, batch_export_import_constants_1.BatchExportImportConstants.VARIABLES_FILE_NAME);
131
131
  configs = yield this.studioService.mapSpaces(configs, studioManifests);
@@ -134,7 +134,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
134
134
  const postPackageImportData = yield this.batchImportExportApi.importPackages(formData, overwrite);
135
135
  yield this.studioService.processImportedPackages(configs, existingStudioPackages, studioManifests);
136
136
  if (gitBranch) {
137
- fs.rmSync(fileToBeImported);
137
+ fs.rmSync(sourceToBeImported);
138
138
  }
139
139
  const reportFileName = "config_import_report_" + (0, uuid_1.v4)() + ".json";
140
140
  file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(postPackageImportData), reportFileName);
@@ -211,6 +211,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
211
211
  }
212
212
  return null;
213
213
  }
214
+ downloadZip(exportedZip, unzip) {
215
+ if (unzip) {
216
+ const fileDownloadedMessage = "Successful download. Downloaded directory: ";
217
+ const targetDirectoryName = `export_${(0, uuid_1.v4)()}`;
218
+ file_service_1.fileService.extractExportedZipWithNestedZipsToDir(exportedZip, targetDirectoryName);
219
+ logger_1.logger.info(fileDownloadedMessage + targetDirectoryName);
220
+ }
221
+ else {
222
+ const fileDownloadedMessage = "File downloaded successfully. New filename: ";
223
+ const filename = `export_${(0, uuid_1.v4)()}.zip`;
224
+ exportedZip.writeZip(filename);
225
+ logger_1.logger.info(fileDownloadedMessage + filename);
226
+ }
227
+ }
214
228
  }
215
229
  exports.BatchImportExportService = BatchImportExportService;
216
230
  });
@@ -13,7 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  if (v !== undefined) module.exports = v;
14
14
  }
15
15
  else if (typeof define === "function" && define.amd) {
16
- define(["require", "exports", "./batch-import-export.service", "./variable.service", "./diff.service"], factory);
16
+ define(["require", "exports", "./batch-import-export.service", "./variable.service", "./diff.service", "../../core/utils/file-service"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -22,6 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  const batch_import_export_service_1 = require("./batch-import-export.service");
23
23
  const variable_service_1 = require("./variable.service");
24
24
  const diff_service_1 = require("./diff.service");
25
+ const file_service_1 = require("../../core/utils/file-service");
25
26
  class ConfigCommandService {
26
27
  constructor(context) {
27
28
  this.batchImportExportService = new batch_import_export_service_1.BatchImportExportService(context);
@@ -52,20 +53,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
52
53
  }
53
54
  });
54
55
  }
55
- batchExportPackages(packageKeys, packageKeysByVersion, withDependencies, gitBranch) {
56
- return this.batchImportExportService.batchExportPackages(packageKeys, packageKeysByVersion, withDependencies, gitBranch);
56
+ batchExportPackages(packageKeys, packageKeysByVersion, withDependencies, gitBranch, unzip) {
57
+ return this.batchImportExportService.batchExportPackages(packageKeys, packageKeysByVersion, withDependencies, gitBranch, unzip);
57
58
  }
58
59
  batchExportPackagesMetadata(packageKeys, jsonResponse) {
59
60
  return this.batchImportExportService.batchExportPackagesMetadata(packageKeys, jsonResponse);
60
61
  }
61
- batchImportPackages(file, overwrite, gitBranch) {
62
- if (file && gitBranch) {
63
- throw new Error("You cannot use both file and gitBranch options at the same time. Only one import source can be defined.");
62
+ batchImportPackages(file, directory, overwrite, gitBranch) {
63
+ if ((directory || file) && gitBranch) {
64
+ throw new Error("You cannot use both file/directory and gitBranch options at the same time. Only one import source can be defined.");
64
65
  }
65
- if (!file && !gitBranch) {
66
- throw new Error("You must provide either a file or a gitBranch option to import packages.");
66
+ if (!directory && !file && !gitBranch) {
67
+ throw new Error("You must provide either a file/directory or a gitBranch option to import packages.");
67
68
  }
68
- return this.batchImportExportService.batchImportPackages(file, overwrite, gitBranch);
69
+ if (file && directory) {
70
+ throw new Error("You cannot use both file and directory options at the same time. Only one import source can be defined.");
71
+ }
72
+ if (file && file_service_1.fileService.isDirectory(file)) {
73
+ throw new Error("The file option accepts only zip files.");
74
+ }
75
+ if (directory && !file_service_1.fileService.isDirectory(directory)) {
76
+ throw new Error("The directory option accepts only directories.");
77
+ }
78
+ const sourcePath = file !== null && file !== void 0 ? file : directory;
79
+ return this.batchImportExportService.batchImportPackages(sourcePath, overwrite, gitBranch);
69
80
  }
70
81
  diffPackages(file, hasChanges, jsonResponse) {
71
82
  return this.diffService.diffPackages(file, hasChanges, jsonResponse);
@@ -40,6 +40,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
40
40
  .option("--packageKeys <packageKeys...>", "Keys of packages to export. Exports the latest deployed version only")
41
41
  .option("--keysByVersion <keysByVersion...>", "Keys of packages to export by version")
42
42
  .option("--withDependencies", "Include variables and dependencies", "")
43
+ .option("--unzip", "Unzip the exported file", "")
43
44
  .betaOption("--gitProfile <gitProfile>", "Git profile which you want to use for the Git operations")
44
45
  .betaOption("--gitBranch <gitBranch>", "Git branch in which you want to push the exported file")
45
46
  .action(this.batchExportPackages);
@@ -57,6 +58,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
57
58
  .betaOption("--gitProfile <gitProfile>", "Git profile which you want to use for the Git operations")
58
59
  .betaOption("--gitBranch <gitBranch>", "Git branch from which you want to pull the exported file and import")
59
60
  .option("-f, --file <file>", "Exported packages file (relative path)")
61
+ .option("-d, --directory <directory>", "Exported packages directory (relative path)")
60
62
  .action(this.batchImportPackages);
61
63
  configCommand.command("diff")
62
64
  .description("Command to diff configs of packages")
@@ -92,7 +94,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
92
94
  throw new Error("Please provide either --packageKeys or --keysByVersion, but not both.");
93
95
  }
94
96
  options.withDependencies = (_a = options.withDependencies) !== null && _a !== void 0 ? _a : false;
95
- yield new config_command_service_1.ConfigCommandService(context).batchExportPackages(options.packageKeys, options.keysByVersion, options.withDependencies, options.gitBranch);
97
+ yield new config_command_service_1.ConfigCommandService(context).batchExportPackages(options.packageKeys, options.keysByVersion, options.withDependencies, options.gitBranch, options.unzip);
96
98
  });
97
99
  }
98
100
  batchExportPackagesMetadata(context, command, options) {
@@ -102,7 +104,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
102
104
  }
103
105
  batchImportPackages(context, command, options) {
104
106
  return __awaiter(this, void 0, void 0, function* () {
105
- yield new config_command_service_1.ConfigCommandService(context).batchImportPackages(options.file, options.overwrite, options.gitBranch);
107
+ yield new config_command_service_1.ConfigCommandService(context).batchImportPackages(options.file, options.directory, options.overwrite, options.gitBranch);
106
108
  });
107
109
  }
108
110
  diffPackages(context, command, options) {
@@ -150,20 +150,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
150
150
  return new Promise((resolve, reject) => {
151
151
  this.axios.post(this.resolveUrl(url), null, {
152
152
  headers: this.buildHeaders(),
153
- responseType: "stream"
153
+ responseType: "stream",
154
+ validateStatus: () => true, // Accept all status codes, handle manually
154
155
  }).then(response => {
155
- const data = [];
156
- response.data.on("data", (chunk) => {
157
- data.push(chunk);
158
- });
159
- response.data.on("end", () => {
160
- if (this.checkBadRequest(response.status)) {
161
- this.handleBadRequest(response.status, data.toString(), reject);
162
- }
163
- else {
156
+ if (this.checkBadRequest(response.status)) {
157
+ // For error responses, collect as text for readable error messages
158
+ let errorData = '';
159
+ response.data.setEncoding('utf8');
160
+ response.data.on('data', (chunk) => {
161
+ errorData += chunk;
162
+ });
163
+ response.data.on('end', () => {
164
+ this.handleBadRequest(response.status, errorData, reject);
165
+ });
166
+ response.data.on('error', (err) => {
167
+ reject(`Error reading error response: ${err.message}`);
168
+ });
169
+ }
170
+ else {
171
+ // For successful responses, collect as binary for file download
172
+ const data = [];
173
+ response.data.on("data", (chunk) => {
174
+ data.push(chunk);
175
+ });
176
+ response.data.on("end", () => {
164
177
  this.handleResponseStreamData(Buffer.concat(data), resolve, reject);
165
- }
166
- });
178
+ });
179
+ response.data.on('error', (err) => {
180
+ reject(`Error reading file data: ${err.message}`);
181
+ });
182
+ }
167
183
  }).catch(err => {
168
184
  this.handleError(err, resolve, reject);
169
185
  });
@@ -31,9 +31,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  encoding: "utf-8",
32
32
  });
33
33
  }
34
- createDirectoryWithGivenName(dirName) {
35
- fs.mkdirSync(path.resolve(process.cwd(), dirName));
36
- }
37
34
  readFileToJson(fileName) {
38
35
  return __awaiter(this, void 0, void 0, function* () {
39
36
  const fileContent = this.readFile(fileName);
@@ -49,10 +46,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
49
46
  extractExportedZipWithNestedZips(zipFile) {
50
47
  const tempDir = path.join(os.tmpdir(), `${(0, uuid_1.v4)()}`);
51
48
  fs.mkdirSync(tempDir, { recursive: true });
52
- zipFile.extractAllTo(tempDir, true);
53
- const files = fs.readdirSync(tempDir);
49
+ return this.extractExportedZipWithNestedZipsToDir(zipFile, tempDir);
50
+ }
51
+ extractExportedZipWithNestedZipsToDir(zipFile, targetDir) {
52
+ zipFile.extractAllTo(targetDir, true);
53
+ const files = fs.readdirSync(targetDir);
54
54
  for (const file of files) {
55
- const innerZipPath = path.join(tempDir, file);
55
+ const innerZipPath = path.join(targetDir, file);
56
56
  if (file.endsWith(".zip")) {
57
57
  const nestedZip = new AdmZip(innerZipPath);
58
58
  const nestedDir = innerZipPath.replace(/\.zip$/, "");
@@ -61,7 +61,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
61
61
  fs.rmSync(innerZipPath); // Optionally remove the inner zip
62
62
  }
63
63
  }
64
- return tempDir;
64
+ return targetDir;
65
+ }
66
+ copyDirectoryToCurrentLocation(sourceDir, targetName) {
67
+ fs.mkdirSync(targetName, { recursive: true });
68
+ fs.cpSync(sourceDir, targetName, { recursive: true });
69
+ }
70
+ isDirectory(sourcePath) {
71
+ var _a;
72
+ return (_a = fs.statSync(sourcePath)) === null || _a === void 0 ? void 0 : _a.isDirectory();
65
73
  }
66
74
  zipDirectoryInBatchExportFormat(sourceDir) {
67
75
  const files = fs.readdirSync(sourceDir);
@@ -7,9 +7,9 @@ export declare class BatchImportExportService {
7
7
  constructor(context: Context);
8
8
  listActivePackages(flavors: string[]): Promise<void>;
9
9
  findAndExportListOfActivePackages(flavors: string[], packageKeys: string[], withDependencies: boolean): Promise<void>;
10
- batchExportPackages(packageKeys: string[], packageKeysByVersion: string[], withDependencies: boolean, gitBranch: string): Promise<void>;
10
+ batchExportPackages(packageKeys: string[], packageKeysByVersion: string[], withDependencies: boolean, gitBranch: string, unzip: boolean): Promise<void>;
11
11
  batchExportPackagesMetadata(packageKeys: string[], jsonResponse: boolean): Promise<void>;
12
- batchImportPackages(file: string, overwrite: boolean, gitBranch: string): Promise<void>;
12
+ batchImportPackages(sourcePath: string, overwrite: boolean, gitBranch: string): Promise<void>;
13
13
  findAndExportListOfActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string): Promise<void>;
14
14
  listActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string): Promise<void>;
15
15
  private exportListOfPackages;
@@ -19,4 +19,5 @@ export declare class BatchImportExportService {
19
19
  private buildBodyForImport;
20
20
  private getReadableStream;
21
21
  private parseEntryData;
22
+ private downloadZip;
22
23
  }
@@ -6,9 +6,9 @@ export declare class ConfigCommandService {
6
6
  constructor(context: Context);
7
7
  listActivePackages(jsonResponse: boolean, flavors: string[], withDependencies: boolean, packageKeys: string[], variableValue: string, variableType: string): Promise<void>;
8
8
  listVariables(jsonResponse: boolean, keysByVersion: string[], keysByVersionFile: string): Promise<void>;
9
- batchExportPackages(packageKeys: string[], packageKeysByVersion: string[], withDependencies: boolean, gitBranch: string): Promise<void>;
9
+ batchExportPackages(packageKeys: string[], packageKeysByVersion: string[], withDependencies: boolean, gitBranch: string, unzip: boolean): Promise<void>;
10
10
  batchExportPackagesMetadata(packageKeys: string[], jsonResponse: boolean): Promise<void>;
11
- batchImportPackages(file: string, overwrite: boolean, gitBranch: string): Promise<void>;
11
+ batchImportPackages(file: string, directory: string, overwrite: boolean, gitBranch: string): Promise<void>;
12
12
  diffPackages(file: string, hasChanges: boolean, jsonResponse: boolean): Promise<void>;
13
13
  private listPackagesByVariableValue;
14
14
  }
@@ -2,10 +2,12 @@ import AdmZip = require("adm-zip");
2
2
  export declare class FileService {
3
3
  static readonly fileDownloadedMessage = "File downloaded successfully. New filename: ";
4
4
  writeToFileWithGivenName(data: any, filename: string): void;
5
- createDirectoryWithGivenName(dirName: string): void;
6
5
  readFileToJson<T>(fileName: string): Promise<T>;
7
6
  readFile(filename: string): string;
8
7
  extractExportedZipWithNestedZips(zipFile: AdmZip): string;
8
+ extractExportedZipWithNestedZipsToDir(zipFile: AdmZip, targetDir: string): string;
9
+ copyDirectoryToCurrentLocation(sourceDir: string, targetName: string): void;
10
+ isDirectory(sourcePath: string): boolean;
9
11
  zipDirectoryInBatchExportFormat(sourceDir: string): string;
10
12
  private getSerializedFileContent;
11
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celonis/content-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "CLI Tool to help manage content in Celonis Platform",
5
5
  "main": "content-cli.js",
6
6
  "bin": {