@@ -3,6 +3,7 @@ var fs = require('fs'),
33 request = require ( 'request' ) ,
44 ncp = require ( 'ncp' ) . ncp ,
55 path = require ( 'path' ) ,
6+ parseUrl = require ( 'url' ) . parse ,
67 shelljs = require ( 'shelljs/global' ) ,
78 argv = require ( 'optimist' ) . argv ,
89 prompt = require ( 'prompt' ) ,
@@ -150,13 +151,19 @@ IonicTask.prototype.fetchWrapper = function() {
150151IonicTask . prototype . fetchSeed = function ( ) {
151152
152153 // Codepen: http://codepen.io/ionic/pen/GpCst
153- if ( this . template . toLowerCase ( ) . indexOf ( 'codepen' ) > - 1 ) {
154+ if ( / \/ \/ c o d e p e n . i o \/ / i . test ( this . template ) ) {
154155 this . seedType = 'codepen' ;
155156 return this . fetchCodepen ( ) ;
156157 }
157158
159+ // Github URL: http://github.com/myrepo/
160+ if ( / \/ \/ g i t h u b .c o m \/ / i. test ( this . template ) ) {
161+ this . seedType = 'github' ;
162+ return this . fetchGithubStarter ( this . template ) ;
163+ }
164+
158165 // Local Directory: /User/starterapp
159- if ( this . template . indexOf ( '/' ) > - 1 || this . template . indexOf ( '\\' ) > - 1 ) {
166+ if ( ( this . template . indexOf ( '/' ) > - 1 || this . template . indexOf ( '\\' ) > - 1 ) && ( this . indexOf ( 'http://' ) === - 1 && this . indexOf ( 'https://' ) === - 1 ) ) {
160167 this . seedType = 'local' ;
161168 return this . fetchLocalStarter ( ) ;
162169 }
@@ -322,31 +329,57 @@ IonicTask.prototype.fetchLocalStarter = function() {
322329
323330
324331IonicTask . prototype . fetchIonicStarter = function ( ) {
325- var self = this ;
326- var q = Q . defer ( ) ;
327332
328333 // Get the starter project repo name:
329- var repoName = 'ionic-starter-' + self . template ;
334+ var repoName = 'ionic-starter-' + this . template ;
330335
331336 // Get the URL for the starter project repo:
332- var repoUrl = 'https://github.com/driftyco/' + repoName + '/archive/master.zip' ;
337+ var repoUrl = 'https://github.com/driftyco/' + repoName ;
338+
339+ return this . fetchGithubStarter ( repoUrl ) ;
340+ } ;
341+
342+
343+ IonicTask . prototype . fetchGithubStarter = function ( repoUrl ) {
344+ var self = this ;
345+ var q = Q . defer ( ) ;
346+
347+ // https://github.com/driftyco/ionic-starter-tabs/
348+ var urlParse = parseUrl ( repoUrl ) ;
349+ var pathSplit = urlParse . pathname . replace ( / \/ / g, ' ' ) . trim ( ) . split ( ' ' ) ;
350+ if ( ! urlParse . hostname || urlParse . hostname . toLowerCase ( ) !== 'github.com' || pathSplit . length !== 2 ) {
351+ console . log ( ( 'Invalid Github URL: ' + repoUrl ) . error ) ;
352+ console . log ( ( 'Example of a valid URL: https://github.com/driftyco/ionic-starter-tabs/' ) . error ) ;
353+ self . ionic . fail ( '' ) ;
354+ q . reject ( ) ;
355+ return q . promise ;
356+ }
357+ var repoName = pathSplit [ 1 ] ;
358+ var repoFolderName = repoName + '-master' ;
359+
360+ // ensure there's an ending /
361+ if ( repoUrl . substr ( repoUrl . length - 1 ) !== '/' ) {
362+ repoUrl += '/' ;
363+ }
364+ repoUrl += 'archive/master.zip' ;
333365
334366 Ionic . fetchArchive ( self . targetPath , repoUrl ) . then ( function ( ) {
335367
336- var repoFolderName = repoName + '-master' ;
368+ try {
369+ // Move the content of this repo into the www folder
370+ cp ( '-Rf' , self . targetPath + '/' + repoFolderName + '/.' , 'www' ) ;
337371
338- // Move the content of this repo into the www folder
339- cp ( '-Rf ' , self . targetPath + '/' + repoFolderName + '/.' , 'www ') ;
372+ // Clean up start template folder
373+ rm ( '-rf ' , self . targetPath + '/' + repoFolderName + '/' ) ;
340374
341- // Clean up start template folder
342- rm ( '-rf' , self . targetPath + '/' + repoFolderName + '/' ) ;
375+ q . resolve ( ) ;
343376
344- q . resolve ( ) ;
377+ } catch ( e ) {
378+ q . reject ( e ) ;
379+ }
345380
346381 } ) . catch ( function ( err ) {
347- console . error ( 'Error: Unable to fetch project: HTTP:' . error . bold , err . statusCode ) ;
348- console . error ( 'Valid project types are "blank", "tabs", or "sidemenu"' . error . bold ) ;
349- console . error ( 'More info available at: http://ionicframework.com/getting-started/' . error . bold ) ;
382+ console . error ( 'More info available at: \nhttp://ionicframework.com/getting-started/\nhttps://github.com/driftyco/ionic-cli' . error . bold ) ;
350383 return self . ionic . fail ( '' ) ;
351384 } ) ;
352385
0 commit comments