Skip to content

Commit d93c560

Browse files
committed
build(scripts/publish): handle errors and prompt for otp last
1 parent fb5df1f commit d93c560

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

scripts/publish.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,41 @@ const inquirer = require('inquirer')
22
const execa = require('execa')
33

44
;(async () => {
5-
const { NPM_OTP, CONVENTIONAL_GITHUB_RELEASER_TOKEN } = await inquirer.prompt([
6-
{
7-
type: 'password',
8-
name: 'NPM_OTP',
9-
message: 'npm OTP code',
10-
filter (input) {
11-
return input.trim()
5+
let code = 0
6+
try {
7+
const { NPM_OTP, CONVENTIONAL_GITHUB_RELEASER_TOKEN } = await inquirer.prompt([
8+
{
9+
type: 'password',
10+
name: 'CONVENTIONAL_GITHUB_RELEASER_TOKEN',
11+
message: 'GitHub Token (for GitHub Releases)',
12+
filter (input) {
13+
return input.trim()
14+
},
15+
validate (input, answers) {
16+
return input && input.length > 0 ? true : 'Cannot be emtpy'
17+
}
1218
},
13-
validate (input, answers) {
14-
return input && input.length > 0 ? true : 'Cannot be emtpy'
19+
{
20+
type: 'password',
21+
name: 'NPM_OTP',
22+
message: 'npm OTP code',
23+
filter (input) {
24+
return input.trim()
25+
},
26+
validate (input, answers) {
27+
return input && input.length > 0 ? true : 'Cannot be emtpy'
28+
}
1529
}
16-
},
17-
{
18-
type: 'password',
19-
name: 'CONVENTIONAL_GITHUB_RELEASER_TOKEN',
20-
message: 'GitHub Token (for GitHub Releases)',
21-
filter (input) {
22-
return input.trim()
23-
},
24-
validate (input, answers) {
25-
return input && input.length > 0 ? true : 'Cannot be emtpy'
26-
}
27-
}
28-
])
29-
await execa('npm', ['publish', '--otp', NPM_OTP])
30-
await execa('conventional-github-releaser', [
31-
'-p', 'angular', '-t', CONVENTIONAL_GITHUB_RELEASER_TOKEN
32-
])
30+
])
31+
32+
await execa('npm', ['publish', '--otp', NPM_OTP])
33+
await execa('conventional-github-releaser', [
34+
'-p', 'angular', '-t', CONVENTIONAL_GITHUB_RELEASER_TOKEN
35+
])
36+
} catch (error) {
37+
code = 1
38+
console.error(error)
39+
} finally {
40+
process.exit(code)
41+
}
3342
})()

0 commit comments

Comments
 (0)