Skip to content
Open
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
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# wgetjs [![NPM version](https://badge.fury.io/js/wgetjs.png?branch=master)](http://badge.fury.io/js/wgetjs) [![Build Status](https://travis-ci.org/angleman/wgetjs.png?branch=master)](https://travis-ci.org/angleman/wgetjs) [![Dependency Status](https://gemnasium.com/angleman/wgetjs.png?branch=master)](https://gemnasium.com/angleman/wgetjs) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](#licensemit)
Ultra simple async retrieval of remote files over http or https
Ultra simple async retrieval of remote files over http or https inspired by wgetjs

## Install

```
npm install wgetjs
npm install node-wget
```

## Usage

```javascript
var wget = require('wgetjs');
var wget = require('node-wget');

wget(url);

Expand All @@ -24,7 +24,7 @@ wget({url: url, dry: true}); // dry run, nothing loaded, callback passing parsed
## Examples

```javascript
var wget = require('wgetjs');
var wget = require('node-wget');

wget('https://raw.github.com/angleman/wgetjs/master/angleman.png'); // angleman.png saved to current folder

Expand Down Expand Up @@ -58,4 +58,34 @@ wget({
);
```

## CLI

Install:

```bash
$ npm install -g node-wget
```

Use:

```text
Usage: wget [options] <url>

Ultra simple async retrieval of remote files over http or https

Options:

-h, --help output usage information
-v, --version output version number
-d, --destination <folder> specify download destination

Usage:

# Download file
$ wget https://github.com/NodeOS/NodeOS/archive/master.zip

# Download file to location
$ wget https://github.com/NodeOS/NodeOS/archive/master.zip -d path/to/here/
```

## License: MIT
99 changes: 99 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env node
'use strict';

/* eslint-disable no-process-exit */

/*
* Dependencies.
*/

var wget = require('./');
var pack = require('./package.json');

/*
* Arguments.
*/

var argv = process.argv.slice(2);

/*
* Command.
*/

var command = Object.keys(pack.bin)[0];

/**
* Help.
*
* @return {string}
*/
function help() {
return [
'',
'Usage: ' + command + ' [options] [url]...',
'',
pack.description,
'',
'Options:',
'',
' -h, --help output usage information',
' -v, --version output version number',
'',
'Usage:',
'',
'# Download file',
'$ ' + command + ' https://github.com/NodeOS/NodeOS/archive/master.zip',
''
].join('\n ') + '\n';
}

/*
* Program.
*/

if (
argv.indexOf('--help') !== -1 ||
argv.indexOf('-h') !== -1
) {
console.log(help());
} else if (
argv.indexOf('--version') !== -1 ||
argv.indexOf('-v') !== -1
) {
console.log(pack.version);
} else if (argv.length) {
var destinationIndex = argv.indexOf('--destination') + argv.indexOf('-d') + 2;

var args = {};
if(destinationIndex){
args.dest = argv[destinationIndex];
argv.splice(destinationIndex-1,2);
}
args.url = firstNonFlag(argv);
if(args.url.length > 0){
console.log("Downloading...");
wget(args, callback);
}else{
console.log(help());
}
} else {
console.log(help());
}

function callback(error, response, body){
if(error){
console.log('--- error:');
console.log(error);
}else{
console.log('Done!');
}
}

function firstNonFlag(args){
for(var i = 0; i < args.length; i++){
if(args[i].charAt(0) != '-'){
return args[i];
}
}
return "";
}
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wgetjs",
"version": "0.3.6",
"name": "node-wget",
"version": "0.4.3",
"description": "Ultra simple async retrieval of remote files over http or https",
"main": "wget.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/angleman/wgetjs.git"
"url": "https://github.com/tylerl0706/wgetjs.git"
},
"keywords": [
"curl",
Expand All @@ -19,23 +19,26 @@
"http",
"https"
],
"author": "angleman",
"author": "tylerl0706",
"license": "MIT",
"bugs": {
"url": "https://github.com/angleman/wgetjs/issues"
"url": "https://github.com/tylerl0706/wgetjs/issues"
},
"engines": {
"node": ">=0.8.6"
},
"bin": {
"wget": "cli.js"
},
"dependencies": {
"request": "~2.27.0"
"request": "~2.85.0"
},
"devDependencies": {
"license-md": "~0.2.5",
"grunt": "~0.4.1",
"grunt-bump": "~0.0.11",
"grunt-license": "~0.1.4",
"mocha": "~1.12.0",
"should": "~1.2.2"
"license-md": "~0.3.6",
"grunt": "~1.0.2",
"grunt-bump": "~0.8.0",
"grunt-license": "~0.1.5",
"mocha": "~5.0.4",
"should": "~13.2.1"
}
}
}