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

Fix exit codes and success output #19

Merged
merged 1 commit into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const download = require('./')
const error = (err) => {
process.stdout.write(`${err}\n`)
process.stdout.write(`Download failed!\n\n`)
process.exit(0)
process.exit(1)
}

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

// First param is the target version
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ function download (version, platform, arch, installPath) {

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

// Unpack the response stream
const unpack = (stream) => {
Expand Down
20 changes: 10 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ test('Ensure ipfs gets downloaded (current version and platform)', (t) => {
rimraf.sync(dir)
download((err, res) => {
t.ifErr(err)
t.ok(res.file.indexOf(`ipfs_${version}_${goenv.GOOS}-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
t.ok(res.fileName.indexOf(`ipfs_${version}_${goenv.GOOS}-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
t.ok(res.installPath === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')

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

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

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

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

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