@clickview/ship-it 0.0.39 → 0.0.41
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/Dockerfile +33 -33
- package/README.md +48 -48
- package/config.json +19 -19
- package/dist/I3/I3 Notes Audit.csv +127 -0
- package/dist/J1/J1 Notes Audit.csv +38 -0
- package/dist/J2/J2 Notes Audit.csv +52 -0
- package/dist/L1/L1 Notes Audit.csv +139 -0
- package/lib/config.json +20 -20
- package/lib/src/api-clients/git-lab/GitLabApiClient.js +561 -439
- package/lib/src/api-clients/git-lab/GitLabMapper.js +122 -82
- package/lib/src/api-clients/index.js +20 -20
- package/lib/src/api-clients/slack/SlackApiClient.js +206 -206
- package/lib/src/api-clients/team-city/TeamCityApiClient.js +100 -100
- package/lib/src/api-clients/trello/TrelloApiClient.js +145 -145
- package/lib/src/commands/BumpPackagesCommand.js +76 -76
- package/lib/src/commands/ConfigureProjectsCommand.js +84 -0
- package/lib/src/commands/CreateBranchCommand.js +100 -100
- package/lib/src/commands/CreateMergeRequestCommand.js +107 -107
- package/lib/src/commands/CreateNotesAuditCommand.js +84 -84
- package/lib/src/commands/CreateReleaseNotesCommand.js +95 -95
- package/lib/src/commands/CreateTrelloCardsCommand.js +77 -77
- package/lib/src/commands/InstallPackagesCommand.js +76 -76
- package/lib/src/commands/ListProjectsCommand.js +76 -76
- package/lib/src/commands/ReleaseCommand.js +136 -129
- package/lib/src/commands/StartProjectBuildsCommand.js +76 -76
- package/lib/src/commands/StatusCommand.js +93 -88
- package/lib/src/commands/TagMasterCommand.js +76 -76
- package/lib/src/commands/ValidateMergeRequestCommand.js +76 -76
- package/lib/src/commands/VersionCommand.js +76 -76
- package/lib/src/commands/index.js +31 -30
- package/lib/src/constants/CommandTypeMapping.js +21 -20
- package/lib/src/constants/GitLabMemberIds.js +6 -6
- package/lib/src/constants/MonorepoPackageJsonFiles.js +41 -41
- package/lib/src/constants/MonorepoProjectNames.js +16 -16
- package/lib/src/constants/ProjectNames.js +69 -69
- package/lib/src/constants/SlackUserEmailList.js +13 -13
- package/lib/src/constants/TeamCityBuildIDs.js +46 -46
- package/lib/src/constants/index.js +19 -19
- package/lib/src/errors/ShipItError.js +32 -32
- package/lib/src/errors/index.js +17 -17
- package/lib/src/index.js +18 -18
- package/lib/src/interfaces/Config.js +2 -2
- package/lib/src/interfaces/MergeRequestState.js +2 -2
- package/lib/src/interfaces/ProjectNames.js +2 -2
- package/lib/src/interfaces/ShipItCommand.js +2 -2
- package/lib/src/interfaces/ShipItTask.js +2 -2
- package/lib/src/interfaces/VersionType.js +2 -2
- package/lib/src/interfaces/command-cli-options/MilestoneCommandCliOptions.js +2 -2
- package/lib/src/interfaces/command-cli-options/ReleaseCommandCliOptions.js +2 -2
- package/lib/src/interfaces/command-cli-options/StatusCommandCliOptions.js +2 -2
- package/lib/src/interfaces/command-cli-options/index.js +19 -19
- package/lib/src/interfaces/command-options/BaseCommandOptions.js +2 -2
- package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +2 -2
- package/lib/src/interfaces/command-options/ConfigureProjectsOptions.js +2 -0
- package/lib/src/interfaces/command-options/DockerMilestoneCommandOptions.js +2 -2
- package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +2 -2
- package/lib/src/interfaces/command-options/ReleaseCommandOptions.js +2 -2
- package/lib/src/interfaces/command-options/StatusCommandOptions.js +2 -2
- package/lib/src/interfaces/command-options/ValidateMRCommandOptions.js +2 -2
- package/lib/src/interfaces/command-options/index.js +23 -22
- package/lib/src/interfaces/index.js +26 -26
- package/lib/src/interfaces/models/ApprovalRule.js +2 -0
- package/lib/src/interfaces/models/ApprovalRuleConfiguration.js +2 -0
- package/lib/src/interfaces/models/Branch.js +2 -2
- package/lib/src/interfaces/models/Commit.js +2 -2
- package/lib/src/interfaces/models/CommitFile.js +2 -2
- package/lib/src/interfaces/models/CreateApprovalRuleRequest.js +2 -0
- package/lib/src/interfaces/models/File.js +2 -2
- package/lib/src/interfaces/models/Group.js +2 -0
- package/lib/src/interfaces/models/Label.js +2 -2
- package/lib/src/interfaces/models/MergeRequest.js +2 -2
- package/lib/src/interfaces/models/Milestone.js +2 -2
- package/lib/src/interfaces/models/Project.js +2 -2
- package/lib/src/interfaces/models/ProjectConfig.js +9 -9
- package/lib/src/interfaces/models/ProtectedBranch.js +2 -0
- package/lib/src/interfaces/models/Release.js +2 -2
- package/lib/src/interfaces/models/Tag.js +2 -2
- package/lib/src/interfaces/models/index.js +32 -26
- package/lib/src/interfaces/view-models/MilestoneProject.js +2 -2
- package/lib/src/interfaces/view-models/index.js +17 -17
- package/lib/src/inversify.config.js +79 -74
- package/lib/src/services/GitLabService.js +544 -510
- package/lib/src/services/SlackService.js +142 -142
- package/lib/src/services/TeamCityService.js +37 -37
- package/lib/src/services/TrelloService.js +84 -84
- package/lib/src/services/index.js +20 -20
- package/lib/src/startup/AddMilestoneCommand.js +96 -96
- package/lib/src/startup/GetAction.js +68 -68
- package/lib/src/startup/SetupCommands.js +180 -168
- package/lib/src/tasks/BumpPackagesTask.js +230 -230
- package/lib/src/tasks/BumpVersionTxtTask.js +110 -110
- package/lib/src/tasks/CommitPackageVersionsTask.js +116 -0
- package/lib/src/tasks/CreateBranchTask.js +104 -104
- package/lib/src/tasks/CreateMergeRequestTask.js +118 -118
- package/lib/src/tasks/CreateNotesAuditTask.js +140 -140
- package/lib/src/tasks/CreateReleaseNotesTask.js +144 -144
- package/lib/src/tasks/InstallPackagesTask.js +415 -415
- package/lib/src/tasks/ListProjectsTask.js +87 -87
- package/lib/src/tasks/PopulateTrelloBoardTask.js +140 -140
- package/lib/src/tasks/StartMonorepoBuildTask.js +109 -109
- package/lib/src/tasks/StartProjectBuildsTask.js +170 -170
- package/lib/src/tasks/TagMasterTask.js +189 -189
- package/lib/src/tasks/ValidateCommitsTask.js +143 -143
- package/lib/src/tasks/ValidateDescriptionsTask.js +178 -178
- package/lib/src/tasks/ValidateMergeRequestTask.js +115 -115
- package/lib/src/tasks/ValidateTask.js +419 -419
- package/lib/src/tasks/VersionTask.js +98 -98
- package/lib/src/tasks/configure-projects/AddApprovalRulesTask.js +199 -0
- package/lib/src/tasks/configure-projects/CreateToolingBranchTask.js +138 -0
- package/lib/src/tasks/configure-projects/EnsureApprovalRulesTask.js +106 -0
- package/lib/src/tasks/configure-projects/index.js +18 -0
- package/lib/src/tasks/configure-projects/primitives/BaseConfigureProjectsTask.js +98 -0
- package/lib/src/tasks/index.js +34 -33
- package/lib/src/types.js +60 -56
- package/lib/src/utils/BranchNames.js +11 -11
- package/lib/src/utils/Commits.js +55 -55
- package/lib/src/utils/Csv.js +54 -54
- package/lib/src/utils/Descriptions.js +274 -274
- package/lib/src/utils/GroupIds.js +6 -6
- package/lib/src/utils/Logger.js +62 -62
- package/lib/src/utils/ProjectIds.js +47 -47
- package/lib/src/utils/Versions.js +20 -20
- package/lib/src/utils/index.js +22 -22
- package/package.json +50 -50
|
@@ -1,230 +1,230 @@
|
|
|
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.BumpPackagesTask = 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 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 BumpPackagesTask = /** @class */ (function () {
|
|
64
|
-
function BumpPackagesTask(service) {
|
|
65
|
-
this.isReleaseBranch = false;
|
|
66
|
-
this.isHotfixBranch = false;
|
|
67
|
-
this.service = service;
|
|
68
|
-
}
|
|
69
|
-
BumpPackagesTask.prototype.run = function (options) {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var branch, isValid, commitFiles, _i, commitFiles_1, file, newJsonFile;
|
|
72
|
-
return __generator(this, function (_a) {
|
|
73
|
-
switch (_a.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
utils_1.Logger.logTask('Bumping clickview npm package versions');
|
|
76
|
-
this.isReleaseBranch = RELEASE_BRANCH_REGEX.test(options.branchName);
|
|
77
|
-
this.isHotfixBranch = HOTFIX_BRANCH_REGEX.test(options.branchName);
|
|
78
|
-
return [4 /*yield*/, this.service.getBranch(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
|
|
79
|
-
case 1:
|
|
80
|
-
branch = _a.sent();
|
|
81
|
-
if (!branch) {
|
|
82
|
-
utils_1.Logger.logError("Branch with name ".concat(options.branchName, " was not be found."));
|
|
83
|
-
return [2 /*return*/, false];
|
|
84
|
-
}
|
|
85
|
-
isValid = this.validateOptions(options);
|
|
86
|
-
if (!isValid)
|
|
87
|
-
return [2 /*return*/, false];
|
|
88
|
-
utils_1.Logger.logInfo('Options are valid! Proceeding to bump package versions.');
|
|
89
|
-
commitFiles = this.getCommitFiles(options);
|
|
90
|
-
utils_1.Logger.logInfo('Writing new versions to package.json files...');
|
|
91
|
-
for (_i = 0, commitFiles_1 = commitFiles; _i < commitFiles_1.length; _i++) {
|
|
92
|
-
file = commitFiles_1[_i];
|
|
93
|
-
(0, fs_1.writeFileSync)(file.filePath, file.content);
|
|
94
|
-
newJsonFile = JSON.parse(file.content);
|
|
95
|
-
utils_1.Logger.logInfo("Updated version for ".concat(newJsonFile.name, " to ").concat(newJsonFile.version));
|
|
96
|
-
}
|
|
97
|
-
utils_1.Logger.logInfo('Committing new versions...');
|
|
98
|
-
return [4 /*yield*/, this.service.commit(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName, 'Bump package versions', commitFiles)];
|
|
99
|
-
case 2:
|
|
100
|
-
_a.sent();
|
|
101
|
-
utils_1.Logger.logSuccess('Successfully committed updated version numbers.');
|
|
102
|
-
return [2 /*return*/, true];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
BumpPackagesTask.prototype.validateOptions = function (options) {
|
|
108
|
-
var isValidReleaseBranch = this.isReleaseBranch || this.isHotfixBranch;
|
|
109
|
-
if (options.preId && options.preId !== 'rc' && options.preId !== 'dev') {
|
|
110
|
-
utils_1.Logger.logError("Argument for \"preId\" can only be \"rc\" or \"dev\". You entered: ".concat(options.preId));
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
if (options.preId === 'dev' && isValidReleaseBranch) {
|
|
114
|
-
utils_1.Logger.logError('Dev versions cannot be generated on release or hotfix branches.');
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
if (options.preId === 'rc' && !isValidReleaseBranch) {
|
|
118
|
-
utils_1.Logger.logError('Release Candidate versions can only be generated on release or hotfix branches.');
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
if (!options.preId && !isValidReleaseBranch) {
|
|
122
|
-
utils_1.Logger.logError('Production package versions can only be generated on release or hotfix branches.');
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
return true;
|
|
126
|
-
};
|
|
127
|
-
BumpPackagesTask.prototype.getFileText = function (projectId, branchName, fileName) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
-
var file, buff;
|
|
130
|
-
return __generator(this, function (_a) {
|
|
131
|
-
switch (_a.label) {
|
|
132
|
-
case 0: return [4 /*yield*/, this.service.getFile(projectId, branchName, fileName)];
|
|
133
|
-
case 1:
|
|
134
|
-
file = _a.sent();
|
|
135
|
-
if (!file)
|
|
136
|
-
return [2 /*return*/, ''];
|
|
137
|
-
buff = Buffer.from(file.content, 'base64');
|
|
138
|
-
return [2 /*return*/, buff.toString('utf-8')];
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
BumpPackagesTask.prototype.getCommitFiles = function (options) {
|
|
144
|
-
var commitFiles = [];
|
|
145
|
-
for (var _i = 0, _a = Object.entries(MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES_MAP); _i < _a.length; _i++) {
|
|
146
|
-
var _b = _a[_i], projectId = _b[0], packageJsonFilePath = _b[1];
|
|
147
|
-
// Only bump versions for projects with an output directory
|
|
148
|
-
if (!(0, fs_1.existsSync)(MonorepoPackageJsonFiles_1.MONOREPO_DISTS_MAP[projectId]) || !(0, fs_1.statSync)(MonorepoPackageJsonFiles_1.MONOREPO_DISTS_MAP[projectId]).isDirectory())
|
|
149
|
-
continue;
|
|
150
|
-
var content = '';
|
|
151
|
-
try {
|
|
152
|
-
content = (0, fs_1.readFileSync)(packageJsonFilePath, { encoding: 'utf8' });
|
|
153
|
-
}
|
|
154
|
-
catch (_c) {
|
|
155
|
-
/**
|
|
156
|
-
* If the file doesn't exist, ignore the error.
|
|
157
|
-
* This will occur when TC Docker runs this script as it doesn't copy over @clickview/tooling
|
|
158
|
-
*/
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
var json = JSON.parse(content);
|
|
162
|
-
json.version = this.getNextVersion(json.version, options);
|
|
163
|
-
commitFiles.push({
|
|
164
|
-
filePath: packageJsonFilePath,
|
|
165
|
-
content: JSON.stringify(json, null, 2)
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
return commitFiles;
|
|
169
|
-
};
|
|
170
|
-
BumpPackagesTask.prototype.getNextVersion = function (currentVersion, options) {
|
|
171
|
-
if (options.preId)
|
|
172
|
-
return this.getNextPrereleaseVersion(currentVersion, options);
|
|
173
|
-
return this.getNextReleaseVersion(currentVersion);
|
|
174
|
-
};
|
|
175
|
-
BumpPackagesTask.prototype.getNextPrereleaseVersion = function (currentVersion, options) {
|
|
176
|
-
if (options.preId === 'dev') {
|
|
177
|
-
// If version is already a dev version, increment the preId
|
|
178
|
-
// Example: 1.0.0-dev.5 -> 1.0.0-dev.6
|
|
179
|
-
if (DEV_VERSION_REGEX.test(currentVersion)) {
|
|
180
|
-
var _a = currentVersion.split('-dev.'), mainVersion = _a[0], currentPreId = _a[1];
|
|
181
|
-
return "".concat(mainVersion, "-dev.").concat(Number(currentPreId) + 1);
|
|
182
|
-
}
|
|
183
|
-
// Bump the patch version and add the dev preId
|
|
184
|
-
// Example: 1.0.0 -> 1.0.1-dev.0
|
|
185
|
-
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'patch'), "-dev.0");
|
|
186
|
-
}
|
|
187
|
-
if (options.preId === 'rc') {
|
|
188
|
-
// If version is already an rc version, increment the preId
|
|
189
|
-
// Example: 1.0.0-rc.5 -> 1.0.0-rc.6
|
|
190
|
-
if (RC_VERSION_REGEX.test(currentVersion)) {
|
|
191
|
-
var _b = currentVersion.split('-rc.'), mainVersion = _b[0], currentPreId = _b[1];
|
|
192
|
-
return "".concat(mainVersion, "-rc.").concat(Number(currentPreId) + 1);
|
|
193
|
-
}
|
|
194
|
-
// For release branches, bump the minor version and add the rc preId
|
|
195
|
-
// Example: 1.0.0 -> 1.1.0-rc.0
|
|
196
|
-
if (this.isReleaseBranch)
|
|
197
|
-
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'minor'), "-rc.0");
|
|
198
|
-
// For hotfix branches, bump the patch version and add the rc preId
|
|
199
|
-
// Example: 1.0.0 -> 1.0.1-rc.0
|
|
200
|
-
if (this.isHotfixBranch)
|
|
201
|
-
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'patch'), "-rc.0");
|
|
202
|
-
}
|
|
203
|
-
// Should never run
|
|
204
|
-
return currentVersion;
|
|
205
|
-
};
|
|
206
|
-
BumpPackagesTask.prototype.getNextReleaseVersion = function (currentVersion) {
|
|
207
|
-
// Example: 1.0.1-dev.0 -> 1.0.1
|
|
208
|
-
if (DEV_VERSION_REGEX.test(currentVersion)) {
|
|
209
|
-
return currentVersion.split('-')[0];
|
|
210
|
-
}
|
|
211
|
-
// Example: 1.0.1-rc.5 -> 1.0.1
|
|
212
|
-
if (RC_VERSION_REGEX.test(currentVersion)) {
|
|
213
|
-
return currentVersion.split('-')[0];
|
|
214
|
-
}
|
|
215
|
-
// Example: 1.0.0 -> 1.1.0
|
|
216
|
-
if (this.isReleaseBranch)
|
|
217
|
-
return utils_1.Versions.getNextVersion(currentVersion, 'minor');
|
|
218
|
-
// Example: 1.0.0 -> 1.0.1
|
|
219
|
-
if (this.isHotfixBranch)
|
|
220
|
-
return utils_1.Versions.getNextVersion(currentVersion, 'patch');
|
|
221
|
-
return currentVersion;
|
|
222
|
-
};
|
|
223
|
-
BumpPackagesTask = __decorate([
|
|
224
|
-
(0, inversify_1.injectable)(),
|
|
225
|
-
__param(0, (0, inversify_1.inject)(types_1.SERVICES.GitLabService)),
|
|
226
|
-
__metadata("design:paramtypes", [services_1.GitLabService])
|
|
227
|
-
], BumpPackagesTask);
|
|
228
|
-
return BumpPackagesTask;
|
|
229
|
-
}());
|
|
230
|
-
exports.BumpPackagesTask = BumpPackagesTask;
|
|
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.BumpPackagesTask = 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 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 BumpPackagesTask = /** @class */ (function () {
|
|
64
|
+
function BumpPackagesTask(service) {
|
|
65
|
+
this.isReleaseBranch = false;
|
|
66
|
+
this.isHotfixBranch = false;
|
|
67
|
+
this.service = service;
|
|
68
|
+
}
|
|
69
|
+
BumpPackagesTask.prototype.run = function (options) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var branch, isValid, commitFiles, _i, commitFiles_1, file, newJsonFile;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
utils_1.Logger.logTask('Bumping clickview npm package versions');
|
|
76
|
+
this.isReleaseBranch = RELEASE_BRANCH_REGEX.test(options.branchName);
|
|
77
|
+
this.isHotfixBranch = HOTFIX_BRANCH_REGEX.test(options.branchName);
|
|
78
|
+
return [4 /*yield*/, this.service.getBranch(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
|
|
79
|
+
case 1:
|
|
80
|
+
branch = _a.sent();
|
|
81
|
+
if (!branch) {
|
|
82
|
+
utils_1.Logger.logError("Branch with name ".concat(options.branchName, " was not be found."));
|
|
83
|
+
return [2 /*return*/, false];
|
|
84
|
+
}
|
|
85
|
+
isValid = this.validateOptions(options);
|
|
86
|
+
if (!isValid)
|
|
87
|
+
return [2 /*return*/, false];
|
|
88
|
+
utils_1.Logger.logInfo('Options are valid! Proceeding to bump package versions.');
|
|
89
|
+
commitFiles = this.getCommitFiles(options);
|
|
90
|
+
utils_1.Logger.logInfo('Writing new versions to package.json files...');
|
|
91
|
+
for (_i = 0, commitFiles_1 = commitFiles; _i < commitFiles_1.length; _i++) {
|
|
92
|
+
file = commitFiles_1[_i];
|
|
93
|
+
(0, fs_1.writeFileSync)(file.filePath, file.content);
|
|
94
|
+
newJsonFile = JSON.parse(file.content);
|
|
95
|
+
utils_1.Logger.logInfo("Updated version for ".concat(newJsonFile.name, " to ").concat(newJsonFile.version));
|
|
96
|
+
}
|
|
97
|
+
utils_1.Logger.logInfo('Committing new versions...');
|
|
98
|
+
return [4 /*yield*/, this.service.commit(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName, 'Bump package versions', commitFiles)];
|
|
99
|
+
case 2:
|
|
100
|
+
_a.sent();
|
|
101
|
+
utils_1.Logger.logSuccess('Successfully committed updated version numbers.');
|
|
102
|
+
return [2 /*return*/, true];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
BumpPackagesTask.prototype.validateOptions = function (options) {
|
|
108
|
+
var isValidReleaseBranch = this.isReleaseBranch || this.isHotfixBranch;
|
|
109
|
+
if (options.preId && options.preId !== 'rc' && options.preId !== 'dev') {
|
|
110
|
+
utils_1.Logger.logError("Argument for \"preId\" can only be \"rc\" or \"dev\". You entered: ".concat(options.preId));
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (options.preId === 'dev' && isValidReleaseBranch) {
|
|
114
|
+
utils_1.Logger.logError('Dev versions cannot be generated on release or hotfix branches.');
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (options.preId === 'rc' && !isValidReleaseBranch) {
|
|
118
|
+
utils_1.Logger.logError('Release Candidate versions can only be generated on release or hotfix branches.');
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (!options.preId && !isValidReleaseBranch) {
|
|
122
|
+
utils_1.Logger.logError('Production package versions can only be generated on release or hotfix branches.');
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
};
|
|
127
|
+
BumpPackagesTask.prototype.getFileText = function (projectId, branchName, fileName) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
+
var file, buff;
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0: return [4 /*yield*/, this.service.getFile(projectId, branchName, fileName)];
|
|
133
|
+
case 1:
|
|
134
|
+
file = _a.sent();
|
|
135
|
+
if (!file)
|
|
136
|
+
return [2 /*return*/, ''];
|
|
137
|
+
buff = Buffer.from(file.content, 'base64');
|
|
138
|
+
return [2 /*return*/, buff.toString('utf-8')];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
BumpPackagesTask.prototype.getCommitFiles = function (options) {
|
|
144
|
+
var commitFiles = [];
|
|
145
|
+
for (var _i = 0, _a = Object.entries(MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES_MAP); _i < _a.length; _i++) {
|
|
146
|
+
var _b = _a[_i], projectId = _b[0], packageJsonFilePath = _b[1];
|
|
147
|
+
// Only bump versions for projects with an output directory
|
|
148
|
+
if (!(0, fs_1.existsSync)(MonorepoPackageJsonFiles_1.MONOREPO_DISTS_MAP[projectId]) || !(0, fs_1.statSync)(MonorepoPackageJsonFiles_1.MONOREPO_DISTS_MAP[projectId]).isDirectory())
|
|
149
|
+
continue;
|
|
150
|
+
var content = '';
|
|
151
|
+
try {
|
|
152
|
+
content = (0, fs_1.readFileSync)(packageJsonFilePath, { encoding: 'utf8' });
|
|
153
|
+
}
|
|
154
|
+
catch (_c) {
|
|
155
|
+
/**
|
|
156
|
+
* If the file doesn't exist, ignore the error.
|
|
157
|
+
* This will occur when TC Docker runs this script as it doesn't copy over @clickview/tooling
|
|
158
|
+
*/
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
var json = JSON.parse(content);
|
|
162
|
+
json.version = this.getNextVersion(json.version, options);
|
|
163
|
+
commitFiles.push({
|
|
164
|
+
filePath: packageJsonFilePath,
|
|
165
|
+
content: JSON.stringify(json, null, 2)
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return commitFiles;
|
|
169
|
+
};
|
|
170
|
+
BumpPackagesTask.prototype.getNextVersion = function (currentVersion, options) {
|
|
171
|
+
if (options.preId)
|
|
172
|
+
return this.getNextPrereleaseVersion(currentVersion, options);
|
|
173
|
+
return this.getNextReleaseVersion(currentVersion);
|
|
174
|
+
};
|
|
175
|
+
BumpPackagesTask.prototype.getNextPrereleaseVersion = function (currentVersion, options) {
|
|
176
|
+
if (options.preId === 'dev') {
|
|
177
|
+
// If version is already a dev version, increment the preId
|
|
178
|
+
// Example: 1.0.0-dev.5 -> 1.0.0-dev.6
|
|
179
|
+
if (DEV_VERSION_REGEX.test(currentVersion)) {
|
|
180
|
+
var _a = currentVersion.split('-dev.'), mainVersion = _a[0], currentPreId = _a[1];
|
|
181
|
+
return "".concat(mainVersion, "-dev.").concat(Number(currentPreId) + 1);
|
|
182
|
+
}
|
|
183
|
+
// Bump the patch version and add the dev preId
|
|
184
|
+
// Example: 1.0.0 -> 1.0.1-dev.0
|
|
185
|
+
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'patch'), "-dev.0");
|
|
186
|
+
}
|
|
187
|
+
if (options.preId === 'rc') {
|
|
188
|
+
// If version is already an rc version, increment the preId
|
|
189
|
+
// Example: 1.0.0-rc.5 -> 1.0.0-rc.6
|
|
190
|
+
if (RC_VERSION_REGEX.test(currentVersion)) {
|
|
191
|
+
var _b = currentVersion.split('-rc.'), mainVersion = _b[0], currentPreId = _b[1];
|
|
192
|
+
return "".concat(mainVersion, "-rc.").concat(Number(currentPreId) + 1);
|
|
193
|
+
}
|
|
194
|
+
// For release branches, bump the minor version and add the rc preId
|
|
195
|
+
// Example: 1.0.0 -> 1.1.0-rc.0
|
|
196
|
+
if (this.isReleaseBranch)
|
|
197
|
+
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'minor'), "-rc.0");
|
|
198
|
+
// For hotfix branches, bump the patch version and add the rc preId
|
|
199
|
+
// Example: 1.0.0 -> 1.0.1-rc.0
|
|
200
|
+
if (this.isHotfixBranch)
|
|
201
|
+
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'patch'), "-rc.0");
|
|
202
|
+
}
|
|
203
|
+
// Should never run
|
|
204
|
+
return currentVersion;
|
|
205
|
+
};
|
|
206
|
+
BumpPackagesTask.prototype.getNextReleaseVersion = function (currentVersion) {
|
|
207
|
+
// Example: 1.0.1-dev.0 -> 1.0.1
|
|
208
|
+
if (DEV_VERSION_REGEX.test(currentVersion)) {
|
|
209
|
+
return currentVersion.split('-')[0];
|
|
210
|
+
}
|
|
211
|
+
// Example: 1.0.1-rc.5 -> 1.0.1
|
|
212
|
+
if (RC_VERSION_REGEX.test(currentVersion)) {
|
|
213
|
+
return currentVersion.split('-')[0];
|
|
214
|
+
}
|
|
215
|
+
// Example: 1.0.0 -> 1.1.0
|
|
216
|
+
if (this.isReleaseBranch)
|
|
217
|
+
return utils_1.Versions.getNextVersion(currentVersion, 'minor');
|
|
218
|
+
// Example: 1.0.0 -> 1.0.1
|
|
219
|
+
if (this.isHotfixBranch)
|
|
220
|
+
return utils_1.Versions.getNextVersion(currentVersion, 'patch');
|
|
221
|
+
return currentVersion;
|
|
222
|
+
};
|
|
223
|
+
BumpPackagesTask = __decorate([
|
|
224
|
+
(0, inversify_1.injectable)(),
|
|
225
|
+
__param(0, (0, inversify_1.inject)(types_1.SERVICES.GitLabService)),
|
|
226
|
+
__metadata("design:paramtypes", [services_1.GitLabService])
|
|
227
|
+
], BumpPackagesTask);
|
|
228
|
+
return BumpPackagesTask;
|
|
229
|
+
}());
|
|
230
|
+
exports.BumpPackagesTask = BumpPackagesTask;
|