11"use strict" ;
22
3- if ( ! global . Promise || ! global . promise . promisify ) {
4- global . Promise = require ( 'bluebird' ) ;
5- }
3+ var Bluebird = require ( 'bluebird' ) ;
64
75// Enable heap dumps in /tmp on kill -USR2.
86// See https://github.com/bnoordhuis/node-heapdump/
@@ -16,7 +14,7 @@ process.on('SIGUSR2', function() {
1614} ) ;
1715
1816var preq = require ( 'preq' ) ;
19- var fs = Promise . promisifyAll ( require ( 'fs' ) ) ;
17+ var fs = Bluebird . promisifyAll ( require ( 'fs' ) ) ;
2018var PromiseStream = require ( './PromiseStream' ) ;
2119
2220// Article dump parallelism
@@ -26,7 +24,7 @@ function getArticles (options, res) {
2624 var next = res . next || '' ;
2725 if ( next === 'finished' ) {
2826 // nothing more to do.
29- return Promise . reject ( 'Articles done' ) ;
27+ return Bluebird . reject ( 'Articles done' ) ;
3028 }
3129
3230 var url = options . apiURL + '?action=query&generator=allpages&gapfilterredir=nonredirects'
@@ -116,14 +114,14 @@ function dumpArticle (options, title, oldid) {
116114 if ( options . saveDir ) {
117115 checkRevision = checkArticle ( options , title , oldid ) ;
118116 } else {
119- checkRevision = Promise . resolve ( false ) ;
117+ checkRevision = Bluebird . resolve ( false ) ;
120118 }
121119
122120 return checkRevision
123121 . then ( function ( checkResult ) {
124122 if ( ! checkResult ) {
125123 console . log ( 'Dumping' , title , oldid ) ;
126- var url = 'http://' + options . host + '/' + options . prefix
124+ var url = options . host + '/' + options . prefix
127125 + '/v1/page/html/' + encodeURIComponent ( title ) + '/' + oldid ;
128126 return preq . get ( {
129127 uri : url ,
@@ -169,12 +167,12 @@ Dumper.prototype.processArticles = function (newArticles) {
169167Dumper . prototype . getArticle = function ( ) {
170168 var self = this ;
171169 if ( this . articles . length ) {
172- return Promise . resolve ( this . articles . shift ( ) ) ;
170+ return Bluebird . resolve ( this . articles . shift ( ) ) ;
173171 } else {
174172 if ( ! this . waiters . length ) {
175173 this . articleChunkStream . next ( ) . then ( this . processArticles . bind ( this ) ) ;
176174 }
177- return new Promise ( function ( resolve , reject ) {
175+ return new Bluebird ( function ( resolve , reject ) {
178176 self . waiters . push ( { resolve : resolve , reject : reject } ) ;
179177 } ) ;
180178 }
@@ -222,19 +220,27 @@ function makeDump (options) {
222220}
223221
224222if ( module . parent === null ) {
225- var argv = require ( 'yargs' )
223+ var argParser = require ( 'yargs' )
226224 . usage ( 'Create a HTML dump in a subdir\nUsage: $0'
227- + '\nExample: node htmldumper.js --prefix en.wikipedia.org --ns 0 --apiURL http://en.wikipedia.org/w/api.php' )
225+ + '\nExample:\nnode htmldumper.js --prefix en.wikipedia.org --ns 0 --apiURL http://en.wikipedia.org/w/api.php --host http://rest.wikimedia.org ' )
228226 . demand ( [ 'apiURL' , 'prefix' , 'ns' , 'host' ] )
227+ . options ( 'h' , {
228+ alias : 'help'
229+ } )
229230 . options ( 'd' , {
230231 alias : 'saveDir' ,
231232 default : ''
232- } )
233+ } ) ;
233234 //.default('apiURL', 'http://en.wikipedia.org/w/api.php')
234235 //.default('prefix', 'en.wikipedia.org')
235236 //.default('ns', '0')
236- //.default('host', 'https://rest.wikimedia.org')
237- . argv ;
237+ //.default('host', 'http://rest.wikimedia.org');
238+
239+ var argv = argParser . argv ;
240+ if ( argv . h ) {
241+ argParser . showHelp ( ) ;
242+ process . exit ( 1 ) ;
243+ }
238244
239245 argv . ns = Number ( argv . ns ) ;
240246 return makeDump ( argv )
0 commit comments