/
publish.js
54 lines (47 loc) · 1.31 KB
/
publish.js
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
// @flow
import * as options from '../utils/options';
import * as logger from '../utils/logger';
import * as messages from '../utils/messages';
import {
publish as publishUtil,
type PublishOptions,
type PackageMeta
} from '../utils/publish';
import { BoltError } from '../utils/errors';
export function toPublishOptions(
args: options.Args,
flags: options.Flags
): PublishOptions {
return {
cwd: options.string(flags.cwd, 'cwd'),
access: options.string(flags.access, 'access')
};
}
function partition(collection, predicate = x => x): PackageMeta[][] {
return collection.reduce(
([a, b], value) => {
(predicate(value) ? a : b).push(value);
return [a, b];
},
[[], []]
);
}
export async function publish(opts: PublishOptions) {
const response: PackageMeta[] = await publishUtil(opts);
const [successful, unsuccessful] = partition(response, p => p.published);
for (const pkg of successful) {
logger.success(
messages.successfullyPublishedPackage(pkg.name, pkg.newVersion)
);
}
for (const pkg of unsuccessful) {
logger.error(messages.failedToPublishPackage(pkg.name));
}
if (unsuccessful.length > 0) {
throw new BoltError(
`Failed to publish ${unsuccessful.length} ${
unsuccessful.length === 1 ? 'package' : 'packages'
}`
);
}
}