Skip to content

Commit

Permalink
refactor(cli): remove lodash dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Jun 29, 2016
1 parent e034326 commit c245a87
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 72 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"dependencies": {
"graceful-fs": "^4.1.3",
"humanize-plus": "^1.8.1",
"lodash": "^4.0.0",
"meow": "^3.7.0",
"muxer": "^1.0.1",
"progress": "^1.1.8",
Expand Down
1 change: 0 additions & 1 deletion src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {mux, demux} from 'muxer'

export const UTILS = U
export const createDownload = (_options) => {

const HTTP = T.HTTP(request)
const FILE = T.FILE(fs)
const options = U.MergeDefaultOptions(_options)
Expand Down
13 changes: 0 additions & 13 deletions src/bin/NewDownload.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/bin/ResumeDownload.js

This file was deleted.

50 changes: 8 additions & 42 deletions src/bin/mtd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
*/

'use strict'

import Rx from 'rx'
import _ from 'lodash'
import * as U from '../Utils'
import meow from 'meow'
import humanize from 'humanize-plus'
import newDownload from './NewDownload'
import resumeDownload from './ResumeDownload'
import {createDownload} from '../Main'
import ProgressBar from 'progress'

const flags = meow(`
import R from 'ramda'
const HELP_TEXT = `
Usage
mtd
Expand All @@ -25,39 +18,12 @@ const flags = meow(`
Examples
mtd --url http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4
mtd --file big_buck_bunny_720p_1mb.mp4.mtd
`).flags
`
const flags = meow(HELP_TEXT).flags

if (!_.some([flags.url, flags.file], (x) => x)) {
if (!R.any(R.identity)([flags.url, flags.file])) {
console.log(HELP_TEXT)
process.exit(0)
}

const pFlags = Rx.Observable.just(flags)

// TODO: Add unit tests
const downloads = Rx.Observable.merge(
newDownload(createDownload, pFlags),
resumeDownload(createDownload, pFlags)
).share()

const progress = downloads
.pluck('message', 'totalBytes')
.filter((x) => x > 0)
.first()
.map((total) => new ProgressBar(':bar :percent', {total, complete: '█', incomplete: '░'}))
.tap((x) => console.log(`SIZE: ${humanize.fileSize(x.total)}`)).share()

downloads
.filter((x) => x)
.filter((x) => x.event === 'DATA')
.pluck('message')

.map((x) => _.sum(_.map(x.offsets, (o, i) => o - x.threads[i][0])) / x.totalBytes)
.withLatestFrom(progress, (bytes, progress) => ({bytes, progress}))
.subscribe((x) => x.progress.update(x.bytes))

downloads.last()
.withLatestFrom(progress, (a, b) => b)
.subscribe((x) => {
x.update(x.total)
console.log('Download Completed!')
})
U.CLI(flags)

0 comments on commit c245a87

Please sign in to comment.