UNPKG

4.04 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('b') === -1 &&
35 prev.indexOf('rc') === -1 &&
36 spec === 'release') {
37 throw new Error('Use "major" or "minor" to switch back to alpha release');
38 }
39 if (prev.indexOf('a') === -1 &&
40 prev.indexOf('b') === -1 &&
41 prev.indexOf('rc') === -1 &&
42 spec === 'build') {
43 throw new Error('Cannot increment a build on a final release');
44 }
45 // Run pre-bump script.
46 utils.prebump();
47 // Handle dry runs.
48 if (opts.dryRun) {
49 utils.run(`bumpversion --dry-run --verbose ${spec}`);
50 return;
51 }
52 // If this is a major release during the alpha cycle, bump
53 // just the Python version.
54 if (prev.indexOf('a') !== -1 && spec === 'major') {
55 // Bump the version.
56 utils.run(`bumpversion ${spec}`);
57 // Run the post-bump script.
58 utils.postbump();
59 return;
60 }
61 // Determine the version spec to use for lerna.
62 let lernaVersion = 'preminor';
63 if (spec === 'build') {
64 lernaVersion = 'prerelease';
65 // a -> b
66 }
67 else if (spec === 'release' && prev.indexOf('a') !== -1) {
68 lernaVersion = 'prerelease --preid=beta';
69 // b -> rc
70 }
71 else if (spec === 'release' && prev.indexOf('b') !== -1) {
72 lernaVersion = 'prerelease --preid=rc';
73 // rc -> final
74 }
75 else if (spec === 'release' && prev.indexOf('rc') !== -1) {
76 lernaVersion = 'patch';
77 }
78 if (lernaVersion === 'preminor') {
79 lernaVersion += ' --preid=alpha';
80 }
81 let cmd = `lerna version -m \"New version\" --force-publish=* --no-push ${lernaVersion}`;
82 if (opts.force) {
83 cmd += ' --yes';
84 }
85 const oldVersion = utils.run('git rev-parse HEAD', {
86 stdio: 'pipe',
87 encoding: 'utf8'
88 }, true);
89 // For a preminor release, we bump 10 minor versions so that we do
90 // not conflict with versions during minor releases of the top
91 // level package.
92 if (lernaVersion === 'preminor') {
93 for (let i = 0; i < 10; i++) {
94 utils.run(cmd);
95 }
96 }
97 else {
98 utils.run(cmd);
99 }
100 const newVersion = utils.run('git rev-parse HEAD', {
101 stdio: 'pipe',
102 encoding: 'utf8'
103 }, true);
104 if (oldVersion === newVersion) {
105 // lerna didn't version anything, so we assume the user aborted
106 throw new Error('Lerna aborted');
107 }
108 // Bump the version.
109 utils.run(`bumpversion ${spec}`);
110 // Run the post-bump script.
111 utils.postbump();
112});
113commander_1.default.parse(process.argv);
114//# sourceMappingURL=bumpversion.js.map
\No newline at end of file