@@ -99,6 +99,10 @@ IonicTask.prototype.getVersionData = function(version) {
9999 return ;
100100 }
101101 self . versionData = JSON . parse ( body ) ;
102+ self . versionData . version_number = self . versionData . version_number || self . versionData . version ;
103+ self . versionData . version_codename = self . versionData . version_codename || self . versionData . codename ;
104+ self . versionData . release_date = self . versionData . release_date || self . versionData . date ;
105+
102106 q . resolve ( ) ;
103107 } catch ( e ) {
104108 console . log ( 'Error loading ' . bold . error + version . bold + ' version information' . bold . error ) ;
@@ -192,40 +196,33 @@ IonicTask.prototype.downloadZip = function(version) {
192196 var self = this ;
193197
194198 var archivePath = 'https://github.com/driftyco/ionic-bower/archive/v' + version + '.zip' ;
195- self . tmpZipPath = path . resolve ( 'www/lib/ionic/ionic.zip' ) ;
196199
197- console . log ( 'Downloading: ' . green . bold + archivePath ) ;
200+ self . tmpExtractPath = path . resolve ( 'www/lib/.ionic' ) ;
201+ self . tmpZipPath = path . join ( self . tmpExtractPath , 'ionic.zip' ) ;
198202
199- var file = fs . createWriteStream ( self . tmpZipPath ) ;
200- file . on ( 'error' , function ( err ) {
201- console . log ( ( 'downloadZip createWriteStream: ' + err ) . error ) ;
202- } ) ;
203+ if ( ! fs . existsSync ( self . tmpExtractPath ) ) {
204+ fs . mkdirSync ( self . tmpExtractPath ) ;
205+ }
206+
207+ console . log ( 'Downloading: ' . green . bold + archivePath ) ;
203208
204209 var proxy = process . env . PROXY || null ;
205- request ( { url : archivePath , encoding : null , proxy : proxy } , function ( err , res , body ) {
210+ request ( { url : archivePath , rejectUnauthorized : false , encoding : null , proxy : proxy } , function ( err , res , body ) {
206211 if ( err ) {
207212 console . log ( err ) ;
208213 return ;
209214 }
210- if ( res . statusCode == 404 ) {
215+ if ( res . statusCode == 404 || res . statusCode == 406 ) {
211216 console . log ( ( 'Invalid version: ' + version ) . bold . red ) ;
212- try {
213- file . close ( ) ;
214- fs . unlink ( self . tmpZipPath ) ;
215- } catch ( e ) {
216- console . error ( ( e ) . red ) ;
217- }
218217 return ;
219218 }
220219 if ( res . statusCode >= 400 ) {
221220 console . log ( 'Unable to download zip (' + res . statusCode + ')' ) ;
222221 return ;
223222 }
224223 try {
225- file . write ( body ) ;
226- file . close ( function ( ) {
227- self . updateFiles ( ) ;
228- } ) ;
224+ fs . writeFileSync ( self . tmpZipPath , body ) ;
225+ self . updateFiles ( ) ;
229226 } catch ( e ) {
230227 console . error ( ( e ) . red ) ;
231228 }
@@ -260,63 +257,67 @@ IonicTask.prototype.downloadZip = function(version) {
260257IonicTask . prototype . updateFiles = function ( version ) {
261258 var self = this ;
262259 var ionicLibDir = path . resolve ( 'www/lib/ionic' ) ;
263- var readStream = fs . createReadStream ( self . tmpZipPath ) ;
264260
265261 try {
262+ var readStream = fs . createReadStream ( self . tmpZipPath ) ;
263+ readStream . on ( 'error' , function ( err ) {
264+ console . log ( ( 'updateFiles readStream: ' + err ) . error ) ;
265+ } ) ;
266266
267- function onEntry ( entry ) {
268- var libEntryPath = entry . path . replace ( 'ionic-bower-' + self . versionData . version_number + '/' , ionicLibDir + '/' ) ;
269-
270- if ( / b o w e r .j s o n | r e a d m e / gi. test ( entry . path ) ) {
271- entry . autodrain ( ) ;
272- return ;
273- }
267+ var writeStream = unzip . Extract ( { path : self . tmpExtractPath } ) ;
268+ writeStream . on ( 'close' , function ( ) {
269+ try {
270+ rm ( '-rf' , self . tmpZipPath )
271+ } catch ( e ) { }
274272
275- if ( entry . type == 'Directory' ) {
276- if ( ! fs . existsSync ( libEntryPath ) ) {
277- fs . mkdirSync ( libEntryPath ) ;
273+ try {
274+ var dir = fs . readdirSync ( self . tmpExtractPath ) ;
275+ var copyFrom ;
276+ for ( var x = 0 ; x < dir . length ; x ++ ) {
277+ if ( dir [ x ] . indexOf ( 'ionic' ) === 0 ) {
278+ copyFrom = path . join ( self . tmpExtractPath , dir [ x ] , '*' ) ;
279+ }
280+ }
281+ if ( ! copyFrom ) {
282+ console . log ( 'updateFiles, invalid zip' ) ;
283+ return ;
278284 }
279- } else {
280- var writeStream = fs . createWriteStream ( libEntryPath ) ;
281- writeStream . on ( 'error' , function ( err ) {
282- console . log ( ( 'updateFiles error writing, ' + libEntryPath + ': ' + err ) . error ) ;
283- } ) ;
284- entry . pipe ( writeStream ) ;
285- }
286285
287- entry . autodrain ( ) ;
288- }
286+ cp ( '-Rf' , copyFrom , ionicLibDir ) ;
289287
290- readStream . pipe ( unzip . Parse ( ) )
291- . on ( 'entry' , onEntry )
292- . on ( 'close' , function ( ) {
293- try {
294- console . log ( 'Ionic version updated to: ' . bold . green + self . versionData . version_number . bold ) ;
295- IonicStats . t ( ) ;
288+ try {
289+ rm ( '-rf' , self . tmpExtractPath )
290+ } catch ( e ) { }
296291
297- self . writeVersionData ( ) ;
292+ try {
293+ rm ( '-rf' , path . join ( ionicLibDir , 'README.md' ) ) ;
294+ } catch ( e ) { }
298295
299- var ionicBower = require ( './bower' ) . IonicBower ;
300- ionicBower . setIonicVersion ( self . versionData . version_number ) ;
296+ try {
297+ rm ( '-rf' , path . join ( ionicLibDir , 'bower.json' ) ) ;
298+ } catch ( e ) { }
301299
302- } catch ( e ) {
303- console . log ( ( 'Error loading version info: ' + e ) . error . bold ) ;
304- }
305- } ) ;
300+ console . log ( 'Ionic version updated to: ' . bold . green + self . versionData . version_number . bold ) ;
301+ IonicStats . t ( ) ;
306302
307- readStream . on ( 'error' , function ( err ) {
308- console . log ( ( 'updateFiles readStream: ' + err ) . error ) ;
309- } ) ;
303+ self . writeVersionData ( ) ;
310304
311- readStream . on ( 'close' , function ( err ) {
312- try {
313- fs . unlink ( self . tmpZipPath ) ;
314- } catch ( e ) { }
305+ var ionicBower = require ( './bower' ) . IonicBower ;
306+ ionicBower . setIonicVersion ( self . versionData . version_number ) ;
307+
308+ } catch ( e ) {
309+ console . log ( 'updateFiles Error: ' + e ) ;
310+ }
315311 } ) ;
312+ writeStream . on ( 'error' , function ( err ) {
313+ console . log ( ( 'updateFiles writeStream: ' + err ) . error ) ;
314+ } ) ;
315+ readStream . pipe ( writeStream ) ;
316316
317- } catch ( err ) {
318- console . log ( 'Error: ' + err ) ;
317+ } catch ( e ) {
318+ console . log ( 'updateFiles Error: ' + e ) ;
319319 }
320+
320321} ;
321322
322323IonicTask . prototype . writeVersionData = function ( ) {
0 commit comments