forked from sindresorhus/np
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.js
40 lines (30 loc) · 943 Bytes
/
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
'use strict';
const execa = require('execa');
const {from} = require('rxjs');
const {catchError} = require('rxjs/operators');
const handleNpmError = require('./handle-npm-error');
const getPackagePublishArguments = options => {
const args = ['publish'];
if (options.contents) {
args.push(options.contents);
}
if (options.tag) {
args.push('--tag', options.tag);
}
if (options.otp) {
args.push('--otp', options.otp);
}
if (options.publishScoped) {
args.push('--access', 'public');
}
return args;
};
const pkgPublish = (pkgManager, options) => execa(pkgManager, getPackagePublishArguments(options));
module.exports = (context, pkgManager, task, options) =>
from(pkgPublish(pkgManager, options)).pipe(
catchError(error => handleNpmError(error, task, otp => {
context.otp = otp;
return pkgPublish(pkgManager, {...options, otp});
}))
);
module.exports.getPackagePublishArguments = getPackagePublishArguments;