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

Commit 9f3a866

Browse files
committed
fix: bunch of linting
1 parent 363233f commit 9f3a866

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
},
1313
"scripts": {
1414
"install": "node src/bin.js",
15-
"test": "tape test/*.js | tap-spec"
15+
"test": "tape test/*.js | tap-spec",
16+
"lint": "standard"
1617
},
18+
"pre-commit": [
19+
"lint",
20+
"test"
21+
],
1722
"repository": {
1823
"type": "git",
1924
"url": "git+https://github.com/ipfs/npm-go-ipfs-dep.git"
@@ -36,7 +41,9 @@
3641
},
3742
"homepage": "https://github.com/ipfs/npm-go-ipfs-dep",
3843
"devDependencies": {
44+
"pre-commit": "^1.1.3",
3945
"rimraf": "^2.5.4",
46+
"standard": "^8.6.0",
4047
"tap-spec": "^4.1.1",
4148
"tape": "^4.6.0"
4249
}

src/check-support.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
// The packages we support
77
const supportedPlatforms = ['linux', 'darwin', 'windows', 'freebsd']
8-
const supportedArchs = ['amd64', '386', 'arm']
9-
const supportedVersions = [
8+
const supportedArchs = ['amd64', '386', 'arm']
9+
const supportedVersions = [
1010
'sharding-pre',
1111
'v0.3.2',
1212
'v0.3.4',
@@ -22,13 +22,13 @@ const supportedVersions = [
2222
'v0.4.2',
2323
'v0.4.3',
2424
'v0.4.4',
25-
'v0.4.5-pre1',
25+
'v0.4.5-pre1'
2626
]
2727

2828
// Check functions
29-
const isSupportedVersion = (version) => supportedVersions.indexOf(version) !== -1
29+
const isSupportedVersion = (version) => supportedVersions.indexOf(version) !== -1
3030
const isSupportedPlatform = (platform) => supportedPlatforms.indexOf(platform) !== -1
31-
const isSupportedArch = (arch) => supportedArchs.indexOf(arch) !== -1
31+
const isSupportedArch = (arch) => supportedArchs.indexOf(arch) !== -1
3232

3333
// Is the platform Windows?
3434
const isWindows = (os) => {
@@ -37,14 +37,15 @@ const isWindows = (os) => {
3737

3838
// Validate the requested binary support, throw en error if not supported
3939
const verify = (version, platform, arch) => {
40-
if (!isSupportedArch(arch))
41-
throw new Error(`No binary available for arch '${arch}'`)
40+
if (!isSupportedArch(arch)) { throw new Error(`No binary available for arch '${arch}'`) }
4241

43-
if (!isSupportedPlatform(platform))
42+
if (!isSupportedPlatform(platform)) {
4443
throw new Error(`No binary available for platform '${platform}'`)
44+
}
4545

46-
if (!isSupportedVersion(version))
46+
if (!isSupportedVersion(version)) {
4747
throw new Error(`Version '${version}' not available`)
48+
}
4849

4950
return true
5051
}
@@ -58,5 +59,5 @@ module.exports = {
5859
isSupportedPlatform: isSupportedPlatform,
5960
isSupportedArch: isSupportedArch,
6061
isWindows: isWindows,
61-
verify: verify,
62+
verify: verify
6263
}

src/index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
2-
/*
2+
/*
33
Download go-ipfs distribution package for desired version, platform and architecture,
44
and unpack it to a desired output directory.
55
@@ -26,27 +26,27 @@ const request = require('request')
2626
const tarFS = require('tar-fs')
2727
const unzip = require('unzip')
2828
const support = require('./check-support')
29-
const pkg = require('./../package.json')
29+
const pkg = require('./../package.json')
3030

3131
// Check package.json for default config
3232
const goIpfsInfo = pkg['go-ipfs']
3333

34-
const goIpfsVersion = (goIpfsInfo && goIpfsInfo.version)
34+
const goIpfsVersion = (goIpfsInfo && goIpfsInfo.version)
3535
? pkg['go-ipfs'].version
3636
: 'v' + pkg.version.replace(/-[0-9]+/, '')
3737

38-
let distUrl = (goIpfsInfo && goIpfsInfo.distUrl)
39-
? pkg['go-ipfs'].distUrl
38+
let distUrl = (goIpfsInfo && goIpfsInfo.distUrl)
39+
? pkg['go-ipfs'].distUrl
4040
: 'https://dist.ipfs.io'
4141

4242
// Main function
4343
function download (version, platform, arch, installPath) {
4444
return new Promise((resolve, reject) => {
4545
// Environment Variables Args Defaults
46-
version = process.env.TARGET_VERSION || version || goIpfsVersion
47-
platform = process.env.TARGET_OS || platform || goenv.GOOS
48-
arch = process.env.TARGET_ARCH || arch || goenv.GOARCH
49-
distUrl = process.env.GO_IPFS_DIST_URL || distUrl
46+
version = process.env.TARGET_VERSION || version || goIpfsVersion
47+
platform = process.env.TARGET_OS || platform || goenv.GOOS
48+
arch = process.env.TARGET_ARCH || arch || goenv.GOARCH
49+
distUrl = process.env.GO_IPFS_DIST_URL || distUrl
5050
installPath = installPath ? path.resolve(installPath) : path.resolve(process.cwd())
5151

5252
// Make sure we support the requested package
@@ -92,14 +92,19 @@ function download (version, platform, arch, installPath) {
9292
process.stdout.write(`Downloading ${url}\n`)
9393

9494
request.get(url, (err, res, body) => {
95+
if (err) {
96+
// TODO handle error: haad?
97+
}
9598
// Handle errors
96-
if (res.statusCode !== 200)
99+
if (res.statusCode !== 200) {
97100
error(new Error(`${res.statusCode} - ${res.body}`), reject)
101+
}
98102
})
99103
.on('response', (res) => {
100104
// Unpack only if the request was successful
101-
if (res.statusCode !== 200)
102-
return
105+
if (res.statusCode !== 200) {
106+
return
107+
}
103108

104109
unpack(res)
105110
})

test/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const version = process.env.TARGET_VERSION || 'v' + pkg.version
1111

1212
// These tests won't work with promises, wrap the download function to a callback
1313
const download = (version, platform, arch, callback) => {
14-
if (typeof version === 'function' || !version) {
14+
if (typeof version === 'function' || !version) {
1515
callback = version || callback
1616
version = null
1717
}
@@ -26,7 +26,11 @@ const download = (version, platform, arch, callback) => {
2626
arch = null
2727
}
2828

29-
callback = callback || ((err, res) => {})
29+
callback = callback || ((err, res) => {
30+
if (err) {
31+
throw err
32+
}
33+
})
3034

3135
Download(version, platform, arch)
3236
.then((e) => callback(null, e))
@@ -38,6 +42,7 @@ test('Ensure ipfs gets downloaded (current version and platform)', (t) => {
3842
const dir = path.resolve(__dirname, '../go-ipfs')
3943
rimraf.sync(dir)
4044
download((err, res) => {
45+
t.ifErr(err)
4146
t.ok(res.file.indexOf(`ipfs_${version}_${goenv.GOOS}-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
4247
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
4348

@@ -53,6 +58,7 @@ test('Ensure Windows version gets downloaded', (t) => {
5358
const dir = path.resolve(__dirname, '../go-ipfs')
5459
rimraf.sync(dir)
5560
download(version, 'windows', (err, res) => {
61+
t.ifErr(err)
5662
t.ok(res.file.indexOf(`ipfs_${version}_windows-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
5763
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
5864

@@ -73,6 +79,7 @@ test('Ensure Linux version gets downloaded', (t) => {
7379
const dir = path.resolve(__dirname, '../go-ipfs')
7480
rimraf.sync(dir)
7581
download(version, 'linux', (err, res) => {
82+
t.ifErr(err)
7683
t.ok(res.file.indexOf(`ipfs_${version}_linux-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
7784
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
7885

@@ -93,6 +100,7 @@ test('Ensure OSX version gets downloaded', (t) => {
93100
const dir = path.resolve(__dirname, '../go-ipfs')
94101
rimraf.sync(dir)
95102
download(version, 'darwin', (err, res) => {
103+
t.ifErr(err)
96104
t.ok(res.file.indexOf(`ipfs_${version}_darwin-${goenv.GOARCH}`) !== -1, 'Returns the correct filename')
97105
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
98106

@@ -116,6 +124,7 @@ test('Ensure TARGET_OS, TARGET_VERSION and TARGET_ARCH version gets downloaded',
116124
process.env.TARGET_VERSION = version
117125
process.env.TARGET_ARCH = '386'
118126
download((err, res) => {
127+
t.ifErr(err)
119128
t.ok(res.file.indexOf(`ipfs_${process.env.TARGET_VERSION}_${process.env.TARGET_OS}-${process.env.TARGET_ARCH}`) !== -1, 'Returns the correct filename')
120129
t.ok(res.dir === path.resolve(__dirname, '../', 'go-ipfs') + '/', 'Returns the correct output path')
121130

0 commit comments

Comments
 (0)