Skip to content

Commit 641de87

Browse files
committed
Various tweaks
1 parent eaccf34 commit 641de87

7 files changed

Lines changed: 123 additions & 127 deletions

File tree

.editorconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
root = true
22

33
[*]
4-
indent_size = 4
54
indent_style = tab
65
end_of_line = lf
76
charset = utf-8
87
trim_trailing_whitespace = true
98
insert_final_newline = true
109

11-
[*.json]
10+
[*.{json,yml}]
1211
indent_size = 2
1312
indent_style = space
1413

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
node_modules
2-
test/tmp*

.jshintrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
"bitwise": true,
33
"camelcase": true,
44
"curly": true,
5-
"eqeqeq": true,
65
"esnext": true,
76
"immed": true,
87
"newcap": true,
98
"noarg": true,
109
"node": true,
11-
"quotmark": "single",
1210
"strict": true,
1311
"undef": true,
1412
"unused": "vars"

index.js

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -114,89 +114,74 @@ BinWrapper.prototype.path = function () {
114114
*/
115115

116116
BinWrapper.prototype.run = function (cmd, cb) {
117-
var self = this;
118-
119117
if (typeof cmd === 'function' && !cb) {
120118
cb = cmd;
121119
cmd = ['--version'];
122120
}
123121

124-
this.search(function (err, file) {
122+
this.findExisting(function (err, files) {
125123
if (err) {
126124
cb(err);
127125
return;
128126
}
129127

130-
if (!file) {
131-
return self.get(function (err) {
132-
if (err) {
133-
cb(err);
134-
return;
135-
}
136-
137-
self.test(cmd, cb);
138-
});
128+
if (this.opts.skipCheck) {
129+
cb();
130+
return;
139131
}
140132

141-
self.test(cmd, cb);
142-
});
133+
this.runCheck(cb);
134+
}.bind(this));
143135
};
144136

145137
/**
146-
* Search for the binary
138+
* Run binary check
147139
*
148140
* @param {Function} cb
149141
* @api private
150142
*/
151143

152-
BinWrapper.prototype.search = function (cb) {
153-
var self = this;
154-
155-
globby(this.path(), function (err, files) {
144+
BinWrapper.prototype.runCheck = function (cb) {
145+
binCheck(this.path(), function (err, works) {
156146
if (err) {
157147
cb(err);
158148
return;
159149
}
160150

161-
cb(null, files[0]);
162-
});
151+
if (!works) {
152+
cb(new Error('The `' + this.path() + '` binary doesn\'t seem to work correctly'));
153+
return;
154+
}
155+
156+
if (this.version()) {
157+
return binVersionCheck(this.path(), this.version(), cb);
158+
}
159+
160+
cb();
161+
}.bind(this));
163162
};
164163

165164
/**
166-
* Check if binary is working
167-
168-
* @param {Array} cmd
165+
* Find existing files
166+
*
169167
* @param {Function} cb
170168
* @api private
171169
*/
172170

173-
BinWrapper.prototype.test = function (cmd, cb) {
174-
var self = this;
175-
var name = path.basename(this.path());
176-
var version = this.version();
177-
178-
if (this.opts.skip) {
179-
cb();
180-
return;
181-
}
182-
183-
binCheck(this.path(), cmd, function (err, works) {
171+
BinWrapper.prototype.findExisting = function (cb) {
172+
globby(this.path(), function (err, files) {
184173
if (err) {
185174
cb(err);
186175
return;
187176
}
188177

189-
if (!works) {
190-
cb(new Error('The `' + name + '` binary doesn\'t seem to work correctly'));
178+
if (!files.length) {
179+
this.download(cb);
191180
return;
192181
}
193182

194-
if (version) {
195-
return binVersionCheck(self.path(), version, cb);
196-
}
197-
198-
cb();
199-
});
183+
cb(null, files);
184+
}.bind(this));
200185
};
201186

202187
/**
@@ -206,7 +191,7 @@ BinWrapper.prototype.test = function (cmd, cb) {
206191
* @api private
207192
*/
208193

209-
BinWrapper.prototype.get = function (cb) {
194+
BinWrapper.prototype.download = function (cb) {
210195
var files = osFilterObj(this.src());
211196
var download = new Download({
212197
extract: true,
@@ -223,8 +208,9 @@ BinWrapper.prototype.get = function (cb) {
223208
download.get(file.url);
224209
});
225210

226-
download.dest(this.dest());
227-
download.run(cb);
211+
download
212+
.dest(this.dest())
213+
.run(cb);
228214
};
229215

230216
/**
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
Copyright (c) Kevin Mårtensson
1+
The MIT License (MIT)
22

3-
Permission is hereby granted, free of charge, to any person obtaining a copy of
4-
this software and associated documentation files (the "Software"), to deal in
5-
the Software without restriction, including without limitation the rights to
6-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7-
of the Software, and to permit persons to whom the Software is furnished to do
8-
so, subject to the following conditions:
3+
Copyright (c) Kevin Mårtensson <[email protected]>
94

10-
The above copyright notice and this permission notice shall be included in all
11-
copies or substantial portions of the Software.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1214

1315
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1416
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1517
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1618
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1719
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md renamed to readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ console.log(bin.path()); // => path/to/vendor/gifsicle
4343

4444
Creates a new `BinWrapper` instance. The available options are:
4545

46-
* `skip`: Whether to skip checking if the binary works or not. Defaults to `false`.
46+
* `skipCheck`: Whether to skip checking if the binary works or not. Defaults to `false`.
4747
* `strip`: Strip a number of leading paths from file names on extraction. Defaults to `1`.
4848

4949
### .src(url, os, arch)

0 commit comments

Comments
 (0)