Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 5, 2018
1 parent 8bea013 commit 7584b88
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
language: node_js
node_js:
- '6'
- '4'
- '0.12'
script:
- 'echo "yo"'
- '8'
121 changes: 62 additions & 59 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,152 +1,155 @@
#!/usr/bin/env node
'use strict';
var url = require('url');
var meow = require('meow');
var speedtest = require('speedtest-net');
var updateNotifier = require('update-notifier');
var roundTo = require('round-to');
var chalk = require('chalk');
var logUpdate = require('log-update');
var logSymbols = require('log-symbols');
var Ora = require('ora');

var cli = meow([
'Usage',
' $ speed-test',
'',
'Options',
' -j, --json Output the result as JSON',
' -b, --bytes Output the result in megabytes per second (MBps)',
' -v, --verbose Output more detailed information'
], {
alias: {
j: 'json',
b: 'bytes',
v: 'verbose',
h: 'help'
const url = require('url');
const meow = require('meow');
const speedtest = require('speedtest-net');
const updateNotifier = require('update-notifier');
const roundTo = require('round-to');
const chalk = require('chalk');
const logUpdate = require('log-update');
const logSymbols = require('log-symbols');
const Ora = require('ora');

const cli = meow(`
Usage
$ speed-test
Options
--json -j Output the result as JSON
--bytes -b Output the result in megabytes per second (MBps)
--verbose -v Output more detailed information
`, {
flags: {
json: {
type: 'boolean',
alias: 'j'
},
bytes: {
type: 'boolean',
alias: 'b'
},
verbose: {
type: 'boolean',
alias: 'v'
}
}
});

updateNotifier({pkg: cli.pkg}).notify();

var stats = {
const stats = {
ping: '',
download: '',
upload: ''
};

var state = 'ping';
var spinner = new Ora();
var unit = cli.flags.bytes ? 'MBps' : 'Mbps';
var multiplier = cli.flags.bytes ? 1 / 8 : 1;
let state = 'ping';
const spinner = new Ora();
const unit = cli.flags.bytes ? 'MBps' : 'Mbps';
const multiplier = cli.flags.bytes ? 1 / 8 : 1;

function getSpinner(x) {
return state === x ? chalk.gray.dim(spinner.frame()) : ' ';
}
const getSpinner = x => state === x ? chalk.gray.dim(spinner.frame()) : ' ';

function render() {
if (cli.flags.json) {
console.log(JSON.stringify(stats));
return;
}

var output = [
'',
' Ping ' + getSpinner('ping') + stats.ping,
' Download ' + getSpinner('download') + stats.download,
' Upload ' + getSpinner('upload') + stats.upload
];
let output = `
Ping ${getSpinner('ping')}${stats.ping}
Download ${getSpinner('download')}${stats.download}
Upload ${getSpinner('upload')}${stats.upload}`;

if (cli.flags.verbose) {
output = output.concat([
output += [
'',
' Server ' + (stats.data === undefined ? '' : chalk.cyan(stats.data.server.host)),
' Location ' + (stats.data === undefined ? '' : chalk.cyan(stats.data.server.location + chalk.dim(' (' + stats.data.server.country + ')'))),
' Distance ' + (stats.data === undefined ? '' : chalk.cyan(roundTo(stats.data.server.distance, 1) + chalk.dim(' km')))
]);
].join('\n');
}

logUpdate(output.join('\n'));
logUpdate(output);
}

function setState(s) {
state = s;

if (s && s.length > 0) {
stats[s] = chalk.yellow('0 ' + chalk.dim(unit));
stats[s] = chalk.yellow(`0 ${chalk.dim(unit)}`);
}
}

function map(server) {
server.host = url.parse(server.url).host;
server.location = server.name;
server.distance = server.dist;

return server;
}

var st = speedtest({maxTime: 20000});
const st = speedtest({maxTime: 20000});

if (!cli.flags.json) {
setInterval(render, 50);
}

st.once('testserver', function (server) {
st.once('testserver', server => {
if (cli.flags.verbose) {
stats.data = {
server: map(server)
};
}

setState('download');
var ping = Math.round(server.bestPing);
const ping = Math.round(server.bestPing);
stats.ping = cli.flags.json ? ping : chalk.cyan(ping + chalk.dim(' ms'));
});

st.on('downloadspeedprogress', function (speed) {
st.on('downloadspeedprogress', speed => {
if (state === 'download' && cli.flags.json !== true) {
speed *= multiplier;
var download = roundTo(speed, speed >= 10 ? 0 : 1);
stats.download = chalk.yellow(download + ' ' + chalk.dim(unit));
const download = roundTo(speed, speed >= 10 ? 0 : 1);
stats.download = chalk.yellow(`${download} ${chalk.dim(unit)}`);
}
});

st.on('uploadspeedprogress', function (speed) {
st.on('uploadspeedprogress', speed => {
if (state === 'upload' && cli.flags.json !== true) {
speed *= multiplier;
var upload = roundTo(speed, speed >= 10 ? 0 : 1);
stats.upload = chalk.yellow(upload + ' ' + chalk.dim(unit));
const upload = roundTo(speed, speed >= 10 ? 0 : 1);
stats.upload = chalk.yellow(`${upload} ${chalk.dim(unit)}`);
}
});

st.once('downloadspeed', function (speed) {
st.once('downloadspeed', speed => {
setState('upload');
speed *= multiplier;
var download = roundTo(speed, speed >= 10 && !cli.flags.json ? 0 : 1);
const download = roundTo(speed, speed >= 10 && !cli.flags.json ? 0 : 1);
stats.download = cli.flags.json ? download : chalk.cyan(download + ' ' + chalk.dim(unit));
});

st.once('uploadspeed', function (speed) {
st.once('uploadspeed', speed => {
setState('');
speed *= multiplier;
var upload = roundTo(speed, speed >= 10 && !cli.flags.json ? 0 : 1);
const upload = roundTo(speed, speed >= 10 && !cli.flags.json ? 0 : 1);
stats.upload = cli.flags.json ? upload : chalk.cyan(upload + ' ' + chalk.dim(unit));
});

st.on('data', function (data) {
st.on('data', data => {
if (cli.flags.verbose) {
stats.data = data;
}

render();
});

st.on('done', function () {
st.on('done', () => {
console.log();
process.exit();
});

st.on('error', function (err) {
st.on('error', err => {
if (err.code === 'ENOTFOUND') {
console.error(logSymbols.error, 'Please check your internet connection');
} else {
Expand Down
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
100 changes: 50 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
{
"name": "speed-test",
"version": "1.8.0",
"description": "Test your internet connection speed and ping using speedtest.net from the CLI",
"license": "MIT",
"repository": "sindresorhus/speed-test",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"bin": "cli.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"cli.js"
],
"keywords": [
"cli-app",
"cli",
"speed",
"test",
"tester",
"speed-test",
"speedtest",
"connection",
"internet",
"bandwidth",
"ping",
"measure",
"check"
],
"dependencies": {
"chalk": "^1.1.0",
"log-symbols": "^1.0.2",
"log-update": "^1.0.0",
"meow": "^3.3.0",
"ora": "^0.2.1",
"round-to": "^1.0.0",
"speedtest-net": "^1.2.4",
"update-notifier": "^0.6.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.1.1",
"xo": "*"
}
"name": "speed-test",
"version": "1.8.0",
"description": "Test your internet connection speed and ping using speedtest.net from the CLI",
"license": "MIT",
"repository": "sindresorhus/speed-test",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"bin": "cli.js",
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"cli.js"
],
"keywords": [
"cli-app",
"cli",
"speed",
"test",
"tester",
"speed-test",
"speedtest",
"connection",
"internet",
"bandwidth",
"ping",
"measure",
"check"
],
"dependencies": {
"chalk": "^2.3.0",
"log-symbols": "^2.2.0",
"log-update": "^2.3.0",
"meow": "^4.0.0",
"ora": "^1.4.0",
"round-to": "^2.0.0",
"speedtest-net": "^1.2.4",
"update-notifier": "^2.3.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.9.0",
"xo": "*"
}
}
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ $ speed-test --help
$ speed-test
Options
-j, --json Output the result as JSON
-b, --bytes Output the result in megabytes per second (MBps)
-v, --verbose Output more detailed information
--json -j Output the result as JSON
--bytes -b Output the result in megabytes per second (MBps)
--verbose -v Output more detailed information
```


Expand Down

0 comments on commit 7584b88

Please sign in to comment.