@clickview/ship-it 0.0.2-dev.0 → 0.0.2-dev.2

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 (39) hide show
  1. package/lib/src/api-clients/GitLabApiClient.js +1 -1
  2. package/lib/src/api-clients/git-lab/GitLabApiClient.js +285 -0
  3. package/lib/src/api-clients/git-lab/GitLabMapper.js +51 -0
  4. package/lib/src/api-clients/index.js +1 -1
  5. package/lib/src/commands/BumpPackagesCommand.js +10 -2
  6. package/lib/src/commands/CommitPackageVersionsCommand.js +78 -0
  7. package/lib/src/commands/CreateBranchCommand.js +8 -8
  8. package/lib/src/commands/CreateMergeRequestCommand.js +10 -10
  9. package/lib/src/commands/CreateReleaseNotesCommand.js +4 -4
  10. package/lib/src/commands/ReleaseCommand.js +14 -14
  11. package/lib/src/commands/StatusCommand.js +2 -2
  12. package/lib/src/commands/VersionCommand.js +2 -2
  13. package/lib/src/constants/index.js +2 -2
  14. package/lib/src/errors/ShipItError.js +32 -0
  15. package/lib/src/errors/index.js +17 -0
  16. package/lib/src/interfaces/VersionType.js +2 -0
  17. package/lib/src/interfaces/command-options/CommitPackageVersionsCommandOptions.js +2 -0
  18. package/lib/src/interfaces/index.js +1 -0
  19. package/lib/src/inversify.config.js +1 -0
  20. package/lib/src/services/GitLabService.js +60 -33
  21. package/lib/src/startup/AddMilestoneCommand.js +2 -2
  22. package/lib/src/startup/SetupCommands.js +3 -4
  23. package/lib/src/tasks/BumpPackagesTask.js +49 -30
  24. package/lib/src/tasks/BumpVersionTxtTask.js +13 -26
  25. package/lib/src/tasks/CommitLocalPackagesTask.js +137 -0
  26. package/lib/src/tasks/CommitPackageVersionsTask.js +111 -0
  27. package/lib/src/tasks/CreateBranchTask.js +17 -32
  28. package/lib/src/tasks/CreateMergeRequestTask.js +21 -36
  29. package/lib/src/tasks/CreateReleaseNotesTask.js +2 -6
  30. package/lib/src/tasks/InstallPackagesTask.js +65 -92
  31. package/lib/src/tasks/ValidateCommitsTask.js +6 -14
  32. package/lib/src/tasks/ValidateDescriptionsTask.js +4 -8
  33. package/lib/src/tasks/ValidateTask.js +5 -6
  34. package/lib/src/tasks/VersionTask.js +7 -20
  35. package/lib/src/tasks/index.js +1 -0
  36. package/lib/src/types.js +2 -1
  37. package/lib/src/utils/Descriptions.js +5 -4
  38. package/lib/src/utils/ProjectIds.js +6 -2
  39. package/package.json +22 -22
@@ -54,13 +54,13 @@ var inversify_1 = require("inversify");
54
54
  var types_1 = require("../types");
