@celonis/content-cli 1.13.1 → 1.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/README.md +17 -5
- package/commands/action-flows/module.js +2 -1
- package/commands/asset-registry/asset-registry-api.js +1 -30
- package/commands/asset-registry/asset-registry.service.js +1 -52
- package/commands/asset-registry/module.js +0 -26
- package/commands/bookmarks/bookmarks-api.js +49 -0
- package/commands/bookmarks/bookmarks-command.service.js +46 -0
- package/{core/utils/path.js → commands/bookmarks/bookmarks.interfaces.js} +0 -5
- package/commands/bookmarks/module.js +49 -0
- package/commands/configuration-management/branch/api/branch.api.js +88 -0
- package/commands/configuration-management/branch/branch-export-import.command.service.js +276 -0
- package/commands/configuration-management/branch/branch.command.service.js +178 -0
- package/commands/configuration-management/branch/interfaces/branch.interfaces.js +41 -0
- package/commands/configuration-management/module.js +164 -1
- package/commands/configuration-management/single-package-import.service.js +6 -6
- package/commands/data-pipeline/connection/connection.commands.js +4 -2
- package/commands/data-pipeline/data-pool/data-pool.commands.js +2 -1
- package/commands/deployment/module.js +4 -7
- package/content-cli.js +4 -0
- package/core/command/module-handler.js +8 -1
- package/core/feature-flag/feature-disabled-error.js +52 -0
- package/core/utils/branches.js +10 -0
- package/core/utils/file-service.js +0 -7
- package/lib/commands/asset-registry/asset-registry-api.d.ts +2 -6
- package/lib/commands/asset-registry/asset-registry.interfaces.d.ts +0 -17
- package/lib/commands/asset-registry/asset-registry.service.d.ts +2 -6
- package/lib/commands/asset-registry/module.d.ts +0 -2
- package/lib/commands/bookmarks/bookmarks-api.d.ts +8 -0
- package/lib/commands/bookmarks/bookmarks-command.service.d.ts +7 -0
- package/lib/commands/bookmarks/bookmarks.interfaces.d.ts +34 -0
- package/lib/commands/bookmarks/module.d.ts +8 -0
- package/lib/commands/configuration-management/branch/api/branch.api.d.ts +12 -0
- package/lib/commands/configuration-management/branch/branch-export-import.command.service.d.ts +36 -0
- package/lib/commands/configuration-management/branch/branch.command.service.d.ts +18 -0
- package/lib/commands/configuration-management/branch/interfaces/branch.interfaces.d.ts +139 -0
- package/lib/commands/configuration-management/module.d.ts +8 -0
- package/lib/commands/configuration-management/single-package-import.service.d.ts +5 -3
- package/lib/core/command/module-handler.d.ts +4 -4
- package/lib/core/feature-flag/feature-disabled-error.d.ts +16 -0
- package/lib/core/utils/branches.d.ts +3 -0
- package/lib/core/utils/file-service.d.ts +0 -1
- package/package.json +3 -3
- package/lib/core/utils/path.d.ts +0 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
(function (factory) {
|
|
11
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
12
|
+
var v = factory(require, exports);
|
|
13
|
+
if (v !== undefined) module.exports = v;
|
|
14
|
+
}
|
|
15
|
+
else if (typeof define === "function" && define.amd) {
|
|
16
|
+
define(["require", "exports", "node:fs", "node:os", "node:path", "uuid", "adm-zip", "node:path", "../../../core/utils/file-service", "../../../core/utils/logger", "../../../core/git-profile/git/git.service", "../api/single-package-export-api", "../api/single-package-import-api", "../single-package-import.service", "./api/branch.api", "../../../core/utils/branches"], factory);
|
|
17
|
+
}
|
|
18
|
+
})(function (require, exports) {
|
|
19
|
+
"use strict";
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.BranchExportImportCommandService = void 0;
|
|
22
|
+
const fs = require("node:fs");
|
|
23
|
+
const os = require("node:os");
|
|
24
|
+
const path = require("node:path");
|
|
25
|
+
const uuid_1 = require("uuid");
|
|
26
|
+
const AdmZip = require("adm-zip");
|
|
27
|
+
const node_path_1 = require("node:path");
|
|
28
|
+
const file_service_1 = require("../../../core/utils/file-service");
|
|
29
|
+
const logger_1 = require("../../../core/utils/logger");
|
|
30
|
+
const git_service_1 = require("../../../core/git-profile/git/git.service");
|
|
31
|
+
const single_package_export_api_1 = require("../api/single-package-export-api");
|
|
32
|
+
const single_package_import_api_1 = require("../api/single-package-import-api");
|
|
33
|
+
const single_package_import_service_1 = require("../single-package-import.service");
|
|
34
|
+
const branch_api_1 = require("./api/branch.api");
|
|
35
|
+
const branches_1 = require("../../../core/utils/branches");
|
|
36
|
+
const PACKAGE_FILE = "package.json";
|
|
37
|
+
class BranchExportImportCommandService {
|
|
38
|
+
constructor(context) {
|
|
39
|
+
this.singlePackageExportApi = new single_package_export_api_1.SinglePackageExportApi(context);
|
|
40
|
+
this.singlePackageImportApi = new single_package_import_api_1.SinglePackageImportApi(context);
|
|
41
|
+
this.branchApi = new branch_api_1.BranchApi(context);
|
|
42
|
+
this.gitService = new git_service_1.GitService(context);
|
|
43
|
+
}
|
|
44
|
+
exportBranch(packageKey, branchKey, options = {}) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const jsonResponse = !!options.jsonResponse;
|
|
47
|
+
if (options.gitEnabled) {
|
|
48
|
+
const pushedKey = yield this.pushBranchToGit(packageKey, branchKey);
|
|
49
|
+
if (jsonResponse) {
|
|
50
|
+
BranchExportImportCommandService.writeJson({ packageKey: pushedKey, branchName: branchKey });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
logger_1.logger.info(`Exported ${pushedKey} to Git branch '${branchKey}'.`);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const branchPackageKey = branches_1.BranchUtils.constructBranchKey(packageKey, branchKey);
|
|
58
|
+
const sourceDir = yield this.exportRewrittenPackageDir(branchPackageKey);
|
|
59
|
+
try {
|
|
60
|
+
const message = this.writeLocalArtifact(sourceDir, packageKey, !!options.zip);
|
|
61
|
+
if (jsonResponse) {
|
|
62
|
+
BranchExportImportCommandService.writeJson({ packageKey: branchPackageKey, branchName: branchKey });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
logger_1.logger.info(message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
this.removeDir(sourceDir);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exportAll(packageKey, jsonResponse = false) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const mainKey = branches_1.BranchUtils.extractProjectKey(packageKey);
|
|
76
|
+
const branches = yield this.branchApi.listBranches(mainKey);
|
|
77
|
+
const synced = [];
|
|
78
|
+
yield this.pushMainPackage(mainKey);
|
|
79
|
+
synced.push(mainKey);
|
|
80
|
+
// listBranches also reports the main package itself, whose packageKey carries no
|
|
81
|
+
// branch suffix. It is already pushed above, and it has no '<mainKey>@<branchKey>'
|
|
82
|
+
// package to export, so exporting it as a branch would fail. A branch keyed 'main'
|
|
83
|
+
// is skipped as well: it would push over the main package's mirror above.
|
|
84
|
+
for (const branch of branches.filter(entry => BranchExportImportCommandService.isExportableBranch(entry))) {
|
|
85
|
+
const pushedKey = yield this.pushBranchToGit(mainKey, branch.branchKey);
|
|
86
|
+
synced.push(pushedKey);
|
|
87
|
+
if (!jsonResponse) {
|
|
88
|
+
logger_1.logger.info(`Exported ${pushedKey} to Git branch '${branch.branchKey}'.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const summary = { packageKey: mainKey, branchName: branches_1.BranchUtils.MAIN_BRANCH_KEY, synced };
|
|
92
|
+
if (jsonResponse) {
|
|
93
|
+
BranchExportImportCommandService.writeJson(summary);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
logger_1.logger.info(`Exported Git mirror for ${mainKey}: ${synced.length} package(s) pushed.`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
importBranch(packageKey, branchKey, options = {}) {
|
|
101
|
+
var _a;
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const branchPackageKey = branches_1.BranchUtils.constructBranchKey(packageKey, branchKey);
|
|
104
|
+
const workingDir = options.gitEnabled
|
|
105
|
+
? yield this.gitService.pullFromBranch(branchKey)
|
|
106
|
+
: this.prepareLocalWorkingDir(options.file, options.directory);
|
|
107
|
+
try {
|
|
108
|
+
this.restoreBranchKey(workingDir, packageKey, branchPackageKey);
|
|
109
|
+
yield this.importPackageSourceDir(workingDir, !!options.overwrite);
|
|
110
|
+
if (options.jsonResponse) {
|
|
111
|
+
BranchExportImportCommandService.writeJson({ packageKey: branchPackageKey, branchName: branchKey });
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const origin = options.gitEnabled ? `Git branch '${branchKey}'` : ((_a = options.file) !== null && _a !== void 0 ? _a : options.directory);
|
|
115
|
+
logger_1.logger.info(`Imported ${origin} into ${branchPackageKey}.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
this.removeDir(workingDir);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
pushBranchToGit(mainKey, branchKey) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const branchPackageKey = branches_1.BranchUtils.constructBranchKey(mainKey, branchKey);
|
|
126
|
+
const sourceDir = yield this.exportRewrittenPackageDir(branchPackageKey);
|
|
127
|
+
try {
|
|
128
|
+
yield this.gitService.pushToBranch(sourceDir, branchKey);
|
|
129
|
+
return branchPackageKey;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
this.removeDir(sourceDir);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
pushMainPackage(mainKey) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const packageData = yield this.singlePackageExportApi.exportPackage(mainKey);
|
|
139
|
+
const extractedDir = file_service_1.fileService.extractZipBufferToTempDirectory(packageData);
|
|
140
|
+
try {
|
|
141
|
+
yield this.gitService.pushToBranch(extractedDir, branches_1.BranchUtils.MAIN_BRANCH_KEY);
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
this.removeDir(extractedDir);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
exportRewrittenPackageDir(branchPackageKey) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const packageData = yield this.singlePackageExportApi.exportPackage(branchPackageKey);
|
|
151
|
+
const extractedDir = file_service_1.fileService.extractZipBufferToTempDirectory(packageData);
|
|
152
|
+
const projectKey = branches_1.BranchUtils.extractProjectKey(branchPackageKey);
|
|
153
|
+
this.normalizeToProjectKey(extractedDir, branchPackageKey, projectKey);
|
|
154
|
+
return extractedDir;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
writeLocalArtifact(sourceDir, packageKey, zip) {
|
|
158
|
+
if (zip) {
|
|
159
|
+
const zipPath = file_service_1.fileService.zipDirectoryAsSinglePackage(sourceDir);
|
|
160
|
+
try {
|
|
161
|
+
const fileName = `${packageKey}.zip`;
|
|
162
|
+
file_service_1.fileService.writeBufferToFileWithGivenName(fs.readFileSync(zipPath), (0, node_path_1.resolve)(process.cwd(), fileName));
|
|
163
|
+
return file_service_1.FileService.fileDownloadedMessage + fileName;
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
fs.rmSync(zipPath, { force: true });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const targetDir = (0, node_path_1.resolve)(process.cwd(), packageKey);
|
|
170
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
171
|
+
fs.cpSync(sourceDir, targetDir, { recursive: true });
|
|
172
|
+
return `Successful export. Exported directory: ${packageKey}`;
|
|
173
|
+
}
|
|
174
|
+
prepareLocalWorkingDir(file, directory) {
|
|
175
|
+
const workingDir = fs.mkdtempSync(path.join(os.tmpdir(), "content-cli-"));
|
|
176
|
+
if (directory) {
|
|
177
|
+
if (!file_service_1.fileService.isDirectory(directory)) {
|
|
178
|
+
fs.rmSync(workingDir, { recursive: true, force: true });
|
|
179
|
+
throw new logger_1.FatalError("The --directory option accepts only directories.");
|
|
180
|
+
}
|
|
181
|
+
fs.cpSync(directory, workingDir, { recursive: true });
|
|
182
|
+
return workingDir;
|
|
183
|
+
}
|
|
184
|
+
if (file_service_1.fileService.isDirectory(file)) {
|
|
185
|
+
fs.rmSync(workingDir, { recursive: true, force: true });
|
|
186
|
+
throw new logger_1.FatalError("The --file option accepts only zip files.");
|
|
187
|
+
}
|
|
188
|
+
const packageZip = new AdmZip(file);
|
|
189
|
+
try {
|
|
190
|
+
single_package_import_service_1.SinglePackageImportService.assertUncompressedSizeWithinLimit(packageZip, file);
|
|
191
|
+
packageZip.extractAllTo(workingDir, true);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
fs.rmSync(workingDir, { recursive: true, force: true });
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
return workingDir;
|
|
198
|
+
}
|
|
199
|
+
importPackageSourceDir(sourceDir, overwrite) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const zipPath = file_service_1.fileService.zipDirectoryAsSinglePackage(sourceDir);
|
|
202
|
+
try {
|
|
203
|
+
const formData = single_package_import_service_1.SinglePackageImportService.buildBodyForImport(new AdmZip(zipPath), zipPath);
|
|
204
|
+
yield this.singlePackageImportApi.importPackage(formData, overwrite);
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
fs.rmSync(zipPath, { force: true });
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
// The export source is a fresh Pacman export of the branch package, so a key that does not
|
|
212
|
+
// match is a no-op rather than a failure: the worst case is a mirror diff that still carries
|
|
213
|
+
// the branch suffix, and nothing outside the local working copy is touched.
|
|
214
|
+
normalizeToProjectKey(dir, from, to) {
|
|
215
|
+
if (from === to) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const filePath = path.join(dir, PACKAGE_FILE);
|
|
219
|
+
if (!fs.existsSync(filePath)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const raw = fs.readFileSync(filePath, { encoding: "utf-8" });
|
|
223
|
+
const json = JSON.parse(raw);
|
|
224
|
+
if (json.key !== from) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const updated = this.replaceFieldValue(raw, "key", from, to);
|
|
228
|
+
if (updated !== raw) {
|
|
229
|
+
fs.writeFileSync(filePath, updated, { encoding: "utf-8" });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// The import source is caller-supplied and the import endpoint derives the target package
|
|
233
|
+
// solely from package.json#key, so a key that is neither the project key nor the branch key
|
|
234
|
+
// must abort rather than silently import into whatever package the source names.
|
|
235
|
+
restoreBranchKey(dir, projectKey, branchPackageKey) {
|
|
236
|
+
const filePath = path.join(dir, PACKAGE_FILE);
|
|
237
|
+
if (!fs.existsSync(filePath)) {
|
|
238
|
+
throw new logger_1.FatalError(`The import source does not contain a ${PACKAGE_FILE} file.`);
|
|
239
|
+
}
|
|
240
|
+
const raw = fs.readFileSync(filePath, { encoding: "utf-8" });
|
|
241
|
+
const sourceKey = JSON.parse(raw).key;
|
|
242
|
+
if (sourceKey === branchPackageKey) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (sourceKey !== projectKey) {
|
|
246
|
+
throw new logger_1.FatalError(`The import source declares package key '${sourceKey}', but importing into '${branchPackageKey}' requires '${projectKey}' or '${branchPackageKey}'. Nothing was imported.`);
|
|
247
|
+
}
|
|
248
|
+
const updated = this.replaceFieldValue(raw, "key", projectKey, branchPackageKey);
|
|
249
|
+
if (updated === raw) {
|
|
250
|
+
throw new logger_1.FatalError(`Could not rewrite the package key in ${PACKAGE_FILE} from '${projectKey}' to '${branchPackageKey}'. Nothing was imported.`);
|
|
251
|
+
}
|
|
252
|
+
fs.writeFileSync(filePath, updated, { encoding: "utf-8" });
|
|
253
|
+
}
|
|
254
|
+
replaceFieldValue(content, field, from, to) {
|
|
255
|
+
const pattern = new RegExp(String.raw `("${this.escapeRegExp(field)}"\s*:\s*)"${this.escapeRegExp(from)}"`);
|
|
256
|
+
return content.replace(pattern, `$1"${to}"`);
|
|
257
|
+
}
|
|
258
|
+
escapeRegExp(value) {
|
|
259
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, match => "\\" + match);
|
|
260
|
+
}
|
|
261
|
+
removeDir(dir) {
|
|
262
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
263
|
+
}
|
|
264
|
+
static isExportableBranch(branch) {
|
|
265
|
+
var _a;
|
|
266
|
+
return branches_1.BranchUtils.isBranchPackageKey(branch.packageKey)
|
|
267
|
+
&& ((_a = branch.branchKey) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== branches_1.BranchUtils.MAIN_BRANCH_KEY;
|
|
268
|
+
}
|
|
269
|
+
static writeJson(payload) {
|
|
270
|
+
const filename = `${(0, uuid_1.v4)()}.json`;
|
|
271
|
+
file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(payload, null, 2), filename);
|
|
272
|
+
logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.BranchExportImportCommandService = BranchExportImportCommandService;
|
|
276
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
(function (factory) {
|
|
11
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
12
|
+
var v = factory(require, exports);
|
|
13
|
+
if (v !== undefined) module.exports = v;
|
|
14
|
+
}
|
|
15
|
+
else if (typeof define === "function" && define.amd) {
|
|
16
|
+
define(["require", "exports", "uuid", "../../../core/utils/file-service", "../../../core/utils/logger", "./api/branch.api", "./interfaces/branch.interfaces"], factory);
|
|
17
|
+
}
|
|
18
|
+
})(function (require, exports) {
|
|
19
|
+
"use strict";
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.BranchCommandService = void 0;
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
23
|
+
const file_service_1 = require("../../../core/utils/file-service");
|
|
24
|
+
const logger_1 = require("../../../core/utils/logger");
|
|
25
|
+
const branch_api_1 = require("./api/branch.api");
|
|
26
|
+
const branch_interfaces_1 = require("./interfaces/branch.interfaces");
|
|
27
|
+
class BranchCommandService {
|
|
28
|
+
constructor(context) {
|
|
29
|
+
this.branchApi = new branch_api_1.BranchApi(context);
|
|
30
|
+
}
|
|
31
|
+
setBranchingEnabled(packageKey, enabled, jsonResponse) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const transport = { branchingEnabled: enabled };
|
|
34
|
+
const result = yield this.branchApi.configureBranchingSettings(packageKey, transport);
|
|
35
|
+
if (jsonResponse) {
|
|
36
|
+
BranchCommandService.writeJson(result);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
logger_1.logger.info(`Branching ${result.branchingEnabled ? "enabled" : "disabled"} for package ${packageKey}.`);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
createBranch(packageKey, branchKey, sourceVersion, validate, jsonResponse) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const transport = { branchKey, version: sourceVersion };
|
|
47
|
+
const result = yield this.branchApi.createBranch(packageKey, transport, validate);
|
|
48
|
+
if (validate) {
|
|
49
|
+
logger_1.logger.info(`Validation successful for branch '${branchKey}' from ${packageKey}@${sourceVersion}.`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (jsonResponse) {
|
|
53
|
+
BranchCommandService.writeJson(result);
|
|
54
|
+
}
|
|
55
|
+
else if (result) {
|
|
56
|
+
BranchCommandService.printBranch(result);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
listBranches(packageKey, jsonResponse) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const branches = yield this.branchApi.listBranches(packageKey);
|
|
64
|
+
if (jsonResponse) {
|
|
65
|
+
BranchCommandService.writeJson(branches);
|
|
66
|
+
}
|
|
67
|
+
else if (branches.length === 0) {
|
|
68
|
+
logger_1.logger.info(`No branches found for ${packageKey}.`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
branches.forEach(branch => {
|
|
72
|
+
logger_1.logger.info(`${branch.branchKey} (package: ${branch.packageKey}, source: ${branch.sourcePackageKey}@${branch.sourceVersion})`);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return branches;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
deleteBranch(packageKey, branchKey) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const branchPackageKey = `${packageKey}@${branchKey}`;
|
|
81
|
+
yield this.branchApi.deleteBranch(branchPackageKey);
|
|
82
|
+
logger_1.logger.info(`Branch ${branchPackageKey} deleted.`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
mergePreview(targetPackageKey, sourceKey, sourceVersion, jsonResponse) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const transport = { sourceKey, sourceVersion };
|
|
88
|
+
const preview = yield this.branchApi.mergePreview(targetPackageKey, transport);
|
|
89
|
+
if (jsonResponse) {
|
|
90
|
+
BranchCommandService.writeJson(preview);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
BranchCommandService.printPreviewSummary(targetPackageKey, sourceKey, sourceVersion, preview);
|
|
94
|
+
}
|
|
95
|
+
return preview;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
mergeApply(targetPackageKey, options) {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const rawBody = options.file
|
|
102
|
+
? JSON.parse(file_service_1.fileService.readFile(options.file))
|
|
103
|
+
: {};
|
|
104
|
+
const effectiveSourceKey = (_a = options.sourceKey) !== null && _a !== void 0 ? _a : rawBody.sourceKey;
|
|
105
|
+
const effectiveSourceVersion = (_b = options.sourceVersion) !== null && _b !== void 0 ? _b : rawBody.sourceVersion;
|
|
106
|
+
const versionCreate = BranchCommandService.buildVersionCreate(rawBody.versionCreate, options.bump, options.version, options.summary, effectiveSourceKey, effectiveSourceVersion);
|
|
107
|
+
const transport = Object.assign(Object.assign({}, rawBody), { sourceKey: effectiveSourceKey, sourceVersion: effectiveSourceVersion, versionCreate });
|
|
108
|
+
const result = yield this.branchApi.merge(targetPackageKey, transport);
|
|
109
|
+
if (options.jsonResponse) {
|
|
110
|
+
BranchCommandService.writeJson(result);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
logger_1.logger.info(`Merge applied: published ${result.packageKey}@${result.version} from ${effectiveSourceKey}@${effectiveSourceVersion}.`);
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
static buildVersionCreate(fromFile, flagBump, flagVersion, flagSummary, sourceKey, sourceVersion) {
|
|
119
|
+
const versionCreate = fromFile ? Object.assign({}, fromFile) : {};
|
|
120
|
+
if (flagVersion !== undefined) {
|
|
121
|
+
versionCreate.version = flagVersion;
|
|
122
|
+
versionCreate.versionBumpOption = undefined;
|
|
123
|
+
}
|
|
124
|
+
else if (flagBump !== undefined) {
|
|
125
|
+
versionCreate.versionBumpOption = flagBump.toUpperCase();
|
|
126
|
+
versionCreate.version = undefined;
|
|
127
|
+
}
|
|
128
|
+
else if (!versionCreate.version && !versionCreate.versionBumpOption) {
|
|
129
|
+
versionCreate.versionBumpOption = branch_interfaces_1.VersionBumpOption.PATCH;
|
|
130
|
+
}
|
|
131
|
+
if (flagSummary !== undefined) {
|
|
132
|
+
versionCreate.summaryOfChanges = flagSummary;
|
|
133
|
+
}
|
|
134
|
+
else if (!versionCreate.summaryOfChanges && sourceKey && sourceVersion) {
|
|
135
|
+
versionCreate.summaryOfChanges = `Merge ${sourceKey}@${sourceVersion}`;
|
|
136
|
+
}
|
|
137
|
+
return versionCreate;
|
|
138
|
+
}
|
|
139
|
+
static writeJson(payload) {
|
|
140
|
+
const filename = `${(0, uuid_1.v4)()}.json`;
|
|
141
|
+
file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(payload, null, 2), filename);
|
|
142
|
+
logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
|
|
143
|
+
}
|
|
144
|
+
static printBranch(branch) {
|
|
145
|
+
logger_1.logger.info(`Main Package Key: ${branch.projectKey}`);
|
|
146
|
+
logger_1.logger.info(`Branch Key: ${branch.branchKey}`);
|
|
147
|
+
logger_1.logger.info(`Package Key: ${branch.packageKey}`);
|
|
148
|
+
logger_1.logger.info(`Source Package Key: ${branch.sourcePackageKey}`);
|
|
149
|
+
logger_1.logger.info(`Source Version: ${branch.sourceVersion}`);
|
|
150
|
+
}
|
|
151
|
+
static printPreviewSummary(targetPackageKey, sourceKey, sourceVersion, preview) {
|
|
152
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
153
|
+
logger_1.logger.info(`Preview: merge ${sourceKey}@${sourceVersion} into ${targetPackageKey}`);
|
|
154
|
+
logger_1.logger.info(`Common ancestor: ${preview.commonPackageKey}@${preview.commonVersion}`);
|
|
155
|
+
const totalNodes = (_b = (_a = preview.nodeChanges) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
156
|
+
const packageConflictPaths = BranchCommandService.countConflictPaths((_c = preview.packageChanges) === null || _c === void 0 ? void 0 : _c.changes);
|
|
157
|
+
const nodeConflictPaths = (_e = (_d = preview.nodeChanges) === null || _d === void 0 ? void 0 : _d.reduce((sum, node) => sum + BranchCommandService.countConflictPaths(node.changes), 0)) !== null && _e !== void 0 ? _e : 0;
|
|
158
|
+
const conflicts = packageConflictPaths + nodeConflictPaths;
|
|
159
|
+
const nodesNeedingResolution = (_g = (_f = preview.nodeChanges) === null || _f === void 0 ? void 0 : _f.filter(node => BranchCommandService.isInConflict(node.changes)).length) !== null && _g !== void 0 ? _g : 0;
|
|
160
|
+
logger_1.logger.info(`Nodes touched: ${totalNodes}, conflicting paths: ${conflicts}, nodes needing resolution: ${nodesNeedingResolution}.`);
|
|
161
|
+
if (BranchCommandService.isInConflict((_h = preview.packageChanges) === null || _h === void 0 ? void 0 : _h.changes)) {
|
|
162
|
+
logger_1.logger.info("The package's own configuration or metadata is in conflict. Supply 'resolvedPackageConflict' before applying.");
|
|
163
|
+
}
|
|
164
|
+
if (nodesNeedingResolution > 0 && nodeConflictPaths === 0) {
|
|
165
|
+
logger_1.logger.info("The conflicts above are structural (a node exists on one side only), so no path-level diff is reported. Supply a resolution for each node before applying.");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
static countConflictPaths(changes) {
|
|
169
|
+
var _a, _b, _c, _d, _e, _f;
|
|
170
|
+
return ((_c = (_b = (_a = changes === null || changes === void 0 ? void 0 : changes.configuration) === null || _a === void 0 ? void 0 : _a.conflicts) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) + ((_f = (_e = (_d = changes === null || changes === void 0 ? void 0 : changes.metadata) === null || _d === void 0 ? void 0 : _d.conflicts) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0);
|
|
171
|
+
}
|
|
172
|
+
static isInConflict(changes) {
|
|
173
|
+
var _a, _b;
|
|
174
|
+
return ((_a = changes === null || changes === void 0 ? void 0 : changes.configuration) === null || _a === void 0 ? void 0 : _a.status) === branch_interfaces_1.MergeStatus.CONFLICT || ((_b = changes === null || changes === void 0 ? void 0 : changes.metadata) === null || _b === void 0 ? void 0 : _b.status) === branch_interfaces_1.MergeStatus.CONFLICT;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.BranchCommandService = BranchCommandService;
|
|
178
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.VersionBumpOption = exports.ChangeType = exports.MergeStatus = exports.MergeResolution = void 0;
|
|
13
|
+
var MergeResolution;
|
|
14
|
+
(function (MergeResolution) {
|
|
15
|
+
MergeResolution["CUSTOM"] = "CUSTOM";
|
|
16
|
+
MergeResolution["ACCEPT_SOURCE"] = "ACCEPT_SOURCE";
|
|
17
|
+
MergeResolution["ACCEPT_TARGET"] = "ACCEPT_TARGET";
|
|
18
|
+
})(MergeResolution || (exports.MergeResolution = MergeResolution = {}));
|
|
19
|
+
var MergeStatus;
|
|
20
|
+
(function (MergeStatus) {
|
|
21
|
+
MergeStatus["UNKNOWN"] = "UNKNOWN";
|
|
22
|
+
MergeStatus["UNCHANGED"] = "UNCHANGED";
|
|
23
|
+
MergeStatus["SOURCE_ONLY"] = "SOURCE_ONLY";
|
|
24
|
+
MergeStatus["TARGET_ONLY"] = "TARGET_ONLY";
|
|
25
|
+
MergeStatus["AUTO_MERGE"] = "AUTO_MERGE";
|
|
26
|
+
MergeStatus["CONFLICT"] = "CONFLICT";
|
|
27
|
+
})(MergeStatus || (exports.MergeStatus = MergeStatus = {}));
|
|
28
|
+
var ChangeType;
|
|
29
|
+
(function (ChangeType) {
|
|
30
|
+
ChangeType["UNKNOWN"] = "UNKNOWN";
|
|
31
|
+
ChangeType["ADDED"] = "ADDED";
|
|
32
|
+
ChangeType["DELETED"] = "DELETED";
|
|
33
|
+
ChangeType["CHANGED"] = "CHANGED";
|
|
34
|
+
ChangeType["UNCHANGED"] = "UNCHANGED";
|
|
35
|
+
})(ChangeType || (exports.ChangeType = ChangeType = {}));
|
|
36
|
+
var VersionBumpOption;
|
|
37
|
+
(function (VersionBumpOption) {
|
|
38
|
+
VersionBumpOption["NONE"] = "NONE";
|
|
39
|
+
VersionBumpOption["PATCH"] = "PATCH";
|
|
40
|
+
})(VersionBumpOption || (exports.VersionBumpOption = VersionBumpOption = {}));
|
|
41
|
+
});
|