@clickview/ship-it 0.0.2 → 0.0.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.
Files changed (48) hide show
  1. package/lib/src/api-clients/{GitLabApiClient.js → git-lab/GitLabApiClient.js} +82 -107
  2. package/lib/src/api-clients/git-lab/GitLabMapper.js +60 -0
  3. package/lib/src/api-clients/index.js +1 -1
  4. package/lib/src/commands/BumpPackagesCommand.js +12 -4
  5. package/lib/src/commands/CreateBranchCommand.js +8 -8
  6. package/lib/src/commands/CreateMergeRequestCommand.js +11 -11
  7. package/lib/src/commands/CreateReleaseNotesCommand.js +4 -4
  8. package/lib/src/commands/InstallPackagesCommand.js +78 -0
  9. package/lib/src/commands/ReleaseCommand.js +14 -14
  10. package/lib/src/commands/StatusCommand.js +2 -2
  11. package/lib/src/commands/ValidateMergeRequestCommand.js +78 -0
  12. package/lib/src/commands/VersionCommand.js +2 -2
  13. package/lib/src/commands/index.js +2 -0
  14. package/lib/src/constants/CommandTypeMapping.js +15 -0
  15. package/lib/src/constants/MonorepoPackageJsonFiles.js +13 -0
  16. package/lib/src/errors/ShipItError.js +32 -0
  17. package/lib/src/errors/index.js +17 -0
  18. package/lib/src/index.js +3 -86
  19. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +2 -0
  20. package/lib/src/interfaces/command-options/InstallPackagesCommandOptions.js +2 -0
  21. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +2 -0
  22. package/lib/src/interfaces/command-options/ValidateMRCommandOptions.js +2 -0
  23. package/lib/src/interfaces/command-options/index.js +20 -0
  24. package/lib/src/interfaces/index.js +2 -1
  25. package/lib/src/interfaces/models/Milestone.js +2 -0
  26. package/lib/src/interfaces/models/index.js +1 -0
  27. package/lib/src/inversify.config.js +5 -0
  28. package/lib/src/services/GitLabService.js +95 -34
  29. package/lib/src/startup/AddMilestoneCommand.js +75 -0
  30. package/lib/src/startup/SetupCommands.js +92 -0
  31. package/lib/src/tasks/BumpPackagesTask.js +114 -238
  32. package/lib/src/tasks/BumpVersionTxtTask.js +13 -26
  33. package/lib/src/tasks/CommitPackageVersionsTask.js +105 -0
  34. package/lib/src/tasks/CreateBranchTask.js +17 -32
  35. package/lib/src/tasks/CreateMergeRequestTask.js +22 -37
  36. package/lib/src/tasks/CreateReleaseNotesTask.js +2 -6
  37. package/lib/src/tasks/InstallPackagesTask.js +358 -0
  38. package/lib/src/tasks/ValidateCommitsTask.js +6 -14
  39. package/lib/src/tasks/ValidateDescriptionsTask.js +15 -16
  40. package/lib/src/tasks/ValidateMergeRequestTask.js +108 -0
  41. package/lib/src/tasks/ValidateTask.js +7 -8
  42. package/lib/src/tasks/VersionTask.js +7 -20
  43. package/lib/src/tasks/index.js +3 -0
  44. package/lib/src/types.js +7 -2
  45. package/lib/src/utils/Descriptions.js +28 -23
  46. package/lib/src/utils/ProjectIds.js +7 -3
  47. package/package.json +22 -22
  48. /package/lib/src/interfaces/{ShipItOptions.js → VersionType.js} +0 -0
@@ -47,302 +47,178 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
48
  }
49
49
  };
50
- var __importDefault = (this && this.__importDefault) || function (mod) {
51
- return (mod && mod.__esModule) ? mod : { "default": mod };
52
- };
53
50
  Object.defineProperty(exports, "__esModule", { value: true });
54
51
  exports.BumpPackagesTask = void 0;
