forked from ionic-team/ionic-app-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathionic.js
947 lines (841 loc) · 29 KB
/
ionic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
/*
_ _
(_) (_)
_ ___ _ __ _ ___
| |/ _ \| '_ \| |/ __|
| | (_) | | | | | (__
|_|\___/|_| |_|_|\___|
http://ionicframework.com/
A utility for starting and administering Ionic based mobile app projects.
Licensed under the MIT license. See LICENSE For more.
Copyright 2014 Drifty (http://drifty.com/)
*/
var argv = require('optimist').argv,
colors = require('colors'),
Q = require('q'),
settings = require('./package.json'),
IonicInfo = require('./lib/info').IonicTask;
shelljs = require('shelljs/global');
// Multibar = require('./ionic/multibar');
// var reportExtras = function reportExtras() {
// var ionicInfo = new IonicInfo();
// var commandLineInfo = process.argv;
// var info = ionicInfo.gatherInfo();
// info.command = commandLineInfo;
// console.log('Command line stuff:', commandLineInfo);
// return info;
// }
// var opbeat = require('opbeat-ionic')({
// organizationId: '7456d1360946446791cde22d1ff90a56',
// appId: '1a3f490314',
// secretToken: 'f058c32e757d3c589c3c1a7236767a307b780d0b',
// clientLogLevel: 'fatal',
// prerequestMethod: reportExtras
// });
// colors.setTheme({
// silly: 'rainbow',
// input: 'grey',
// small: 'grey',
// verbose: 'cyan',
// prompt: 'grey',
// info: 'white',
// data: 'grey',
// help: 'cyan',
// warn: 'yellow',
// debug: 'blue',
// error: 'red'
// });
// var TASKS = [
// {
// title: 'start',
// name: 'start',
// summary: 'Starts a new Ionic project in the specified PATH',
// args: {
// '[options]': 'any flags for the command',
// '<PATH>': 'directory for the new project',
// '[template]': 'Template name, ex: tabs, sidemenu, blank\n' +
// 'Codepen url, ex: http://codepen.io/ionic/pen/odqCz\n' +
// 'Defaults to Ionic "tabs" starter template'
// },
// options: {
// '--appname|-a': 'Human readable name for the app (Use quotes around the name)',
// '--id|-i': 'Package name for <widget id> config, ex: com.mycompany.myapp',
// '--no-cordova|-w': 'Create a basic structure without Cordova requirements',
// '--sass|-s': 'Setup the project to use Sass CSS precompiling',
// '--list|-l': 'List starter templates available'
// },
// module: './ionic/start'
// },
// {
// title: 'serve',
// name: 'serve',
// summary: 'Start a local development server for app dev/testing',
// args: {
// '[options]': ''
// },
// options: {
// '--consolelogs|-c': 'Print app console logs to Ionic CLI',
// '--serverlogs|-s': 'Print dev server logs to Ionic CLI',
// '--port|-p': 'Dev server HTTP port (8100 default)',
// '--livereload-port|-r': 'Live Reload port (35729 default)',
// '--nobrowser|-b': 'Disable launching a browser',
// '--nolivereload': 'Do not start live reload',
// '--noproxy|-x': 'Do not add proxies',
// '--address': 'Use specific address or return with failure',
// '--lab': 'Test your apps on multiple screen sizes and platform types'
// },
// module: './ionic/serve'
// },
// {
// title: 'platform',
// name: 'platform',
// summary: 'Add platform target for building an Ionic app',
// args: {
// '[options]': '',
// '<PLATFORM>': ''
// },
// module: './ionic/cordova'
// },
// {
// title: 'run',
// name: 'run',
// summary: 'Run an Ionic project on a connected device',
// args: {
// '[options]': '',
// '<PLATFORM>': ''
// },
// options: {
// '--livereload|-l': 'Live reload app dev files from the device' + ' (beta)'.yellow,
// '--port|-p': 'Dev server HTTP port (8100 default, livereload req.)',
// '--livereload-port|-r': 'Live Reload port (35729 default, livereload req.)',
// '--consolelogs|-c': 'Print app console logs to Ionic CLI (livereload req.)',
// '--serverlogs|-s': 'Print dev server logs to Ionic CLI (livereload req.)',
// '--debug|--release': '',
// '--device|--emulator|--target=FOO': ''
// },
// module: './ionic/cordova'
// },
// {
// title: 'emulate',
// name: 'emulate',
// summary: 'Emulate an Ionic project on a simulator or emulator',
// args: {
// '[options]': '',
// '<PLATFORM>': ''
// },
// options: {
// '--livereload|-l': 'Live reload app dev files from the device' + ' (beta)'.yellow,
// '--port|-p': 'Dev server HTTP port (8100 default, livereload req.)',
// '--livereload-port|-r': 'Live Reload port (35729 default, livereload req.)',
// '--consolelogs|-c': 'Print app console logs to Ionic CLI (livereload req.)',
// '--serverlogs|-s': 'Print dev server logs to Ionic CLI (livereload req.)',
// '--debug|--release': '',
// '--device|--emulator|--target=FOO': ''
// },
// module: './ionic/cordova'
// },
// {
// title: 'build',
// name: 'build',
// summary: 'Locally build an Ionic project for a given platform',
// args: {
// '[options]': '',
// '<PLATFORM>': ''
// },
// module: './ionic/cordova'
// },
// {
// title: 'plugin add',
// name: 'plugin',
// summary: 'Add a Cordova plugin',
// args: {
// '[options]': '',
// '<SPEC>': 'Can be a plugin ID, a local path, or a git URL.'
// },
// options: {
// '--searchpath <directory>': 'When looking up plugins by ID, look in this directory\n' +
// 'and subdirectories first for the plugin before\n' +
// 'looking it up in the registry.'
// },
// module: './ionic/cordova'
// },
// {
// title: 'prepare',
// name: 'prepare',
// module: './ionic/cordova'
// },
// {
// title: 'compile',
// name: 'compile',
// module: './ionic/cordova'
// },
// {
// title: 'resources',
// name: 'resources',
// summary: 'Automatically create icon and splash screen resources' + ' (beta)'.yellow,
// options: {
// '--icon|-i': 'Generate icon resources',
// '--splash|-s': 'Generate splash screen resources'
// },
// module: './ionic/resources/generate'
// },
// {
// title: 'package',
// name: 'package',
// alt: ['pack'],
// summary: 'Package an app using the Ionic Build service' + ' (beta)'.yellow,
// args: {
// '[options]': '',
// '<MODE>': '"debug" or "release"',
// '<PLATFORM>': '"ios" or "android"'
// },
// options: {
// '--android-keystore-file|-k': 'Android keystore file',
// '--android-keystore-alias|-a': 'Android keystore alias',
// '--android-keystore-password|-w': 'Android keystore password',
// '--android-key-password|-r': 'Android key password',
// '--ios-certificate-file|-c': 'iOS certificate file',
// '--ios-certificate-password|-d': 'iOS certificate password',
// '--ios-profile-file|-f': 'iOS profile file',
// '--output|-o': 'Path to save the packaged app',
// '--no-email|-n': 'Do not send a build package email',
// '--clear-signing|-l': 'Clear out all signing data from Ionic server',
// '--email|-e': 'Ionic account email',
// '--password|-p': 'Ionic account password'
// },
// module: './ionic/package'
// },
// {
// title: 'upload',
// name: 'upload',
// summary: 'Upload an app to your Ionic account',
// options: {
// '--email|-e': 'Ionic account email',
// '--password|-p': 'Ionic account password'
// },
// alt: ['up'],
// module: './ionic/upload'
// },
// {
// title: 'lib',
// name: 'lib',
// summary: 'Gets Ionic library version or updates the Ionic library',
// args: {
// '[options]': '',
// '[update]': 'Updates the Ionic Framework in www/lib/ionic'
// },
// options: {
// '--version|-v': 'Specific Ionic version\nOtherwise it defaults to the latest version'
// },
// module: './ionic/lib'
// },
// {
// title: 'setup',
// name: 'setup',
// summary: 'Configure the project with a build tool ' + '(beta)'.yellow,
// args: {
// '[sass]': 'Setup the project to use Sass CSS precompiling'
// },
// module: './ionic/setup'
// },
// {
// title: 'login',
// name: 'login',
// module: './ionic/login'
// },
// {
// title: 'address',
// name: 'address',
// module: './ionic/serve'
// },
// {
// title: 'app',
// name: 'app',
// // summary: 'Deploy a new Ionic app version or list versions',
// // options: {
// // '--versions|-v': 'List recently uploaded versions of this app',
// // '--deploy|-d': 'Upload the current working copy and mark it as deployed',
// // '--note|-n': 'Add a note to a deploy',
// // '--uuid|-u': 'Mark an already uploaded version as deployed'
// // },
// module: './ionic/app'
// },
// {
// title: 'push',
// name: 'push',
// module: './ionic/push'
// },
// {
// title: 'browser',
// name: 'browser',
// summary: 'Add another browser for a platform ' + '(beta)'.yellow,
// args: {
// '<command>': '"add remove rm versions upgrade list ls revert"',
// '[browser]': 'The browser you wish to add or remove (Crosswalk)'
// },
// module: './ionic/browser'
// },
// {
// title: 'service add',
// name: 'service',
// summary: 'Add an Ionic service package and install any required plugins',
// args: {
// '[options]': '',
// '<SPEC>': 'Can be a service name or a git url'
// },
// module: './ionic/service'
// },
// {
// title: 'add',
// name: 'add',
// summary: 'Add an Ion, bower component, or addon to the project',
// args: {
// '[name]': 'The name of the ion, bower component, or addon you wish to install'
// },
// module: './ionic/add'
// },
// {
// title: 'remove',
// name: 'remove',
// summary: 'Remove an Ion, bower component, or addon from the project',
// args: {
// '[name]': 'The name of the Ion, bower component, or addon you wish to remove'
// },
// module: './ionic/add',
// alt: ['rm']
// },
// {
// title: 'list',
// name: 'list',
// summary: 'List Ions, bower components, or addons in the project',
// module: './ionic/add',
// alt: ['ls']
// },
// {
// title: 'ions',
// name: 'ions',
// summary: 'List available ions to add to your project',
// module: './ionic/ions'
// },
// {
// title: 'templates',
// name: 'templates',
// summary: 'List available Ionic starter templates',
// module: './ionic/templates'
// },
// {
// title: 'info',
// name: 'info',
// summary: 'List information about the users runtime environment',
// module: './ionic/info'
// },
// {
// title: 'help',
// name: 'help',
// summary: 'Provides help for a certain command',
// args: {
// '[command]': 'The command you desire help with'
// },
// module: './ionic/help'
// },
// ];
// Ionic = {
// IONIC_DASH: 'https://apps.ionic.io',
// //IONIC_DASH: 'http://localhost:8000',
// IONIC_API: '/api/v1/',
// PRIVATE_PATH: '.ionic',
// _tryBuildingTask: function() {
// if(argv._.length === 0) {
// return false;
// }
// var taskName = argv._[0];
// return this._getTaskWithName(taskName);
// },
// _getTaskWithName: function(name) {
// for(var i = 0; i < TASKS.length; i++) {
// var t = TASKS[i];
// if(t.name === name) {
// return t;
// }
// if(t.alt) {
// for(var j = 0; j < t.alt.length; j++) {
// var alt = t.alt[j];
// if(alt === name) {
// return t;
// }
// }
// }
// }
// },
// printUsage: function(d) {
// var w = function(s) {
// process.stdout.write(s);
// };
// w('\n');
// var rightColumn = 41;
// var dots = '';
// var indent = '';
// var x, arg;
// var taskArgs = d.title;
// for(arg in d.args) {
// taskArgs += ' ' + arg;
// }
// w(taskArgs.green.bold);
// while( (taskArgs + dots).length < rightColumn + 1) {
// dots += '.';
// }
// w(' ' + dots.grey + ' ');
// if(d.summary) {
// w(d.summary.bold);
// }
// for(arg in d.args) {
// if( !d.args[arg] ) continue;
// indent = '';
// w('\n');
// while(indent.length < rightColumn) {
// indent += ' ';
// }
// w( (indent + ' ' + arg + ' ').bold );
// var argDescs = d.args[arg].split('\n');
// var argIndent = indent + ' ';
// for(x=0; x<arg.length + 1; x++) {
// argIndent += ' ';
// }
// for(x=0; x<argDescs.length; x++) {
// if(x===0) {
// w( argDescs[x].bold );
// } else {
// w( '\n' + argIndent + argDescs[x].bold );
// }
// }
// }
// indent = '';
// while(indent.length < d.name.length + 1) {
// indent += ' ';
// }
// var optIndent = indent;
// while(optIndent.length < rightColumn + 4) {
// optIndent += ' ';
// }
// for(var opt in d.options) {
// w('\n');
// dots = '';
// var optLine = indent + '[' + opt + '] ';
// w(optLine.yellow.bold);
// if(d.options[opt]) {
// while( (dots.length + optLine.length - 2) < rightColumn) {
// dots += '.';
// }
// w(dots.grey + ' ');
// var optDescs = d.options[opt].split('\n');
// for(x=0; x<optDescs.length; x++) {
// if(x===0) {
// w( optDescs[x].bold );
// } else {
// w( '\n' + optIndent + optDescs[x].bold );
// }
// }
// }
// }
// w('\n');
// },
// _printAvailableTasks: function() {
// this._printIonic();
// process.stderr.write('\nUsage: ionic task args\n\n=======================\n\n');
// if(process.argv.length > 2) {
// process.stderr.write( (process.argv[2] + ' is not a valid task\n\n').bold.red );
// }
// process.stderr.write('Available tasks: '.bold);
// process.stderr.write('(use --help or -h for more info)\n\n');
// for(var i = 0; i < TASKS.length; i++) {
// var task = TASKS[i];
// if(task.summary) {
// var name = ' ' + task.name + ' ';
// var dots = '';
// while((name + dots).length < 20) {
// dots += '.';
// }
// process.stderr.write(name.green.bold + dots.grey + ' ' + task.summary.bold + '\n');
// }
// }
// process.stderr.write('\n');
// this.processExit(1);
// },
// _printHelpLines: function() {
// this._printIonic();
// process.stderr.write('\n=======================\n');
// for(var i = 0; i < TASKS.length; i++) {
// var task = TASKS[i];
// if(task.summary) {
// this.printUsage(task);
// }
// }
// process.stderr.write('\n');
// this.processExit(1);
// },
// _printIonic: function() {
// var w = function(s) {
// process.stdout.write(s);
// };
// w(' _ _ \n');
// w(' (_) (_) \n');
// w(' _ ___ _ __ _ ___ \n');
// w(' | |/ _ \\| \'_ \\| |/ __|\n');
// w(' | | (_) | | | | | (__ \n');
// w(' |_|\\___/|_| |_|_|\\___| CLI v'+ settings.version + '\n');
// },
// run: function() {
// var self = this;
// console.log('argv', argv)
// self.checkLatestVersion();
// process.on('exit', function(){
// self.printVersionWarning();
// });
// if( (argv.version || argv.v) && !argv._.length) {
// return this.version();
// }
// if(argv.help || argv.h) {
// return this._printHelpLines();
// }
// if(argv['stats-opt-out']) {
// var IonicStore = require('./ionic/store').IonicStore;
// var ionicConfig = new IonicStore('ionic.config');
// ionicConfig.set('statsOptOut', true);
// ionicConfig.save();
// console.log('Successful stats opt-out');
// return;
// }
// var taskSetting = this._tryBuildingTask();
// if(!taskSetting) {
// return this._printAvailableTasks();
// }
// var taskModule = require(taskSetting.module).IonicTask;
// var taskInstance = new taskModule();
// taskInstance.run(this);//, argv);
// },
// fail: function(msg, taskHelp) {
// this.hasFailed = true;
// if(msg) {
// process.stderr.write(msg.error.bold);
// process.stderr.write( (' (CLI v' + settings.version + ')').error.bold + '\n');
// var infoChecker = new IonicInfo();
// var info = infoChecker.gatherInfo();
// infoChecker.printInfo(info);
// }
// if(taskHelp) {
// for(var i = 0; i < TASKS.length; i++) {
// var task = TASKS[i];
// if(task.name == taskHelp) {
// this.printUsage(task);
// process.stderr.write('\n');
// break;
// }
// }
// }
// process.stderr.write('\n');
// this.processExit(1);
// },
// version: function() {
// process.stderr.write(settings.version + '\n');
// },
// checkLatestVersion: function() {
// this.latestVersion = Q.defer();
// var self = this;
// try {
// if(settings.version.indexOf('beta') > -1) {
// // don't bother checking if its a beta
// self.latestVersion.resolve();
// return;
// }
// // stay silent if it errors
// var IonicStore = require('./ionic/store').IonicStore;
// var ionicConfig = new IonicStore('ionic.config');
// var versionCheck = ionicConfig.get('versionCheck');
// if(versionCheck && ((versionCheck + 86400000) > Date.now() )) {
// // we've recently checked for the latest version, so don't bother again
// self.latestVersion.resolve();
// return;
// }
// var proxy = process.env.PROXY || process.env.http_proxy || null;
// var request = require('request');
// request({ url: 'http://registry.npmjs.org/ionic/latest', proxy: proxy }, function(err, res, body) {
// try {
// self.npmVersion = JSON.parse(body).version;
// ionicConfig.set('versionCheck', Date.now());
// ionicConfig.save();
// } catch(e) {}
// self.latestVersion.resolve();
// });
// } catch(e) {
// self.latestVersion.resolve();
// }
// },
// printVersionWarning: function() {
// if(this.npmVersion && this.npmVersion != settings.version.trim()) {
// process.stdout.write('\n------------------------------------\n'.red);
// process.stdout.write('Ionic CLI is out of date:\n'.bold.yellow);
// process.stdout.write( (' * Locally installed version: ' + settings.version + '\n').yellow );
// process.stdout.write( (' * Latest version: ' + this.npmVersion + '\n').yellow );
// process.stdout.write( (' * https://github.com/driftyco/ionic-cli/blob/master/CHANGELOG.md\n').yellow );
// process.stdout.write( ' * Run '.yellow + 'npm install -g ionic'.bold + ' to update\n'.yellow );
// process.stdout.write('------------------------------------\n\n'.red);
// this.npmVersion = null;
// }
// },
// printNewsUpdates: function printNewsUpdates(skipNewsCheck) {
// if(typeof skipNewsCheck == 'undefined') {
// skipNewsCheck = true;
// }
// var q = this.cliNews = Q.defer();
// var proxy = process.env.PROXY || null;
// var IonicStore = require('./ionic/store').IonicStore;
// var ionicConfig = new IonicStore('ionic.config');
// var request = require('request');
// var monthNames = [ "January", "February", "March", "April", "May", "June",
// "July", "August", "September", "October", "November", "December" ];
// var d = new Date();
// var downloadUrl = 'http://code.ionicframework.com/content/cli-message.json';
// request({ url: downloadUrl, proxy: proxy }, function(err, res, html) {
// if(!err && res && res.statusCode === 200) {
// try {
// var newsId = ionicConfig.get('newsId');
// var messagesJson = {};
// messagesJson = JSON.parse(html);
// if(skipNewsCheck || typeof newsId == 'undefined' || newsId != messagesJson.id) {
// ionicConfig.set('newsId', messagesJson.id)
// ionicConfig.save()
// } else {
// q.resolve();
// return q.promise;
// }
// process.stdout.write('+---------------------------------------------------------+\n'.green);
// var monthMessage = ['+ New Ionic Updates for ', monthNames[d.getMonth()], ' ', d.getFullYear(), '\n+\n'].join('').green;
// process.stdout.write(monthMessage);
// for(var i = 0, j = messagesJson.list.length; i < j; i++) {
// var entry = messagesJson.list[i];
// var entryMessage = ['+ ', entry.name, '\n', '+ ', entry.action.yellow, '\n+\n'].join('');
// process.stdout.write(entryMessage);
// }
// process.stdout.write('+---------------------------------------------------------+\n'.green);
// }catch(ex) {
// console.log('ex', ex)
// q.reject('Error occured in downloading the CLI messages:', ex)
// self.ionic.fail(ex);
// q.reject(ex);
// return
// }
// q.resolve(messagesJson);
// } else {
// process.stdout.write('Unable to fetch', err, res.statusCode);
// q.reject(res);
// }
// });
// return q.promise;
// },
// processExit: function(code) {
// if(this.cliNews && this.cliNews.promise) {
// Q.all([this.latestVersion.promise, this.cliNews.promise])
// .then(function() {
// process.exit(code);
// })
// } else {
// this.latestVersion.promise.then(function() {
// process.exit(code);
// })
// }
// },
// getContentSrc: function() {
// var self = this;
// var contentSrc;
// try {
// var fs = require('fs');
// var path = require('path');
// var configXmlPath = path.resolve('config.xml');
// if( !fs.existsSync(configXmlPath) ) {
// return 'index.html';
// }
// self.setConfigXml({
// resetContent: true,
// errorWhenNotFound: false
// });
// var configString = fs.readFileSync(configXmlPath, { encoding: 'utf8' });
// var xml2js = require('xml2js');
// var parseString = xml2js.parseString;
// parseString(configString, function (err, jsonConfig) {
// if(err) {
// return self.fail('Error parsing config.xml: ' + err);
// }
// try {
// contentSrc = jsonConfig.widget.content[0].$.src;
// } catch(e) {
// return self.fail('Error parsing ' + configXmlPath + ': ' + e);
// }
// });
// } catch(e) {
// return self.fail('Error loading ' + configXmlPath + ': ' + e);
// }
// return contentSrc;
// },
// /**
// * Download a zip file, unzip it to a specific folder.
// */
// fetchArchive: function(targetPath, archiveUrl) {
// var os = require('os');
// var fs = require('fs');
// var path = require('path');
// var unzip = require('unzip');
// var q = Q.defer();
// // The folder name the project will be downloaded and extracted to
// console.log('\nDownloading:'.bold, archiveUrl);
// var tmpFolder = os.tmpdir();
// var tempZipFilePath = path.join(tmpFolder, 'ionic-starter-' + new Date().getTime() + '.zip');
// var unzipRepo = function(fileName) {
// var readStream = fs.createReadStream(fileName);
// readStream.on('error', function(err) {
// console.log( ('unzipRepo readStream: ' + err).error );
// q.reject(err);
// });
// var writeStream = unzip.Extract({ path: targetPath });
// writeStream.on('close', function() {
// q.resolve();
// });
// writeStream.on('error', function(err) {
// console.log( ('unzipRepo writeStream: ' + err).error );
// q.reject(err);
// });
// readStream.pipe(writeStream);
// };
// var proxy = process.env.PROXY || process.env.http_proxy || null;
// var request = require('request');
// request({ url: archiveUrl, rejectUnauthorized: false, encoding: null, proxy: proxy }, function(err, res, body) {
// if(err) {
// console.error('Error fetching:'.error.bold, archiveUrl, err);
// q.reject(err);
// return;
// }
// if(!res) {
// console.error('Invalid response:'.error.bold, archiveUrl);
// q.reject('Unable to fetch response: ' + archiveUrl);
// return;
// }
// if(res.statusCode !== 200) {
// if(res.statusCode === 404 || res.statusCode === 406) {
// console.error('Not found:'.error.bold, archiveUrl, '(' + res.statusCode + ')');
// console.error('Please verify the url and try again.'.error.bold);
// } else {
// console.error('Invalid response status:'.error.bold, archiveUrl, '(' + res.statusCode + ')');
// }
// q.reject(res);
// return;
// }
// try {
// fs.writeFileSync(tempZipFilePath, body);
// unzipRepo(tempZipFilePath);
// } catch(e) {
// console.log('fetchArchive request write: ' + e);
// q.reject(e);
// }
// }).on('response', function(res){
// // var ProgressBar = require('progress');
// var bar = Multibar.newBar('[:bar] :percent :etas', {
// complete: '=',
// incomplete: ' ',
// width: 30,
// total: parseInt(res.headers['content-length'], 10)
// });
// res.on('data', function (chunk) {
// try {
// bar.tick(chunk.length);
// } catch(e){}
// });
// });
// return q.promise;
// },
// setConfigXml: function(options) {
// console.log('setConfigXml')
// var fs = require('fs');
// var path = require('path');
// var xml2js = require('xml2js');
// var d = Q.defer();
// var self = this;
// var madeChange = false;
// try {
// var configXmlPath = path.resolve('config.xml');
// if(!fs.existsSync(configXmlPath)) {
// // working directory does not have the config.xml file
// if(options.errorWhenNotFound) {
// d.reject('Unable to locate config.xml file. Please ensure the working directory is at the root of the app where the config.xml should be located.');
// } else {
// d.resolve();
// }
// return d.promise;
// }
// var configString = fs.readFileSync(configXmlPath, { encoding: 'utf8' });
// var parseString = xml2js.parseString;
// parseString(configString, function (err, jsonConfig) {
// if(err) {
// d.reject(err);
// return self.fail('Error parsing ' + configXmlPath + ': ' + err);
// }
// if(!jsonConfig.widget) {
// throw new Error('\nYour config.xml file is invalid. You must have a <widget> element.');
// } else if(jsonConfig.widget && !jsonConfig.widget.content) {
// throw new Error('\nYour config.xml file does not have a <content> element. \nAdd something like: <content src="index.html"/>');
// }
// if(options.devServer) {
// if( !jsonConfig.widget.content[0].$['original-src'] ) {
// jsonConfig.widget.content[0].$['original-src'] = jsonConfig.widget.content[0].$.src;
// madeChange = true;
// }
// if(jsonConfig.widget.content[0].$.src !== options.devServer) {
// jsonConfig.widget.content[0].$.src = options.devServer;
// madeChange = true;
// }
// } else if(options.resetContent) {
// if( jsonConfig.widget.content[0].$['original-src'] ) {
// jsonConfig.widget.content[0].$.src = jsonConfig.widget.content[0].$['original-src'];
// delete jsonConfig.widget.content[0].$['original-src'];
// madeChange = true;
// }
// }
// if(madeChange) {
// var xmlBuilder = new xml2js.Builder();
// configString = xmlBuilder.buildObject(jsonConfig);
// fs.writeFileSync(configXmlPath, configString);
// }
// d.resolve();
// });
// } catch(e) {
// d.reject(e);
// self.fail('Error updating ' + configXmlPath + ': ' + e);
// }
// return d.promise;
// }
// };
// var consoleInfo = console.info;
// console.info = function() {
// if (arguments.length === 1 && !arguments[0]) return;
// var msg = '';
// for (var n in arguments) {
// msg += arguments[n] + ' ';
// }
// consoleInfo.call(console, msg.blue.bold);
// };
// var consoleError = console.error;
// console.error = function() {
// if (arguments.length === 1 && !arguments[0]) return;
// var msg = ' ✗';
// for (var n in arguments) {
// msg += ' ' + arguments[n];
// }
// consoleError.call(console, msg.red.bold);
// };
// console.success = function() {
// if (arguments.length === 1 && !arguments[0]) return;
// var msg = ' ✓';
// for (var n in arguments) {
// msg += ' ' + arguments[n];
// }
// console.log(msg.green.bold);
// };
// exports.Ionic = Ionic;