55
55
  var StatusCommand = /** @class */ (function () {
56
56
  function StatusCommand(validateTask) {
57
- this._validateTask = validateTask;
57
+ this.validateTask = validateTask;
58
58
  }
59
59
  StatusCommand.prototype.run = function (options) {
60
60
  return __awaiter(this, void 0, void 0, function () {
61
61
  return __generator(this, function (_a) {
62
62
  switch (_a.label) {
63
- case 0: return [4 /*yield*/, this._validateTask.run(options)];
63
+ case 0: return [4 /*yield*/, this.validateTask.run(options)];
64
64
  case 1:
65
65
  _a.sent();
66
66
  return [2 /*return*/];
@@ -54,13 +54,13 @@ var inversify_1 = require("inversify");
54
54
  var types_1 = require("../types");
55
55
  var VersionCommand = /** @class */ (function () {
56
56
  function VersionCommand(versionTask) {
57
- this._versionTask = versionTask;
57
+ this.versionTask = versionTask;
58
58
  }
59
59
  VersionCommand.prototype.run = function (options) {
60
60
  return __awaiter(this, void 0, void 0, function () {
61
61
  return __generator(this, function (_a) {
62
62
  switch (_a.label) {
63
- case 0: return [4 /*yield*/, this._versionTask.run(options)];
63
+ case 0: return [4 /*yield*/, this.versionTask.run(options)];
64
64
  case 1:
65
65
  _a.sent();
66
66
  return [2 /*return*/];
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./CommandTypeMapping"), exports);
18
- __exportStar(require("./MonorepoPackageJsonFiles"), exports);
17
+ __exportStar(require("./CommandTypeMapping.js"), exports);
18
+ __exportStar(require("./MonorepoPackageJsonFiles.js"), exports);
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ShipItError = void 0;
19
+ var ShipItError = /** @class */ (function (_super) {
20
+ __extends(ShipItError, _super);
21
+ function ShipItError(message) {
22
+ var _this = _super.call(this, message) || this;
23
+ /**
24
+ * Need to do this to extend errors in typescript and still be able to use instanceof in a catch statement
25
+ * https://stackoverflow.com/questions/31626231/custom-error-class-in-typescript/41429145
26
+ */
27
+ Object.setPrototypeOf(_this, ShipItError.prototype);
28
+ return _this;
29
+ }
30
+ return ShipItError;
31
+ }(Error));
32
+ exports.ShipItError = ShipItError;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ShipItError"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -20,3 +20,4 @@ __exportStar(require("./view-models"), exports);
20
20
  __exportStar(require("./Config"), exports);
21
21
  __exportStar(require("./ShipItCommand"), exports);
22
22
  __exportStar(require("./ShipItTask"), exports);
23
+ __exportStar(require("./VersionType"), exports);
@@ -34,6 +34,7 @@ function createContainer(config) {
34
34
  container.bind(types_1.TASKS.CreateReleaseNotesTask).to(tasks_1.CreateReleaseNotesTask);
35
35
  container.bind(types_1.TASKS.InstallPackagesTask).to(tasks_1.InstallPackagesTask);
36
36
  container.bind(types_1.TASKS.BumpPackagesTask).to(tasks_1.BumpPackagesTask);
37
+ container.bind(types_1.TASKS.CommitPackageVersionsTask).to(tasks_1.CommitPackageVersionsTask);
37
38
  /**
38
39
  * Commands
39
40
  */
@@ -69,9 +69,11 @@ var lodash_1 = __importDefault(require("lodash"));
69
69
  var semver_1 = __importDefault(require("semver"));
70
70
  var types_1 = require("../types");
71
71
  var api_clients_1 = require("../api-clients");
72
+ var errors_1 = require("../errors");
73
+ var utils_1 = require("../utils");
72
74
  var GitLabService = /** @class */ (function () {
73
75
  function GitLabService(apiClient) {
74
- this._apiClient = apiClient;
76
+ this.apiClient = apiClient;
75
77
  }
76
78
  GitLabService.prototype.getProjects = function (options) {
77
79
  return __awaiter(this, void 0, void 0, function () {
@@ -79,20 +81,20 @@ var GitLabService = /** @class */ (function () {
79
81
  return __generator(this, function (_a) {
80
82
  switch (_a.label) {
81
83
  case 0:
82
- if (this._projects)
83
- return [2 /*return*/, this._projects];
84
- return [4 /*yield*/, this._apiClient.getMergeRequests(options)];
84
+ if (this.projects)
85
+ return [2 /*return*/, this.projects];
86
+ return [4 /*yield*/, this.apiClient.getMergeRequests(options)];
85
87
  case 1:
86
88
  mergeRequests = _a.sent();
87
89
  if (!(mergeRequests === null || mergeRequests === void 0 ? void 0 : mergeRequests.length))
88
- throw new Error('Could not find any merge requests for the specified options');
90
+ throw new errors_1.ShipItError('Could not find any merge requests for the specified options');
89
91
  projectIds = lodash_1.default.uniqBy(mergeRequests, function (m) { return m.projectId; }).map(function (m) { return m.projectId; });
90
- return [4 /*yield*/, this._apiClient.getProjectsByIds(projectIds)];
92
+ return [4 /*yield*/, this.apiClient.getProjectsByIds(projectIds)];
91
93
  case 2:
92
94
  projects = _a.sent();
93
95
  if (!(projects === null || projects === void 0 ? void 0 : projects.length) || projects.length !== projectIds.length)
94
- throw new Error('Could not find all projects for the found merge requests');
95
- return [2 /*return*/, (this._projects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); }))];
96
+ throw new errors_1.ShipItError('Could not find all projects for the found merge requests');
97
+ return [2 /*return*/, (this.projects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); }))];
96
98
  }
97
99
  });
98
100
  });
@@ -102,7 +104,7 @@ var GitLabService = /** @class */ (function () {
102
104
  var commits, lastDevCommit, title;
103
105
  return __generator(this, function (_a) {
104
106
  switch (_a.label) {
105
- case 0: return [4 /*yield*/, this._apiClient.getCommitsSince(projectId, 'dev', sinceSha)];
107
+ case 0: return [4 /*yield*/, this.apiClient.getCommitsSince(projectId, 'dev', sinceSha)];
106
108
  case 1:
107
109
  commits = _a.sent();
108
110
  lastDevCommit = lodash_1.default.last(commits);
@@ -113,7 +115,7 @@ var GitLabService = /** @class */ (function () {
113
115
  commits.pop();
114
116
  }
115
117
  if (!(commits === null || commits === void 0 ? void 0 : commits.length))
116
- throw new Error("Could not find any commits in dev for projectId: ".concat(projectId, " since ").concat(sinceSha));
118
+ throw new errors_1.ShipItError("Could not find any commits in dev for projectId: ".concat(projectId, " since ").concat(sinceSha));
117
119
  return [2 /*return*/, commits];
118
120
  }
119
121
  });
@@ -123,7 +125,7 @@ var GitLabService = /** @class */ (function () {
123
125
  return __awaiter(this, void 0, void 0, function () {
124
126
  return __generator(this, function (_a) {
125
127
  switch (_a.label) {
126
- case 0: return [4 /*yield*/, this._apiClient.getBranch(projectId, branchName)];
128
+ case 0: return [4 /*yield*/, this.apiClient.getBranch(projectId, branchName)];
127
129
  case 1: return [2 /*return*/, _a.sent()];
128
130
  }
129
131
  });
@@ -131,53 +133,47 @@ var GitLabService = /** @class */ (function () {
131
133
  };
132
134
  GitLabService.prototype.createBranch = function (project, branchFrom, branchName, cherryPick) {
133
135
  return __awaiter(this, void 0, void 0, function () {
134
- var newBranch_1, i, mr, newBranch;
136
+ var newBranch, i, mr;
135
137
  return __generator(this, function (_a) {
136
138
  switch (_a.label) {
137
139
  case 0:
138
140
  if (!cherryPick) return [3 /*break*/, 6];
139
- return [4 /*yield*/, this._apiClient.createBranch(project.id, branchName, 'master')];
141
+ return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, 'master')];
140
142
  case 1:
141
- newBranch_1 = _a.sent();
142
- if (!newBranch_1)
143
- throw new Error("Failed to create branch from master for projectId: ".concat(project.id));
143
+ newBranch = _a.sent();
144
144
  i = 0;
145
145
  _a.label = 2;
146
146
  case 2:
147
147
  if (!(i < project.mergeRequests.length)) return [3 /*break*/, 5];
148
148
  mr = project.mergeRequests[i];
149
149
  if (!mr.mergeCommit)
150
- throw new Error("Could not find the merge commit sha for MR: ".concat(mr.title, " in projectId: ").concat(project.id));
151
- return [4 /*yield*/, this._apiClient.cherryPick(project.id, mr.mergeCommit, branchName)];
150
+ throw new errors_1.ShipItError("Could not find the merge commit sha for MR: ".concat(mr.title, " in projectId: ").concat(project.id));
151
+ return [4 /*yield*/, this.apiClient.cherryPick(project.id, mr.mergeCommit, branchName)];
152
152
  case 3:
153
153
  _a.sent();
154
154
  _a.label = 4;
155
155
  case 4:
156
156
  i++;
157
157
  return [3 /*break*/, 2];
158
- case 5: return [2 /*return*/, newBranch_1];
159
- case 6: return [4 /*yield*/, this._apiClient.createBranch(project.id, branchName, branchFrom)];
160
- case 7:
161
- newBranch = _a.sent();
162
- if (!newBranch)
163
- throw new Error("Failed to create branch from master for projectId: ".concat(project.id));
164
- return [2 /*return*/, newBranch];
158
+ case 5: return [2 /*return*/, newBranch];
159
+ case 6: return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, branchFrom)];
160
+ case 7: return [2 /*return*/, _a.sent()];
165
161
  }
166
162
  });
167
163
  });
168
164
  };
169
165
  GitLabService.prototype.getMergeRequest = function (projectId, branchName) {
170
- return this._apiClient.getMergeRequest(projectId, branchName, 'master');
166
+ return this.apiClient.getMergeRequest(projectId, branchName, 'master');
171
167
  };
172
168
  GitLabService.prototype.createMergeRequest = function (projectId, branchName, description) {
173
- return this._apiClient.createMergeRequest(projectId, branchName, 'master', branchName, description);
169
+ return this.apiClient.createMergeRequest(projectId, branchName, 'master', branchName, description);
174
170
  };
175
171
  GitLabService.prototype.bumpVersionTxt = function (projectId, branchName, newVersion) {
176
172
  return __awaiter(this, void 0, void 0, function () {
177
173
  var versionTxt, buff, text;
178
174
  return __generator(this, function (_a) {
179
175
  switch (_a.label) {
180
- case 0: return [4 /*yield*/, this._apiClient.getFile(projectId, 'version.txt', branchName)];
176
+ case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, 'version.txt', branchName)];
181
177
  case 1:
182
178
  versionTxt = _a.sent();
183
179
  if (!versionTxt)
@@ -186,7 +182,7 @@ var GitLabService = /** @class */ (function () {
186
182
  text = buff.toString('utf-8');
187
183
  if (text === newVersion)
188
184
  return [2 /*return*/, false];
189
- return [4 /*yield*/, this._apiClient.updateFile(projectId, 'version.txt', branchName, newVersion, 'Bumping version.txt')];
185
+ return [4 /*yield*/, this.apiClient.updateFile(projectId, 'version.txt', branchName, newVersion, 'Bumping version.txt')];
190
186
  case 2:
191
187
  _a.sent();
192
188
  return [2 /*return*/, true];
@@ -198,20 +194,20 @@ var GitLabService = /** @class */ (function () {
198
194
  return __awaiter(this, void 0, void 0, function () {
199
195
  return __generator(this, function (_a) {
200
196
  switch (_a.label) {
201
- case 0: return [4 /*yield*/, this._apiClient.getFile(projectId, file, branchName)];
197
+ case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, file, branchName)];
202
198
  case 1: return [2 /*return*/, _a.sent()];
203
199
  }
204
200
  });
205
201
  });
206
202
  };
207
203
  GitLabService.prototype.updateFile = function (projectId, filePath, branchName, content, commit) {
208
- return this._apiClient.updateFile(projectId, filePath, branchName, content, commit);
204
+ return this.apiClient.updateFile(projectId, filePath, branchName, content, commit);
209
205
  };
210
206
  GitLabService.prototype.commit = function (projectId, branchName, commitMessage, files) {
211
207
  return __awaiter(this, void 0, void 0, function () {
212
208
  return __generator(this, function (_a) {
213
209
  switch (_a.label) {
214
- case 0: return [4 /*yield*/, this._apiClient.commit(projectId, branchName, files, commitMessage)];
210
+ case 0: return [4 /*yield*/, this.apiClient.commit(projectId, branchName, files, commitMessage)];
215
211
  case 1:
216
212
  _a.sent();
217
213
  return [2 /*return*/];
@@ -219,12 +215,16 @@ var GitLabService = /** @class */ (function () {
219
215
  });
220
216
  });
221
217
  };
218
+ /**
219
+ * We use the latest valid semver tag in master to determine what the current version
220
+ * of a project is
221
+ */
222
222
  GitLabService.prototype.getCurrentVersionTag = function (projectId) {
223
223
  return __awaiter(this, void 0, void 0, function () {
224
224
  var tags, tagNames, sortedTagNames, currentVersion, currentTag;
225
225
  return __generator(this, function (_a) {
226
226
  switch (_a.label) {
227
- case 0: return [4 /*yield*/, this._apiClient.getLatestTags(projectId)];
227
+ case 0: return [4 /*yield*/, this.apiClient.getLatestTags(projectId)];
228
228
  case 1:
229
229
  tags = _a.sent();
230
230
  if (!(tags === null || tags === void 0 ? void 0 : tags.length))
@@ -242,6 +242,33 @@ var GitLabService = /** @class */ (function () {
242
242
  });
243
243
  });
244
244
  };
245
+ GitLabService.prototype.getNextBranchInfo = function (projectId, version) {
246
+ return __awaiter(this, void 0, void 0, function () {
247
+ var tag, nextVersion, branchName, branch;
248
+ return __generator(this, function (_a) {
249
+ switch (_a.label) {
250
+ case 0: return [4 /*yield*/, this.getCurrentVersionTag(projectId)];
251
+ case 1:
252
+ tag = _a.sent();
253
+ if (!tag)
254
+ throw new errors_1.ShipItError("Could not find the latest semver tag for projectId: ".concat(projectId));
255
+ nextVersion = utils_1.Versions.getNextVersion(tag.name, version);
256
+ branchName = version === 'patch' ?
257
+ utils_1.BranchNames.getHotfix(nextVersion) :
258
+ utils_1.BranchNames.getRelease(nextVersion);
259
+ return [4 /*yield*/, this.getBranch(projectId, branchName)];
260
+ case 2:
261
+ branch = _a.sent();
262
+ return [2 /*return*/, {
263
+ nextVersion: nextVersion,
264
+ branchName: branchName,
265
+ branch: branch,
266
+ tag: tag
267
+ }];
268
+ }
269
+ });
270
+ });
271
+ };
245
272
  GitLabService = __decorate([
246
273
  (0, inversify_1.injectable)(),
247
274
  __param(0, (0, inversify_1.inject)(types_1.API_CLIENTS.GitLabApiClient)),
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getAddMilestoneCommand = void 0;
40
- var constants_1 = require("../constants");
40
+ var CommandTypeMapping_1 = require("../constants/CommandTypeMapping");
41
41
  var utils_1 = require("../utils");
42
42
  function processOptions(options) {
43
43
  var opts = {
@@ -65,7 +65,7 @@ var getAddMilestoneCommand = function (program, container) {
65
65
  .option('--major')
66
66
  .action(function (options) { return __awaiter(_this, void 0, void 0, function () {
67
67
  return __generator(this, function (_a) {
68
- container.get(constants_1.CommandTypeMapping[name])
68
+ container.get(CommandTypeMapping_1.CommandTypeMapping[name])
69
69
  .run(processOptions(options));
70
70
  return [2 /*return*/];
71
71
  });
@@ -37,8 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.setupCommands = void 0;
40
- var commander_1 = require("commander");
41
- var constants_1 = require("../constants");
40
+ var CommandTypeMapping_1 = require("../constants/CommandTypeMapping");
42
41
  var AddMilestoneCommand_1 = require("./AddMilestoneCommand");
43
42
  function setupCommands(program, container) {
44
43
  var _this = this;
@@ -54,11 +53,11 @@ function setupCommands(program, container) {
54
53
  program.command('bump-packages')
55
54
  .description('Bump clickview npm package versions in monorepo to their next version')
56
55
  .requiredOption('-b, --branchName <branchName>')
57
- .addOption(new commander_1.Option('-p, --preid <preId>').choices(['dev', 'rc']))
56
+ .option('-p, --preId <preId>')
58
57
  .action(function (options) { return __awaiter(_this, void 0, void 0, function () {
59
58
  return __generator(this, function (_a) {
60
59
  container
61
- .get(constants_1.CommandTypeMapping['bump-packages'])
60
+ .get(CommandTypeMapping_1.CommandTypeMapping['bump-packages'])
62
61
  .run(options);
63
62
  return [2 /*return*/];
64
63
  });
@@ -54,12 +54,13 @@ var inversify_1 = require("inversify");
54
54
  var child_process_1 = require("child_process");
55
55
  var types_1 = require("../types");
56
56
  var services_1 = require("../services");
57
+ var MonorepoPackageJsonFiles_1 = require("../constants/MonorepoPackageJsonFiles");
57
58
  var utils_1 = require("../utils");
58
- var constants_1 = require("../constants");
59
59
  var RELEASE_BRANCH_REGEX = /^release\/(\d|\.)+$/;
60
60
  var HOTFIX_BRANCH_REGEX = /^hotfix\/(\d|\.)+$/;
61
61
  var DEV_VERSION_REGEX = /-dev\.\d+$/;
62
62
  var RC_VERSION_REGEX = /-rc\.\d+$/;
63
+ var SHARED_LERNA_OPTIONS = '--exact --no-git-tag-version --no-push --yes';
63
64
  var BumpPackagesTask = /** @class */ (function () {
64
65
  function BumpPackagesTask(service) {
65
66
  this.isReleaseBranch = false;
@@ -68,26 +69,31 @@ var BumpPackagesTask = /** @class */ (function () {
68
69
  }
69
70
  BumpPackagesTask.prototype.run = function (options) {
70
71
  return __awaiter(this, void 0, void 0, function () {
71
- var mergeRequest, isValid, bumpCommand;
72
+ var branch, isValid, lernaVersionCmd;
72
73
  return __generator(this, function (_a) {
73
74
  switch (_a.label) {
74
75
  case 0:
75
76
  utils_1.Logger.logTask('Bumping clickview npm package versions');
76
77
  this.isReleaseBranch = RELEASE_BRANCH_REGEX.test(options.branchName);
77
78
  this.isHotfixBranch = HOTFIX_BRANCH_REGEX.test(options.branchName);
78
- mergeRequest = this.service.getMergeRequest(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName);
79
- if (!mergeRequest) {
80
- utils_1.Logger.logError("Merge request for branch ".concat(options.branchName, " could not be found."));
79
+ return [4 /*yield*/, this.service.getBranch(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
80
+ case 1:
81
+ branch = _a.sent();
82
+ if (!branch) {
83
+ utils_1.Logger.logError("Branch with name ".concat(options.branchName, " was not be found."));
81
84
  return [2 /*return*/, false];
82
85
  }
83
86
  isValid = this.validateOptions(options);
84
87
  if (!isValid)
85
88
  return [2 /*return*/, false];
86
- return [4 /*yield*/, this.getBumpCommand(options)];
87
- case 1:
88
- bumpCommand = _a.sent();
89
- // console.log('bump command is:', bumpCommand);
90
- (0, child_process_1.execSync)("npm run ".concat(bumpCommand));
89
+ return [4 /*yield*/, this.getLernaCommand(options)];
90
+ case 2:
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.');
94
+ return [2 /*return*/, false];
95
+ }
96
+ (0, child_process_1.execSync)(lernaVersionCmd);
91
97
  return [2 /*return*/, true];
92
98
  }
93
99
  });
@@ -95,6 +101,10 @@ var BumpPackagesTask = /** @class */ (function () {
95
101
  };
96
102
  BumpPackagesTask.prototype.validateOptions = function (options) {
97
103
  var isValidReleaseBranch = this.isReleaseBranch || this.isHotfixBranch;
104
+ if (options.preId && options.preId !== 'rc' && options.preId !== 'dev') {
105
+ utils_1.Logger.logError("Argument for \"preId\" can only be \"rc\" or \"dev\". You entered: ".concat(options.preId));
106
+ return false;
107
+ }
98
108
  if (options.preId === 'dev' && isValidReleaseBranch) {
99
109
  utils_1.Logger.logError('Dev versions cannot be generated on release or hotfix branches.');
100
110
  return false;
@@ -125,47 +135,56 @@ var BumpPackagesTask = /** @class */ (function () {
125
135
  });
126
136
  });
127
137
  };
128
- BumpPackagesTask.prototype.getBumpCommand = function (options) {
138
+ BumpPackagesTask.prototype.getLernaCommand = function (options) {
129
139
  return __awaiter(this, void 0, void 0, function () {
130
- var hasBumpedOnce;
140
+ var isInPrerelease;
131
141
  return __generator(this, function (_a) {
132
142
  switch (_a.label) {
133
- case 0: return [4 /*yield*/, this.hasBumpedOnce(options.branchName)];
143
+ case 0: return [4 /*yield*/, this.isInPrerelease(options.branchName)];
134
144
  case 1:
135
- hasBumpedOnce = _a.sent();
145
+ isInPrerelease = _a.sent();
146
+ /**
147
+ * The `lerna version prerelease` script only cares about incrementing the preId part
148
+ * of the version number. That's why we run this if `isInPrerelease` is true.
149
+ *
150
+ * E.g. this would change 0.0.1-dev.0 to 0.0.0-dev.1
151
+ */
152
+ if (isInPrerelease && options.preId)
153
+ return [2 /*return*/, "lerna version prerelease --preid ".concat(options.preId, " ").concat(SHARED_LERNA_OPTIONS)];
154
+ // Bump the patch with the preId "dev". We currently only support dev prereleases on patch versions
155
+ if (options.preId === 'dev')
156
+ return [2 /*return*/, "lerna version prepatch --preid dev ".concat(SHARED_LERNA_OPTIONS)];
136
157
  if (options.preId === 'rc') {
137
- if (hasBumpedOnce)
138
- return [2 /*return*/, 'lerna-prerelease-rc'];
158
+ // Bump the minor number with the preId "rc". Release branches always bump the minor number.
139
159
  if (this.isReleaseBranch)
140
- return [2 /*return*/, 'lerna-preminor-rc'];
160
+ return [2 /*return*/, "lerna version preminor --preid rc ".concat(SHARED_LERNA_OPTIONS)];
161
+ // Bump the patch with the preId "rc". Hotfix branches always bump the patch number.
141
162
  if (this.isHotfixBranch)
142
- return [2 /*return*/, 'lerna-prepatch-rc'];
143
- }
144
- if (options.preId === 'dev') {
145
- if (hasBumpedOnce)
146
- return [2 /*return*/, 'lerna-prerelease-dev'];
147
- return [2 /*return*/, 'lerna-prepatch-dev'];
163
+ return [2 /*return*/, "lerna version prepatch --preid rc ".concat(SHARED_LERNA_OPTIONS)];
148
164
  }
165
+ /**
166
+ * If no preId is provided, we bump the version number to a production version.
167
+ *
168
+ * Release branch = minor bump
169
+ * Hotfix branch = patch bump
170
+ */
149
171
  if (this.isReleaseBranch)
150
- return [2 /*return*/, 'lerna-minor'];
172
+ return [2 /*return*/, "lerna version minor ".concat(SHARED_LERNA_OPTIONS)];
151
173
  if (this.isHotfixBranch)
152
- return [2 /*return*/, 'lerna-patch'];
174
+ return [2 /*return*/, "lerna version patch ".concat(SHARED_LERNA_OPTIONS)];
153
175
  // Should never be reached
154
176
  return [2 /*return*/, ''];
155
177
  }
156
178
  });
157
179
  });
158
180
  };
159
- /**
160
- * If a package in the release already has a version
161
- */
162
- BumpPackagesTask.prototype.hasBumpedOnce = function (branchName) {
181
+ BumpPackagesTask.prototype.isInPrerelease = function (branchName) {
163
182
  return __awaiter(this, void 0, void 0, function () {
164
183
  var _i, MONOREPO_PACKAGE_JSON_FILES_1, file, text, json;
165
184
  return __generator(this, function (_a) {
166
185
  switch (_a.label) {
167
186
  case 0:
168
- _i = 0, MONOREPO_PACKAGE_JSON_FILES_1 = constants_1.MONOREPO_PACKAGE_JSON_FILES;
187
+ _i = 0, MONOREPO_PACKAGE_JSON_FILES_1 = MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES;
169
188
  _a.label = 1;
170
189
  case 1:
171
190
  if (!(_i < MONOREPO_PACKAGE_JSON_FILES_1.length)) return [3 /*break*/, 4];
@@ -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
  });