55
52
  require("reflect-metadata");
56
53
  var inversify_1 = require("inversify");
57
- var fs_extra_1 = __importDefault(require("fs-extra"));
58
- var semver_1 = __importDefault(require("semver"));
59
- var child_process_1 = __importDefault(require("child_process"));
54
+ var child_process_1 = require("child_process");
60
55
  var types_1 = require("../types");
61
56
  var services_1 = require("../services");
57
+ var MonorepoPackageJsonFiles_1 = require("../constants/MonorepoPackageJsonFiles");
62
58
  var utils_1 = require("../utils");
63
- var MONOREPO_PACKAGES_FILES = [
64
- 'packages/libs/analytics/package.json',
65
- 'packages/libs/styles/package.json',
66
- 'packages/libs/tooling/package.json',
67
- 'packages/projects/curator/package.json',
68
- 'packages/projects/library-editor/package.json',
69
- 'packages/projects/lite/package.json',
70
- 'packages/projects/online/package.json',
71
- 'packages/projects/reports/package.json'
72
- ];
73
- var ROOT_DIRECTORIES = {
74
- // Curator
75
- 62: 'src/ClickView.Curator.Web/Assets',
76
- // Library Editor
77
- 534: 'src/ClickView.Cloud',
78
- // Lite
79
- 822: 'src/ClickView.Lite',
80
- // Online
81
- 109: 'src/ClickView.Web.Online.Pages',
82
- // Reports
83
- 970: 'src/ClickView.Analytics.Web'
84
- };
59
+ var RELEASE_BRANCH_REGEX = /^release\/(\d|\.)+$/;
60
+ var HOTFIX_BRANCH_REGEX = /^hotfix\/(\d|\.)+$/;
61
+ var DEV_VERSION_REGEX = /-dev\.\d+$/;
62
+ var RC_VERSION_REGEX = /-rc\.\d+$/;
63
+ var SHARED_LERNA_OPTIONS = '--exact --no-git-tag-version --no-push --yes';
85
64
  var BumpPackagesTask = /** @class */ (function () {
86
65
  function BumpPackagesTask(service) {
87
- this._service = service;
66
+ this.isReleaseBranch = false;
67
+ this.isHotfixBranch = false;
68
+ this.service = service;
88
69
  }
89
70
  BumpPackagesTask.prototype.run = function (options) {
90
71
  return __awaiter(this, void 0, void 0, function () {
91
- var projects, monorepo, consumingProjects, monorepoBranchName, versions, _i, consumingProjects_1, project, branchName, _a, consumingProjects_2, project, _b, consumingProjects_3, project, branchName;
92
- return __generator(this, function (_c) {
93
- switch (_c.label) {
72
+ var branch, isValid, lernaVersionCmd;
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
94
75
  case 0:
95
- utils_1.Logger.logTask('Bumping npm packages');
96
- return [4 /*yield*/, this._service.getProjects(options)];
76
+ utils_1.Logger.logTask('Bumping clickview npm package versions');
77
+ this.isReleaseBranch = RELEASE_BRANCH_REGEX.test(options.branchName);
78
+ this.isHotfixBranch = HOTFIX_BRANCH_REGEX.test(options.branchName);
79
+ return [4 /*yield*/, this.service.getBranch(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
97
80
  case 1:
98
- projects = _c.sent();
99
- monorepo = projects.find(function (p) { return p.id.toString() === utils_1.ProjectIds.MONOREPO_PROJECT_ID; });
100
- consumingProjects = projects.filter(function (p) { return p.id.toString() !== utils_1.ProjectIds.MONOREPO_PROJECT_ID; });
101
- if (!monorepo) {
102
- utils_1.Logger.logError("Monorepo was not in this release");
81
+ branch = _a.sent();
82
+ if (!branch) {
83
+ utils_1.Logger.logError("Branch with name ".concat(options.branchName, " was not be found."));
103
84
  return [2 /*return*/, false];
104
85
  }
105
- if (!consumingProjects.length) {
106
- utils_1.Logger.logError("No projects that consume monorepo could be found");
86
+ isValid = this.validateOptions(options);
87
+ if (!isValid)
107
88
  return [2 /*return*/, false];
108
- }
109
- return [4 /*yield*/, this.getBranchName(monorepo.id, options.version)];
89
+ return [4 /*yield*/, this.getLernaCommand(options)];
110
90
  case 2:
111
- monorepoBranchName = _c.sent();
112
- if (!monorepoBranchName) {
113
- utils_1.Logger.logError("[".concat(monorepo.title, "] branch does not exist"));
91
+ lernaVersionCmd = _a.sent();
92
+ if (!lernaVersionCmd) {
93
+ utils_1.Logger.logError('Something went wrong while trying to detect which versioning script to run with Lerna.');
114
94
  return [2 /*return*/, false];
115
95
  }
116
- return [4 /*yield*/, this.getPackageVersions(monorepoBranchName)];
117
- case 3:
118
- versions = _c.sent();
119
- utils_1.Logger.logMessage("Versions identified for ".concat(monorepoBranchName));
120
- Object.keys(versions).forEach(function (key) {
121
- utils_1.Logger.logMessage("- [".concat(key, "]: ").concat(versions[key]));
122
- });
123
- // let cont = true;
124
- utils_1.Logger.logMessage('\nBumping packages:\n');
125
- _i = 0, consumingProjects_1 = consumingProjects;
126
- _c.label = 4;
127
- case 4:
128
- if (!(_i < consumingProjects_1.length)) return [3 /*break*/, 8];
129
- project = consumingProjects_1[_i];
130
- return [4 /*yield*/, this.getBranchName(project.id, options.version)];
131
- case 5:
132
- branchName = _c.sent();
133
- // TODO: potentially add a validate branches task and removing the branch checking from this task
134
- // so that bump packages can't be run until create release is run
135
- if (!branchName) {
136
- utils_1.Logger.logError("[".concat(project.title, "]: branch does not exist"));
137
- return [3 /*break*/, 7];
138
- }
139
- return [4 /*yield*/, this.updateAndSavePackageFiles(project, options.milestone, branchName, versions)];
140
- case 6:
141
- _c.sent();
142
- _c.label = 7;
143
- case 7:
144
- _i++;
145
- return [3 /*break*/, 4];
146
- case 8:
147
- for (_a = 0, consumingProjects_2 = consumingProjects; _a < consumingProjects_2.length; _a++) {
148
- project = consumingProjects_2[_a];
149
- utils_1.Logger.logInfo("[".concat(project.title, "]: Running npm i --package-lock-only"));
150
- this.npmInstall(project, options.milestone);
151
- utils_1.Logger.logInfo('\n');
152
- }
153
- /**
154
- * TODO: Need to not commit when there's no changes
155
- */
156
- utils_1.Logger.logMessage('Committing files');
157
- _b = 0, consumingProjects_3 = consumingProjects;
158
- _c.label = 9;
159
- case 9:
160
- if (!(_b < consumingProjects_3.length)) return [3 /*break*/, 13];
161
- project = consumingProjects_3[_b];
162
- return [4 /*yield*/, this.getBranchName(project.id, options.version)];
163
- case 10:
164
- branchName = _c.sent();
165
- if (!branchName) {
166
- utils_1.Logger.logError("[".concat(project.title, "]: branch does not exist"));
167
- return [3 /*break*/, 12];
168
- }
169
- return [4 /*yield*/, this.commitUpdatedFiles(project, options.milestone, branchName)];
170
- case 11:
171
- _c.sent();
172
- utils_1.Logger.logMessage("[".concat(project.title, "]: File changes committed"));
173
- _c.label = 12;
174
- case 12:
175
- _b++;
176
- return [3 /*break*/, 9];
177
- case 13: return [2 /*return*/, true];
96
+ (0, child_process_1.execSync)(lernaVersionCmd);
97
+ utils_1.Logger.logSuccess('Successfully executed Lerna versioning command.');
98
+ return [2 /*return*/, true];
178
99
  }
179
100
  });
180
101
  });
181
102
  };
182
- BumpPackagesTask.prototype.commitUpdatedFiles = function (project, milestone, branchName) {
103
+ BumpPackagesTask.prototype.validateOptions = function (options) {
104
+ var isValidReleaseBranch = this.isReleaseBranch || this.isHotfixBranch;
105
+ if (options.preId && options.preId !== 'rc' && options.preId !== 'dev') {
106
+ utils_1.Logger.logError("Argument for \"preId\" can only be \"rc\" or \"dev\". You entered: ".concat(options.preId));
107
+ return false;
108
+ }
109
+ if (options.preId === 'dev' && isValidReleaseBranch) {
110
+ utils_1.Logger.logError('Dev versions cannot be generated on release or hotfix branches.');
111
+ return false;
112
+ }
113
+ if (options.preId === 'rc' && !isValidReleaseBranch) {
114
+ utils_1.Logger.logError('Release Candidate versions can only be generated on release or hotfix branches.');
115
+ return false;
116
+ }
117
+ if (!options.preId && !isValidReleaseBranch) {
118
+ utils_1.Logger.logError('Production package versions can only be generated on release or hotfix branches.');
119
+ return false;
120
+ }
121
+ return true;
122
+ };
123
+ BumpPackagesTask.prototype.getFileText = function (projectId, branchName, fileName) {
183
124
  return __awaiter(this, void 0, void 0, function () {
184
- var rootDir, outputPath, commitFiles, _a;
185
- var _b, _c;
186
- return __generator(this, function (_d) {
187
- switch (_d.label) {
188
- case 0:
189
- rootDir = ROOT_DIRECTORIES[project.id];
190
- outputPath = this.getOutputPath(project, milestone);
191
- _b = {
192
- filePath: "".concat(rootDir, "/package.json")
193
- };
194
- return [4 /*yield*/, fs_extra_1.default.readFile("".concat(outputPath, "/package.json"), 'utf8')];
125
+ var file, buff;
126
+ return __generator(this, function (_a) {
127
+ switch (_a.label) {
128
+ case 0: return [4 /*yield*/, this.service.getFile(projectId, branchName, fileName)];
195
129
  case 1:
196
- _a = [(_b.content = _d.sent(),
197
- _b)];
198
- _c = {
199
- filePath: "".concat(rootDir, "/package-lock.json")
200
- };
201
- return [4 /*yield*/, fs_extra_1.default.readFile("".concat(outputPath, "/package-lock.json"), 'utf8')];
202
- case 2:
203
- commitFiles = _a.concat([(_c.content = _d.sent(),
204
- _c)]);
205
- return [4 /*yield*/, this._service.commit(project.id, branchName, 'Bumping @clickview npm packages', commitFiles)];
206
- case 3:
207
- _d.sent();
208
- return [2 /*return*/];
130
+ file = _a.sent();
131
+ if (!file)
132
+ return [2 /*return*/, ''];
133
+ buff = Buffer.from(file.content, 'base64');
134
+ return [2 /*return*/, buff.toString('utf-8')];
209
135
  }
210
136
  });
211
137
  });
212
138
  };
213
- BumpPackagesTask.prototype.npmInstall = function (project, milestone) {
214
- var outputPath = this.getOutputPath(project, milestone);
215
- child_process_1.default.execSync('npm i --package-lock-only', {
216
- cwd: outputPath,
217
- // Uncomment if we want to silence
218
- // stdio: 'pipe'
219
- });
220
- };
221
- BumpPackagesTask.prototype.updateAndSavePackageFiles = function (project, milestone, branchName, versions) {
139
+ BumpPackagesTask.prototype.getLernaCommand = function (options) {
222
140
  return __awaiter(this, void 0, void 0, function () {
223
- var rootDir, packageJson, packageLock, packageJsonObj, outputPath;
141
+ var isInPrerelease;
224
142
  return __generator(this, function (_a) {
225
143
  switch (_a.label) {
226
- case 0:
227
- rootDir = ROOT_DIRECTORIES[project.id];
228
- return [4 /*yield*/, this.getFileText(project.id, branchName, "".concat(rootDir, "/package.json"))];
144
+ case 0: return [4 /*yield*/, this.isInPrerelease(options.branchName)];
229
145
  case 1:
230
- packageJson = _a.sent();
231
- return [4 /*yield*/, this.getFileText(project.id, branchName, "".concat(rootDir, "/package-lock.json"))];
232
- case 2:
233
- packageLock = _a.sent();
234
- packageJsonObj = JSON.parse(packageJson);
235
- utils_1.Logger.logMessage(project.title);
146
+ isInPrerelease = _a.sent();
236
147
  /**
237
- * Annoyingly some projects have clickview packages sitting in dependencies
238
- * and others have it in devDependencies
148
+ * The `lerna version prerelease` script only cares about incrementing the preId part
149
+ * of the version number. That's why we run this if `isInPrerelease` is true.
150
+ *
151
+ * E.g. this would change 0.0.1-dev.0 to 0.0.0-dev.1
239
152
  */
240
- if (packageJsonObj.dependencies)
241
- packageJson = this.replaceVersions(packageJson, versions, packageJsonObj.dependencies);
242
- if (packageJsonObj.devDependencies)
243
- packageJson = this.replaceVersions(packageJson, versions, packageJsonObj.devDependencies);
244
- outputPath = this.getOutputPath(project, milestone);
245
- return [4 /*yield*/, fs_extra_1.default.outputFile("".concat(outputPath, "/package.json"), packageJson, { encoding: 'utf8' })];
246
- case 3:
247
- _a.sent();
248
- return [4 /*yield*/, fs_extra_1.default.outputFile("".concat(outputPath, "/package-lock.json"), packageLock, { encoding: 'utf8' })];
249
- case 4:
250
- _a.sent();
251
- return [2 /*return*/];
153
+ if (isInPrerelease && options.preId) {
154
+ utils_1.Logger.logMessage("Incrementing \"".concat(options.preId, "\" preId for each package."));
155
+ return [2 /*return*/, "lerna version prerelease --preid ".concat(options.preId, " ").concat(SHARED_LERNA_OPTIONS)];
156
+ }
157
+ // Bump the patch with the preId "dev". We currently only support dev prereleases on patch versions
158
+ if (options.preId === 'dev') {
159
+ utils_1.Logger.logMessage("Incrementing the patch version for each package and appending preId: \"dev\".");
160
+ return [2 /*return*/, "lerna version prepatch --preid dev ".concat(SHARED_LERNA_OPTIONS)];
161
+ }
162
+ if (options.preId === 'rc') {
163
+ // Bump the minor number with the preId "rc". Release branches always bump the minor number.
164
+ if (this.isReleaseBranch) {
165
+ utils_1.Logger.logMessage("Incrementing the minor version for each package and appending preId: \"rc\".");
166
+ return [2 /*return*/, "lerna version preminor --preid rc ".concat(SHARED_LERNA_OPTIONS)];
167
+ }
168
+ // Bump the patch with the preId "rc". Hotfix branches always bump the patch number.
169
+ if (this.isHotfixBranch) {
170
+ utils_1.Logger.logMessage("Incrementing the patch version for each package and appending preId: \"rc\".");
171
+ return [2 /*return*/, "lerna version prepatch --preid rc ".concat(SHARED_LERNA_OPTIONS)];
172
+ }
173
+ }
174
+ /**
175
+ * If no preId is provided, we bump the version number to a production version.
176
+ *
177
+ * Release branch = minor bump
178
+ * Hotfix branch = patch bump
179
+ */
180
+ if (this.isReleaseBranch) {
181
+ utils_1.Logger.logMessage('Updating each package to production release version.');
182
+ return [2 /*return*/, "lerna version minor ".concat(SHARED_LERNA_OPTIONS)];
183
+ }
184
+ if (this.isHotfixBranch) {
185
+ utils_1.Logger.logMessage('Updating each package to production hotfix version.');
186
+ return [2 /*return*/, "lerna version patch ".concat(SHARED_LERNA_OPTIONS)];
187
+ }
188
+ // Should never be reached
189
+ return [2 /*return*/, ''];
252
190
  }
253
191
  });
254
192
  });
255
193
  };
256
- BumpPackagesTask.prototype.replaceVersions = function (packageJson, versions, deps) {
257
- Object.keys(deps).forEach(function (key) {
258
- if (!key.startsWith('@clickview'))
259
- return;
260
- if (!versions[key])
261
- return;
262
- var oldVersion = deps[key];
263
- var newVersion = versions[key];
264
- if (oldVersion === newVersion) {
265
- utils_1.Logger.logWarning("- [".concat(key, "]: ").concat(versions[key], " is up to date"));
266
- return;
267
- }
268
- if (semver_1.default.compare(oldVersion, newVersion) === 1) {
269
- utils_1.Logger.logError("- [".concat(key, "]: ").concat(deps[key], " -> ").concat(versions[key], " downgrade detected"));
270
- return;
271
- }
272
- packageJson = packageJson.replace("\"".concat(key, "\": \"").concat(deps[key], "\""), "\"".concat(key, "\": \"").concat(versions[key], "\""));
273
- utils_1.Logger.logMessage("- [".concat(key, "]: ").concat(deps[key], " -> ").concat(versions[key]));
274
- });
275
- return packageJson;
276
- };
277
- BumpPackagesTask.prototype.getPackageVersions = function (branchName) {
194
+ BumpPackagesTask.prototype.isInPrerelease = function (branchName) {
278
195
  return __awaiter(this, void 0, void 0, function () {
279
- var monorepoPackages, _i, MONOREPO_PACKAGES_FILES_1, file, text, json;
196
+ var _i, MONOREPO_PACKAGE_JSON_FILES_1, file, text, json;
280
197
  return __generator(this, function (_a) {
281
198
  switch (_a.label) {
282
199
  case 0:
283
- monorepoPackages = {};
284
- _i = 0, MONOREPO_PACKAGES_FILES_1 = MONOREPO_PACKAGES_FILES;
200
+ _i = 0, MONOREPO_PACKAGE_JSON_FILES_1 = MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES;
285
201
  _a.label = 1;
286
202
  case 1:
287
- if (!(_i < MONOREPO_PACKAGES_FILES_1.length)) return [3 /*break*/, 4];
288
- file = MONOREPO_PACKAGES_FILES_1[_i];
203
+ if (!(_i < MONOREPO_PACKAGE_JSON_FILES_1.length)) return [3 /*break*/, 4];
204
+ file = MONOREPO_PACKAGE_JSON_FILES_1[_i];
289
205
  return [4 /*yield*/, this.getFileText(utils_1.ProjectIds.MONOREPO_PROJECT_ID, branchName, file)];
290
206
  case 2:
291
207
  text = _a.sent();
292
208
  json = JSON.parse(text);
293
- monorepoPackages[json.name] = json.version;
209
+ if (RC_VERSION_REGEX.test(json.version))
210
+ return [2 /*return*/, true];
211
+ if (DEV_VERSION_REGEX.test(json.version))
212
+ return [2 /*return*/, true];
294
213
  _a.label = 3;
295
214
  case 3:
296
215
  _i++;
297
216
  return [3 /*break*/, 1];
298
- case 4: return [2 /*return*/, monorepoPackages];
299
- }
300
- });
301
- });
302
- };
303
- BumpPackagesTask.prototype.getFileText = function (projectId, branchName, fileName) {
304
- return __awaiter(this, void 0, void 0, function () {
305
- var file, buff;
306
- return __generator(this, function (_a) {
307
- switch (_a.label) {
308
- case 0: return [4 /*yield*/, this._service.getFile(projectId, branchName, fileName)];
309
- case 1:
310
- file = _a.sent();
311
- if (!file)
312
- return [2 /*return*/, ''];
313
- buff = Buffer.from(file.content, 'base64');
314
- return [2 /*return*/, buff.toString('utf-8')];
217
+ case 4: return [2 /*return*/, false];
315
218
  }
316
219
  });
317
220
  });
318
221
  };
319
- BumpPackagesTask.prototype.getBranchName = function (projectId, version) {
320
- return __awaiter(this, void 0, void 0, function () {
321
- var currentVersionTag, nextVersion, branchName, branch;
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
324
- case 0: return [4 /*yield*/, this._service.getCurrentVersionTag(projectId)];
325
- case 1:
326
- currentVersionTag = _a.sent();
327
- if (!currentVersionTag)
328
- return [2 /*return*/, null];
329
- return [4 /*yield*/, utils_1.Versions.getNextVersion(currentVersionTag.name, version)];
330
- case 2:
331
- nextVersion = _a.sent();
332
- branchName = utils_1.BranchNames.getRelease(nextVersion);
333
- return [4 /*yield*/, this._service.getBranch(projectId, branchName)];
334
- case 3:
335
- branch = _a.sent();
336
- if (!branch)
337
- return [2 /*return*/, null];
338
- return [2 /*return*/, branchName];
339
- }
340
- });
341
- });
342
- };
343
- BumpPackagesTask.prototype.getOutputPath = function (project, milestone) {
344
- return "./temp/".concat(milestone, "/").concat(project.title);
345
- };
346
222
  BumpPackagesTask = __decorate([
347
223
  (0, inversify_1.injectable)(),
348
224
  __param(0, (0, inversify_1.inject)(types_1.SERVICES.GitLabService)),
@@ -54,53 +54,40 @@ var inversify_1 = require("inversify");
54
54
  var Logger_1 = require("../utils/Logger");
55
55
  var types_1 = require("../types");
56
56
  var services_1 = require("../services");
57
- var utils_1 = require("../utils");
58
57
  var BumpVersionTxtTask = /** @class */ (function () {
59
58
  function BumpVersionTxtTask(service) {
60
- this._service = service;
59
+ this.service = service;
61
60
  }
62
61
  BumpVersionTxtTask.prototype.run = function (options) {
63
62
  return __awaiter(this, void 0, void 0, function () {
64
- var projects, cont, _i, projects_1, project, currentVersionTag, nextVersion, branchName, versionBumped;
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
63
+ var projects, _i, projects_1, project, _a, nextVersion, branchName, versionBumped;
64
+ return __generator(this, function (_b) {
65
+ switch (_b.label) {
67
66
  case 0:
68
67
  Logger_1.Logger.logTask('Bumping version.txt');
69
- return [4 /*yield*/, this._service.getProjects(options)];
68
+ return [4 /*yield*/, this.service.getProjects(options)];
70
69
  case 1:
71
- projects = _a.sent();
72
- if (!projects.length) {
73
- Logger_1.Logger.logError("No projects could be found with the specified options");
74
- return [2 /*return*/, false];
75
- }
76
- cont = true;
70
+ projects = _b.sent();
77
71
  _i = 0, projects_1 = projects;
78
- _a.label = 2;
72
+ _b.label = 2;
79
73
  case 2:
80
74
  if (!(_i < projects_1.length)) return [3 /*break*/, 6];
81
75
  project = projects_1[_i];
82
- return [4 /*yield*/, this._service.getCurrentVersionTag(project.id)];
76
+ return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
83
77
  case 3:
84
- currentVersionTag = _a.sent();
85
- if (currentVersionTag === null) {
86
- Logger_1.Logger.logError("[".concat(project.title, "]: Could not find current version tag"));
87
- cont = false;
88
- return [3 /*break*/, 5];
89
- }
90
- nextVersion = utils_1.Versions.getNextVersion(currentVersionTag.name, options.version);
91
- branchName = utils_1.BranchNames.getRelease(nextVersion);
92
- return [4 /*yield*/, this._service.bumpVersionTxt(project.id, branchName, nextVersion)];
78
+ _a = _b.sent(), nextVersion = _a.nextVersion, branchName = _a.branchName;
79
+ return [4 /*yield*/, this.service.bumpVersionTxt(project.id, branchName, nextVersion)];
93
80
  case 4:
94
- versionBumped = _a.sent();
81
+ versionBumped = _b.sent();
95
82
  if (versionBumped)
96
83
  Logger_1.Logger.logMessage("[".concat(project.title, "]: Bumped to ").concat(nextVersion));
97
84
  else
98
85
  Logger_1.Logger.logWarning("[".concat(project.title, "]: Has already been bumped, or does not have a version.txt"));
99
- _a.label = 5;
86
+ _b.label = 5;
100
87
  case 5:
101
88
  _i++;
102
89
  return [3 /*break*/, 2];
103
- case 6: return [2 /*return*/, cont];
90
+ case 6: return [2 /*return*/, true];
104
91
  }
105
92
  });
106
93
  });
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (_) try {
30
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.CommitPackageVersionsTask = void 0;
52
+ require("reflect-metadata");
53
+ var fs_1 = require("fs");
54
+ var inversify_1 = require("inversify");
55
+ var types_1 = require("../types");
56
+ var services_1 = require("../services");
57
+ var MonorepoPackageJsonFiles_1 = require("../constants/MonorepoPackageJsonFiles");
58
+ var utils_1 = require("../utils");
59
+ var CommitPackageVersionsTask = /** @class */ (function () {
60
+ function CommitPackageVersionsTask(service) {
61
+ this.service = service;
62
+ }
63
+ CommitPackageVersionsTask.prototype.run = function (options) {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var branch, commitFiles;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0:
69
+ utils_1.Logger.logTask('Committing clickview npm package versions');
70
+ return [4 /*yield*/, this.service.getBranch(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
71
+ case 1:
72
+ branch = _a.sent();
73
+ if (!branch) {
74
+ utils_1.Logger.logError("Branch with name ".concat(options.branchName, " was not be found."));
75
+ return [2 /*return*/, false];
76
+ }
77
+ commitFiles = this.getCommitFiles();
78
+ return [4 /*yield*/, this.service.commit(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName, 'Bump package versions', commitFiles)];
79
+ case 2:
80
+ _a.sent();
81
+ utils_1.Logger.logSuccess('Successfully committed package versions.');
82
+ return [2 /*return*/, true];
83
+ }
84
+ });
85
+ });
86
+ };
87
+ CommitPackageVersionsTask.prototype.getCommitFiles = function () {
88
+ var commitFiles = [];
89
+ for (var _i = 0, MONOREPO_PACKAGE_JSON_FILES_1 = MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES; _i < MONOREPO_PACKAGE_JSON_FILES_1.length; _i++) {
90
+ var filePath = MONOREPO_PACKAGE_JSON_FILES_1[_i];
91
+ commitFiles.push({
92
+ filePath: filePath,
93
+ content: (0, fs_1.readFileSync)(filePath, { encoding: 'utf8' })
94
+ });
95
+ }
96
+ return commitFiles;
97
+ };
98
+ CommitPackageVersionsTask = __decorate([
99
+ (0, inversify_1.injectable)(),
100
+ __param(0, (0, inversify_1.inject)(types_1.SERVICES.GitLabService)),
101
+ __metadata("design:paramtypes", [services_1.GitLabService])
102
+ ], CommitPackageVersionsTask);
103
+ return CommitPackageVersionsTask;
104
+ }());
105
+ exports.CommitPackageVersionsTask = CommitPackageVersionsTask;