forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.ts
85 lines (74 loc) · 2.81 KB
/
publish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
import commander from 'commander';
import * as crypto from 'crypto';
import * as fs from 'fs-extra';
import * as path from 'path';
import { handlePackage } from './update-dist-tag';
import * as utils from './utils';
// Specify the program signature.
commander
.description('Publish the JS packages and prep the Python package')
.option(
'--skip-build',
'Skip the clean and build step (if there was a network error during a JS publish'
)
.action(async (options: any) => {
// Make sure we are logged in.
if (utils.checkStatus('npm whoami') !== 0) {
console.error('Please run `npm login`');
}
// Optionally clean and build the python packages.
if (!options.skipBuild) {
// Ensure a clean state.
utils.run('npm run clean:slate');
}
// Publish JS to the appropriate tag.
const curr = utils.getPythonVersion();
if (curr.indexOf('rc') === -1 && curr.indexOf('a') === -1) {
utils.run('lerna publish from-package -m "Publish"');
} else {
utils.run('lerna publish from-package --npm-tag=next -m "Publish"');
}
// Fix up any tagging issues.
const basePath = path.resolve('.');
const paths = utils.getLernaPaths(basePath).sort();
const cmds = await Promise.all(paths.map(handlePackage));
cmds.forEach(cmdList => {
cmdList.forEach(cmd => {
utils.run(cmd);
});
});
// Update core mode. This cannot be done until the JS packages are
// released.
utils.run('node buildutils/lib/update-core-mode.js');
// Make the Python release.
utils.run('python setup.py sdist');
utils.run('python setup.py bdist_wheel');
utils.run('python -m pip install -U twine');
utils.run('twine check dist/*');
const files = fs.readdirSync('./dist/');
const hashes = new Map<string, string>();
files.forEach(file => {
const shasum = crypto.createHash('sha256');
const hash = shasum.update(fs.readFileSync('./dist/' + file));
hashes.set(file, hash.digest('hex'));
});
const hashString = Array.from(hashes.entries())
.map(entry => `${entry[0]}: ${entry[1]}`)
.join('" -m "');
// Prompt the user to finalize.
console.log('*'.repeat(40));
console.log('*'.repeat(40));
console.log('Ready to publish!');
console.log('Run these command when ready:');
console.log(
`git commit -am "Publish ${curr}" -m "SHA256 hashes:" -m "${hashString}"`
);
console.log(`git tag v${curr}`);
console.log('twine upload dist/*');
console.log('git push origin <BRANCH> --tags');
});
commander.parse(process.argv);