UNPKG

3.44 kBJavaScriptView Raw
1"use strict";
2/*-----------------------------------------------------------------------------
3| Copyright (c) Jupyter Development Team.
4| Distributed under the terms of the Modified BSD License.
5|----------------------------------------------------------------------------*/
6var __importDefault = (this && this.__importDefault) || function (mod) {
7 return (mod && mod.__esModule) ? mod : { "default": mod };
8};
9var __importStar = (this && this.__importStar) || function (mod) {
10 if (mod && mod.__esModule) return mod;
11 var result = {};
12 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
13 result["default"] = mod;
14 return result;
15};
16Object.defineProperty(exports, "__esModule", { value: true });
17const commander_1 = __importDefault(require("commander"));
18const utils = __importStar(require("./utils"));
19// Specify the program signature.
20commander_1.default
21 .description('Update the version and publish')
22 .option('--dry-run', 'Dry run')
23 .option('--force', 'Force the upgrade')
24 .arguments('<spec>')
25 .action((spec, opts) => {
26 // Get the previous version.
27 const prev = utils.getPythonVersion();
28 // Make sure we have a valid version spec.
29 const options = ['major', 'minor', 'release', 'build'];
30 if (options.indexOf(spec) === -1) {
31 throw new Error(`Version spec must be one of: ${options}`);
32 }
33 if (prev.indexOf('a') === -1 &&
34 prev.indexOf('rc') === -1 &&
35 spec === 'release') {
36 throw new Error('Use "major" or "minor" to switch back to alpha release');
37 }
38 if (prev.indexOf('a') === -1 &&
39 prev.indexOf('rc') === -1 &&
40 spec === 'build') {
41 throw new Error('Cannot increment a build on a final release');
42 }
43 // Run pre-bump script.
44 utils.prebump();
45 // Handle dry runs.
46 if (opts.dryRun) {
47 utils.run(`bumpversion --dry-run --verbose ${spec}`);
48 return;
49 }
50 // If this is a major release during the alpha cycle, bump
51 // just the Python version.
52 if (prev.indexOf('a') !== -1 && spec === 'major') {
53 // Bump the version.
54 utils.run(`bumpversion ${spec}`);
55 // Run the post-bump script.
56 utils.postbump();
57 return;
58 }
59 // Determine the version spec to use for lerna.
60 let lernaVersion = 'preminor';
61 if (spec === 'build') {
62 lernaVersion = 'prerelease';
63 // a -> rc
64 }
65 else if (spec === 'release' && prev.indexOf('a') !== -1) {
66 lernaVersion = 'prerelease --preid=rc';
67 // rc -> final
68 }
69 else if (spec === 'release' && prev.indexOf('rc') !== -1) {
70 lernaVersion = 'patch';
71 }
72 let cmd = `lerna version -m \"New version\" --force-publish=* --no-push ${lernaVersion}`;
73 if (opts.force) {
74 cmd += ' --yes';
75 }
76 let oldVersion = utils.run('git rev-parse HEAD', {
77 stdio: 'pipe',
78 encoding: 'utf8'
79 }, true);
80 utils.run(cmd);
81 let newVersion = utils.run('git rev-parse HEAD', {
82 stdio: 'pipe',
83 encoding: 'utf8'
84 }, true);
85 if (oldVersion === newVersion) {
86 // lerna didn't version anything, so we assume the user aborted
87 throw new Error('Lerna aborted');
88 }
89 // Bump the version.
90 utils.run(`bumpversion ${spec}`);
91 // Run the post-bump script.
92 utils.postbump();
93});
94commander_1.default.parse(process.argv);
95//# sourceMappingURL=bumpversion.js.map
\No newline at end of file