1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.bump = exports.cmd = exports.args = exports.description = exports.alias = exports.name = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var common_1 = require("../common");
|
6 | var listCommand = require("./ls.cmd");
|
7 | exports.name = 'bump';
|
8 | exports.alias = 'b';
|
9 | exports.description = "Bumps a module version along with it's entire dependency graph.";
|
10 | exports.args = {
|
11 | '-i': 'Include ignored modules.',
|
12 | '-d': 'Dry run where no files are saved.',
|
13 | '-l': 'Local versions only. Does not retrieve NPM details.',
|
14 | };
|
15 | function cmd(args) {
|
16 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
17 | var options;
|
18 | return tslib_1.__generator(this, function (_a) {
|
19 | switch (_a.label) {
|
20 | case 0:
|
21 | options = (args && args.options) || {};
|
22 | return [4, bump({
|
23 | includeIgnored: options.i || false,
|
24 | local: options.l || false,
|
25 | dryRun: options.d || false,
|
26 | })];
|
27 | case 1:
|
28 | _a.sent();
|
29 | return [2];
|
30 | }
|
31 | });
|
32 | });
|
33 | }
|
34 | exports.cmd = cmd;
|
35 | function bump(options) {
|
36 | if (options === void 0) { options = {}; }
|
37 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
38 | var _a, includeIgnored, _b, local, _c, dryRun, save, npm, settings, modules, module, dependants, release, bumped;
|
39 | return tslib_1.__generator(this, function (_d) {
|
40 | switch (_d.label) {
|
41 | case 0:
|
42 | _a = options.includeIgnored, includeIgnored = _a === void 0 ? false : _a, _b = options.local, local = _b === void 0 ? false : _b, _c = options.dryRun, dryRun = _c === void 0 ? false : _c;
|
43 | save = !dryRun;
|
44 | npm = !local;
|
45 | return [4, common_1.loadSettings({ npm: npm, spinner: npm })];
|
46 | case 1:
|
47 | settings = _d.sent();
|
48 | if (!settings) {
|
49 | common_1.log.warn.yellow(common_1.constants.CONFIG_NOT_FOUND_ERROR);
|
50 | return [2];
|
51 | }
|
52 | modules = settings.modules.filter(function (pkg) { return common_1.filter.includeIgnored(pkg, includeIgnored); });
|
53 | return [4, promptForModule(modules)];
|
54 | case 2:
|
55 | module = _d.sent();
|
56 | if (!module) {
|
57 | return [2];
|
58 | }
|
59 | common_1.log.info();
|
60 | dependants = common_1.dependsOn(module, modules);
|
61 | listCommand.printTable([module], { includeIgnored: true, dependants: dependants });
|
62 | if (dryRun) {
|
63 | common_1.log.info.gray("Dry run...no files will be saved.\n");
|
64 | }
|
65 | common_1.log.info();
|
66 | return [4, promptForReleaseType(module.version)];
|
67 | case 3:
|
68 | release = (_d.sent());
|
69 | if (!release) {
|
70 | return [2];
|
71 | }
|
72 | common_1.log.info();
|
73 | return [4, bumpModule({
|
74 | release: release,
|
75 | pkg: module,
|
76 | allModules: modules,
|
77 | save: save,
|
78 | })];
|
79 | case 4:
|
80 | bumped = _d.sent();
|
81 | common_1.log.info();
|
82 | common_1.log.info(bumped.log());
|
83 | common_1.log.info();
|
84 | if (dryRun) {
|
85 | common_1.log.info.gray("\nNo files were saved.");
|
86 | }
|
87 | else {
|
88 | common_1.log.info();
|
89 | }
|
90 | return [2];
|
91 | }
|
92 | });
|
93 | });
|
94 | }
|
95 | exports.bump = bump;
|
96 | function bumpModule(options) {
|
97 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
98 | var release, pkg, allModules, save, _a, level, ref, dependants, version, isRoot, head, table, logPkgUpdate, json, _i, dependants_1, dependentPkg;
|
99 | return tslib_1.__generator(this, function (_b) {
|
100 | switch (_b.label) {
|
101 | case 0:
|
102 | release = options.release, pkg = options.pkg, allModules = options.allModules, save = options.save, _a = options.level, level = _a === void 0 ? 0 : _a, ref = options.ref;
|
103 | dependants = common_1.dependsOn(pkg, allModules);
|
104 | version = common_1.semver.inc(pkg.latest, release);
|
105 | isRoot = ref === undefined;
|
106 | if (!version) {
|
107 | throw new Error("Failed to '" + release + "' the semver " + pkg.latest + ".");
|
108 | }
|
109 | head = ['update', 'module', 'version', 'dependants'].map(function (title) { return common_1.log.gray(title); });
|
110 | table = options.table || common_1.log.table({ head: head, border: false });
|
111 | logPkgUpdate = function (args) {
|
112 | var release = args.release, pkg = args.pkg, version = args.version;
|
113 | var msg = '';
|
114 | msg += " " + common_1.log.yellow(release.toUpperCase()) + " ";
|
115 | msg += common_1.formatModuleName(pkg.name) + " from " + pkg.latest + " \u2192 " + common_1.log.yellow(version) + " ";
|
116 | return common_1.log.gray(msg);
|
117 | };
|
118 | if (ref) {
|
119 | table.add([
|
120 | common_1.log.yellow(" " + release.toUpperCase() + " "),
|
121 | common_1.formatModuleName(pkg.name + " "),
|
122 | common_1.log.gray(pkg.latest + " \u2192 " + common_1.log.magenta(version) + " "),
|
123 | common_1.log.gray(common_1.formatModuleName(ref.name) + " " + ref.fromVersion + " \u2192 " + common_1.log.magenta(ref.toVersion)),
|
124 | ]);
|
125 | }
|
126 | json = common_1.R.clone(pkg.json);
|
127 | json.version = version;
|
128 | if (!save) return [3, 2];
|
129 | return [4, common_1.savePackage(pkg.dir, json)];
|
130 | case 1:
|
131 | _b.sent();
|
132 | _b.label = 2;
|
133 | case 2:
|
134 | if (isRoot && dependants.length > 0) {
|
135 | common_1.log.info.gray('\nchanges:');
|
136 | }
|
137 | _i = 0, dependants_1 = dependants;
|
138 | _b.label = 3;
|
139 | case 3:
|
140 | if (!(_i < dependants_1.length)) return [3, 7];
|
141 | dependentPkg = dependants_1[_i];
|
142 | return [4, common_1.updatePackageRef(dependentPkg, pkg.name, version, { save: save })];
|
143 | case 4:
|
144 | _b.sent();
|
145 | return [4, bumpModule({
|
146 | release: 'patch',
|
147 | pkg: dependentPkg,
|
148 | allModules: allModules,
|
149 | level: level + 1,
|
150 | ref: { name: pkg.name, fromVersion: pkg.latest, toVersion: version },
|
151 | save: save,
|
152 | table: table,
|
153 | })];
|
154 | case 5:
|
155 | _b.sent();
|
156 | _b.label = 6;
|
157 | case 6:
|
158 | _i++;
|
159 | return [3, 3];
|
160 | case 7: return [2, {
|
161 | table: table,
|
162 | log: function () {
|
163 | return ("\n" + common_1.log.info(logPkgUpdate({ release: release, pkg: pkg, version: version })) + "\n\n" + table.toString() + "\n\n" + common_1.log.gray('complete') + "\n" + common_1.log.info(logPkgUpdate({ release: release, pkg: pkg, version: version })) + "\n").substring(1);
|
164 | },
|
165 | }];
|
166 | }
|
167 | });
|
168 | });
|
169 | }
|
170 | function promptForModule(modules) {
|
171 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
172 | var choices, res, name;
|
173 | return tslib_1.__generator(this, function (_a) {
|
174 | switch (_a.label) {
|
175 | case 0:
|
176 | choices = modules.map(function (pkg) { return ({ name: pkg.name, value: pkg.name }); });
|
177 | return [4, common_1.inquirer.prompt({
|
178 | type: 'list',
|
179 | name: 'name',
|
180 | message: 'Select a module',
|
181 | choices: choices,
|
182 | pageSize: 30,
|
183 | })];
|
184 | case 1:
|
185 | res = (_a.sent());
|
186 | name = res.name;
|
187 | return [2, modules.find(function (pkg) { return pkg.name === name; })];
|
188 | }
|
189 | });
|
190 | });
|
191 | }
|
192 | function promptForReleaseType(version) {
|
193 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
194 | var choices, res;
|
195 | return tslib_1.__generator(this, function (_a) {
|
196 | switch (_a.label) {
|
197 | case 0:
|
198 | choices = ['patch', 'minor', 'major'];
|
199 | return [4, common_1.inquirer.prompt({
|
200 | type: 'list',
|
201 | name: 'name',
|
202 | message: 'Release',
|
203 | choices: choices,
|
204 | })];
|
205 | case 1:
|
206 | res = (_a.sent());
|
207 | return [2, res.name];
|
208 | }
|
209 | });
|
210 | });
|
211 | }
|