Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Commit 210ddcf

Browse files
committed
fix(bin): Fix exit codes and success output
1 parent 75f751c commit 210ddcf

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/bin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const download = require('./')
77
const error = (err) => {
88
process.stdout.write(`${err}\n`)
99
process.stdout.write(`Download failed!\n\n`)
10-
process.exit(0)
10+
process.exit(1)
1111
}
1212

13-
const success = (fileName, installPath) => {
14-
process.stdout.write(`Downloaded ${fileName}\n`)
15-
process.stdout.write(`Installed go-${fileName.replace('.tar.gz', '').replace('.zip', '').replace(/_/g, ' ')} to ${installPath}\n`)
16-
process.exit(1)
13+
const success = (output) => {
14+
process.stdout.write(`Downloaded ${output.fileName}\n`)
15+
process.stdout.write(`Installed go-${output.fileName.replace('.tar.gz', '').replace('.zip', '').replace(/_/g, ' ')} to ${output.installPath}\n`)
16+
process.exit(0)
1717
}
1818

1919
// First param is the target version

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ function download (version, platform, arch, installPath) {
6666

6767
// Success callback wrapper
6868
// go-ipfs contents are in 'go-ipfs/', so append that to the path
69-
const done = () => resolve({ file: fileName, dir: path.join(installPath, '/go-ipfs/') })
69+
const done = () => resolve({
70+
fileName: fileName,
71+
installPath: path.join(installPath, '/go-ipfs/')
72+
})
7073

7174
// Unpack the response stream
7275
const unpack = (stream) => {

test/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ test('Ensure ipfs gets downloaded (current version and platform)', (t) => {
4444
rimraf.sync(dir)
4545
download((err, res) => {
4646
t.ifErr(err)
47-
t.ok(res.file.indexOf(`ipfs_${version}_${goenv.GOOS}-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
48-
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
47+
t.ok(res.fileName.indexOf(`ipfs_${version}_${goenv.GOOS}-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
48+
t.ok(res.installPath === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
4949

5050
fs.stat(dir, (err, stats) => {
5151
t.error(err, 'go-ipfs should stat without error')
@@ -60,8 +60,8 @@ test('Ensure Windows version gets downloaded', (t) => {
6060
rimraf.sync(dir)
6161
download(version, 'windows', (err, res) => {
6262
t.ifErr(err)
63-
t.ok(res.file.indexOf(`ipfs_${version}_windows-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
64-
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
63+
t.ok(res.fileName.indexOf(`ipfs_${version}_windows-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
64+
t.ok(res.installPath === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
6565

6666
fs.stat(dir, (err, stats) => {
6767
t.error(err, 'go-ipfs for windows should stat without error')
@@ -81,8 +81,8 @@ test('Ensure Linux version gets downloaded', (t) => {
8181
rimraf.sync(dir)
8282
download(version, 'linux', (err, res) => {
8383
t.ifErr(err)
84-
t.ok(res.file.indexOf(`ipfs_${version}_linux-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
85-
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
84+
t.ok(res.fileName.indexOf(`ipfs_${version}_linux-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
85+
t.ok(res.installPath === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
8686

8787
fs.stat(dir, (err, stats) => {
8888
t.error(err, 'go-ipfs for linux should stat without error')
@@ -102,8 +102,8 @@ test('Ensure OSX version gets downloaded', (t) => {
102102
rimraf.sync(dir)
103103
download(version, 'darwin', (err, res) => {
104104
t.ifErr(err)
105-
t.ok(res.file.indexOf(`ipfs_${version}_darwin-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
106-
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
105+
t.ok(res.fileName.indexOf(`ipfs_${version}_darwin-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
106+
t.ok(res.installPath === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
107107

108108
fs.stat(dir, (err, stats) => {
109109
t.error(err, 'go-ipfs for OSX should stat without error')
@@ -126,8 +126,8 @@ test('Ensure TARGET_OS, TARGET_VERSION and TARGET_ARCH version gets downloaded',
126126
process.env.TARGET_ARCH = '386'
127127
download((err, res) => {
128128
t.ifErr(err)
129-
t.ok(res.file.indexOf(`ipfs_${process.env.TARGET_VERSION}_${process.env.TARGET_OS}-${process.env.TARGET_ARCH}`) !== -1, 'Returns the correct filename')
130-
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
129+
t.ok(res.fileName.indexOf(`ipfs_${process.env.TARGET_VERSION}_${process.env.TARGET_OS}-${process.env.TARGET_ARCH}`) !== -1, 'Returns the correct filename')
130+
t.ok(res.installPath === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
131131

132132
fs.stat(dir, (err, stats) => {
133133
t.error(err, 'go-ipfs for windows should stat without error')

0 commit comments

Comments
 (0)