forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
1819 lines (1597 loc) · 57.9 KB
/
commands.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
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var main = require('./main.js');
var path = require('path');
var _ = require('underscore');
var fs = require('fs');
var files = require('./files.js');
var deploy = require('./deploy.js');
var buildmessage = require('./buildmessage.js');
var project = require('./project.js').project;
var warehouse = require('./warehouse.js');
var auth = require('./auth.js');
var config = require('./config.js');
var release = require('./release.js');
var Future = require('fibers/future');
var runLog = require('./run-log.js');
var packageClient = require('./package-client.js');
var utils = require('./utils.js');
var httpHelpers = require('./http-helpers.js');
var archinfo = require('./archinfo.js');
var tropohouse = require('./tropohouse.js');
var compiler = require('./compiler.js');
var catalog = require('./catalog.js');
var stats = require('./stats.js');
var unipackage = require('./unipackage.js');
var cordova = require('./commands-cordova.js');
var commandsPackages = require('./commands-packages.js');
var execFileSync = require('./utils.js').execFileSync;
var Console = require('./console.js').Console;
// The architecture used by Galaxy servers; it's the architecture used
// by 'meteor deploy'.
var DEPLOY_ARCH = 'os.linux.x86_64';
// The default host to use when building apps. (Specifically, for mobile
// builds, we need a host to use for DDP_DEFAULT_CONNECTION_URL if the
// user doesn't specify one with -p or --mobile-port).
var DEFAULT_BUILD_HOST = "localhost";
// Given a site name passed on the command line (eg, 'mysite'), return
// a fully-qualified hostname ('mysite.meteor.com').
//
// This is fairly simple for now. It appends 'meteor.com' if the name
// doesn't contain a dot, and it deletes any trailing dots (the
// technically legal hostname 'mysite.com.' is canonicalized to
// 'mysite.com').
//
// In the future, you should be able to make this default to some
// other domain you control, rather than 'meteor.com'.
var qualifySitename = function (site) {
if (site.indexOf(".") === -1)
site = site + ".meteor.com";
while (site.length && site[site.length - 1] === ".")
site = site.substring(0, site.length - 1);
return site;
};
// Given a (non necessarily fully qualified) site name from the
// command line, return true if the site is hosted by a Galaxy, else
// false.
var hostedWithGalaxy = function (site) {
var site = qualifySitename(site);
return !! require('./deploy-galaxy.js').discoverGalaxy(site);
};
var parseHostPort = function (str) {
// XXX factor this out into a {type: host/port}?
var portMatch = str.match(/^(?:(.+):)?([0-9]+)$/);
if (!portMatch) {
throw new Error(
"run: --port (-p) must be a number or be of the form 'host:port' where\n" +
"port is a number. Try 'meteor help run' for help.\n");
}
var host = portMatch[1];
var port = parseInt(portMatch[2]);
return {
host: host,
port: port
};
};
///////////////////////////////////////////////////////////////////////////////
// options that act like commands
///////////////////////////////////////////////////////////////////////////////
// Prints the Meteor architecture name of this host
main.registerCommand({
name: '--arch',
requiresRelease: false
}, function (options) {
var archinfo = require('./archinfo.js');
console.log(archinfo.host());
});
// Prints the current release in use. Note that if there is not
// actually a specific release, we print to stderr and exit non-zero,
// while if there is a release we print to stdout and exit zero
// (making this useful to scripts).
// XXX: What does this mean in our new release-free world?
main.registerCommand({
name: '--version',
requiresRelease: false
}, function (options) {
if (release.current === null) {
if (! options.appDir)
throw new Error("missing release, but not in an app?");
Console.stderr.write(
"This project was created with a checkout of Meteor, rather than an\n" +
"official release, and doesn't have a release number associated with\n" +
"it. You can set its release with 'meteor update'.\n");
return 1;
}
if (release.current.isCheckout()) {
Console.stderr.write("Unreleased (running from a checkout)\n");
return 1;
}
console.log(release.current.getDisplayName());
});
// Internal use only. For automated testing.
main.registerCommand({
name: '--long-version',
requiresRelease: false
}, function (options) {
if (files.inCheckout()) {
Console.stderr.write("checkout\n");
return 1;
} else if (release.current === null) {
// .meteor/release says "none" but not in a checkout.
Console.stderr.write("none\n");
return 1;
} else {
Console.stdout.write(release.current.name + "\n");
Console.stdout.write(files.getToolsVersion() + "\n");
return 0;
}
});
// Internal use only. For automated testing.
main.registerCommand({
name: '--requires-release',
requiresRelease: true
}, function (options) {
return 0;
});
///////////////////////////////////////////////////////////////////////////////
// run
///////////////////////////////////////////////////////////////////////////////
main.registerCommand({
name: 'run',
pretty: true,
requiresApp: true,
maxArgs: Infinity,
options: {
port: { type: String, short: "p", default: '3000' },
'mobile-port': { type: String },
'app-port': { type: String },
'http-proxy-port': { type: String },
production: { type: Boolean },
'raw-logs': { type: Boolean },
settings: { type: String },
program: { type: String },
verbose: { type: Boolean, short: "v" },
// With --once, meteor does not re-run the project if it crashes
// and does not monitor for file changes. Intentionally
// undocumented: intended for automated testing (eg, cli-test.sh),
// not end-user use. #Once
once: { type: Boolean },
// With --clean, meteor cleans the application directory and uses the
// bundled assets only. Encapsulates the behavior of once (does not rerun)
// and does not monitor for file changes. Not for end-user use.
clean: { type: Boolean}
}
}, function (options) {
// Calculate project versions. (XXX: Theoretically, we should not be doing it
// here. We should do it lazily, if the command calls for it. However, we do
// end up recalculating them for stats, for example, and, more importantly, we
// have noticed some issues if we just leave this in the air. We think that
// those issues are concurrency-related, or possibly some weird
// order-of-execution of interaction that we are failing to understand. This
// seems to fix it in a clear and understandable fashion.)
var messages = buildmessage.capture(function () {
project.getVersions(); // #StructuredProjectInitialization
});
if (messages.hasMessages()) {
Console.stderr.write(messages.formatMessages());
return 1;
}
cordova.setVerboseness(options.verbose);
cordova.verboseLog('Parsing the --port option');
try {
var parsedHostPort = parseHostPort(options.port);
} catch (err) {
if (options.verbose) {
Console.stderr.write('Error while parsing --port option: '
+ err.stack + '\n');
} else {
Console.stderr.write(err.message + '\n');
}
return 1;
}
var mobilePort = options["mobile-port"] || options.port;
try {
var parsedMobileHostPort = parseHostPort(mobilePort);
} catch (err) {
if (options.verbose) {
process.stderr.write('Error while parsing --mobile-port option: '
+ err.stack + '\n');
} else {
process.stderr.write(err.message + '\n');
}
return 1;
}
parsedMobileHostPort.host = parsedMobileHostPort.host || DEFAULT_BUILD_HOST;
options.httpProxyPort = options['http-proxy-port'];
// If we are targeting the remote devices
if (_.intersection(options.args, ['ios-device', 'android-device']).length) {
cordova.verboseLog('A run on a device requested');
// ... and if you didn't specify your ip address as host, print a warning
if (parsedMobileHostPort.host === DEFAULT_BUILD_HOST)
Console.stderr.write(
"WARN: You are testing your app on a remote device but your host option\n" +
"WARN: is set to 'localhost'. Perhaps you want to change it to your local\n" +
"WARN: network's IP address with the -p or --mobile-port option?\n");
}
// Always bundle for the browser by default.
var webArchs = project.getWebArchs();
var runners = [];
// If additional args were specified, then also start a mobile build.
if (options.args.length) {
// will asynchronously start mobile emulators/devices
try {
// --clean encapsulates the behavior of once
if (options.clean) {
options.once = true;
}
// For this release; we won't force-enable the httpProxy
if (false) { //!options.httpProxyPort) {
console.log('Forcing http proxy on port 3002 for mobile');
options.httpProxyPort = '3002';
}
cordova.verboseLog('Will compile mobile builds');
var appName = path.basename(options.appDir);
var localPath = path.join(options.appDir, '.meteor', 'local');
cordova.buildPlatforms(localPath, options.args,
_.extend({ appName: appName, debug: ! options.production },
options, parsedMobileHostPort));
runners = runners.concat(cordova.buildPlatformRunners(localPath, options.args, options));
} catch (err) {
if (options.verbose) {
Console.stderr.write('Error while running for mobile platforms ' +
err.stack + '\n');
} else {
Console.stderr.write(err.message + '\n');
}
return 1;
}
}
var appHost, appPort;
if (options['app-port']) {
var appPortMatch = options['app-port'].match(/^(?:(.+):)?([0-9]+)?$/);
if (!appPortMatch) {
Console.stderr.write(
"run: --app-port must be a number or be of the form 'host:port' where\n" +
"port is a number. Try 'meteor help run' for help.\n");
return 1;
}
appHost = appPortMatch[1] || null;
// It's legit to specify `--app-port host:` and still let the port be
// randomized.
appPort = appPortMatch[2] ? parseInt(appPortMatch[2]) : null;
}
if (release.forced) {
var appRelease = project.getMeteorReleaseVersion();
if (release.current.name !== appRelease) {
console.log("=> Using Meteor %s as requested (overriding Meteor %s)",
release.current.name, appRelease);
console.log();
}
}
auth.tryRevokeOldTokens({timeout: 1000});
if (options['raw-logs'])
runLog.setRawLogs(true);
var runAll = require('./run-all.js');
return runAll.run(options.appDir, {
proxyPort: parsedHostPort.port,
proxyHost: parsedHostPort.host,
httpProxyPort: options.httpProxyPort,
appPort: appPort,
appHost: appHost,
settingsFile: options.settings,
program: options.program || undefined,
buildOptions: {
minify: options.production,
webArchs: webArchs
},
rootUrl: process.env.ROOT_URL,
mongoUrl: process.env.MONGO_URL,
oplogUrl: process.env.MONGO_OPLOG_URL,
once: options.once,
extraRunners: runners
});
});
///////////////////////////////////////////////////////////////////////////////
// create
///////////////////////////////////////////////////////////////////////////////
main.registerCommand({
name: 'create',
maxArgs: 1,
options: {
list: { type: Boolean },
example: { type: String },
package: { type: Boolean }
},
pretty: true
}, function (options) {
// Creating a package is much easier than creating an app, so if that's what
// we are doing, do that first. (For example, we don't springboard to the
// latest release to create a package if we are inside an app)
if (options.package) {
var packageName = options.args[0];
// No package examples exist yet.
if (options.list && options.example) {
Console.stderr.write("No package examples exist at this time.\n\n");
throw new main.ShowUsage;
}
if (!packageName) {
Console.stderr.write("Please specify the name of the package. \n");
throw new main.ShowUsage;
}
utils.validatePackageNameOrExit(
packageName, {detailedColonExplanation: true});
var packageDir = options.appDir
? path.resolve(options.appDir, 'packages', packageName)
: path.resolve(packageName);
var inYourApp = options.appDir ? " in your app" : "";
if (fs.existsSync(packageDir)) {
Console.stderr.write(packageName + ": Already exists" + inYourApp + "\n");
return 1;
}
var transform = function (x) {
var xn = x.replace(/~name~/g, packageName);
// If we are running from checkout, comment out the line sourcing packages
// from a release, with the latest release filled in (in case they do want
// to publish later). If we are NOT running from checkout, fill it out
// with the current release.
var relString;
if (release.current.isCheckout()) {
xn = xn.replace(/~cc~/g, "//");
var rel = commandsPackages.doOrDie(function () {
return catalog.official.getDefaultReleaseVersion();
});
var relString = rel.track + "@" + rel.version;
} else {
xn = xn.replace(/~cc~/g, "");
relString = release.current.name;
}
// If we are not in checkout, write the current release here.
return xn.replace(/~release~/g, relString);
};
try {
files.cp_r(path.join(__dirname, 'skel-pack'), packageDir, {
transformFilename: function (f) {
return transform(f);
},
transformContents: function (contents, f) {
if ((/(\.html|\.js|\.css)/).test(f))
return new Buffer(transform(contents.toString()));
else
return contents;
},
ignore: [/^local$/]
});
} catch (err) {
Console.stderr.write("Could not create package: " + err.message + "\n");
return 1;
}
Console.stdout.write(packageName + ": created" + inYourApp + "\n");
return 0;
}
// Suppose you have an app A, and from some directory inside that
// app, you run 'meteor create /my/new/app'. The new app should use
// the latest available Meteor release, not the release that A
// uses. So if we were run from inside an app directory, and the
// user didn't force a release with --release, we need to
// springboard to the correct release and tools version.
//
// (In particular, it's not sufficient to create the new app with
// this version of the tools, and then stamp on the correct release
// at the end.)
if (! release.current.isCheckout() && !release.forced) {
var needToSpringboard = commandsPackages.doOrDie(function () {
return release.current.name !== release.latestDownloaded();
});
if (needToSpringboard)
throw new main.SpringboardToLatestRelease;
}
var exampleDir = path.join(__dirname, '..', 'examples');
var examples = _.reject(fs.readdirSync(exampleDir), function (e) {
return (e === 'unfinished' || e === 'other' || e[0] === '.');
});
if (options.list) {
Console.stdout.write("Available examples:\n");
_.each(examples, function (e) {
Console.stdout.write(" " + e + "\n");
});
Console.stdout.write("\n" +
"Create a project from an example with 'meteor create --example <name>'.\n");
return 0;
};
var appPath;
if (options.args.length === 1)
appPath = options.args[0];
else if (options.example)
appPath = options.example;
else
throw new main.ShowUsage;
if (fs.existsSync(appPath)) {
Console.stderr.write(appPath + ": Already exists\n");
return 1;
}
if (files.findAppDir(appPath)) {
Console.stderr.write(
"You can't create a Meteor project inside another Meteor project.\n");
return 1;
}
var transform = function (x) {
return x.replace(/~name~/g, path.basename(appPath));
};
if (options.example) {
if (examples.indexOf(options.example) === -1) {
Console.stderr.write(options.example + ": no such example\n\n");
Console.stderr.write("List available applications with 'meteor create --list'.\n");
return 1;
} else {
files.cp_r(path.join(exampleDir, options.example), appPath, {
// We try not to check the project ID into git, but it might still
// accidentally exist and get added (if running from checkout, for
// example). To be on the safe side, explicitly remove the project ID
// from example apps.
ignore: [/^local$/, /^\.id$/]
});
}
} else {
files.cp_r(path.join(__dirname, 'skel'), appPath, {
transformFilename: function (f) {
return transform(f);
},
transformContents: function (contents, f) {
if ((/(\.html|\.js|\.css)/).test(f))
return new Buffer(transform(contents.toString()));
else
return contents;
},
ignore: [/^local$/, /^\.id$/]
});
}
// We are actually working with a new meteor project at this point, so
// reorient its path. We might do some things to it, but they should be
// invisible to the user, so mute non-error output.
project.setRootDir(path.resolve(appPath));
project.setMuted(true);
project.writeMeteorReleaseVersion(
release.current.isCheckout() ? "none" : release.current.name);
// Any upgrader that is in this version of Meteor doesn't need to be run on
// this project.
var upgraders = require('./upgraders.js');
_.each(upgraders.allUpgraders(), function (upgrader) {
project.appendFinishedUpgrader(upgrader);
});
var messages = buildmessage.capture({ title: "Updating dependencies" }, function () {
// Run the constraint solver. Override the assumption that using '--release'
// means we shouldn't update .meteor/versions.
project._ensureDepsUpToDate({alwaysRecord: true});
});
if (messages.hasMessages()) {
Console.stderr.write(messages.formatMessages());
return 1;
}
{
var message = appPath + ": created";
if (options.example && options.example !== appPath)
message += (" (from '" + options.example + "' template)");
message += ".\n";
Console.info(message);
}
Console.stdout.write(
"To run your new app:\n" +
" cd " + appPath + "\n" +
" meteor\n");
});
///////////////////////////////////////////////////////////////////////////////
// run-upgrader
///////////////////////////////////////////////////////////////////////////////
main.registerCommand({
name: 'run-upgrader',
hidden: true,
minArgs: 1,
maxArgs: 1,
requiresApp: true
}, function (options) {
var upgrader = options.args[0];
var upgraders = require("./upgraders.js");
console.log("%s: running upgrader %s.",
path.basename(options.appDir), upgrader);
upgraders.runUpgrader(upgrader);
});
///////////////////////////////////////////////////////////////////////////////
// build
///////////////////////////////////////////////////////////////////////////////
var buildCommands = {
minArgs: 1,
maxArgs: 1,
requiresApp: true,
options: {
debug: { type: Boolean },
directory: { type: Boolean },
architecture: { type: String },
port: { type: String, short: "p", default: DEFAULT_BUILD_HOST + ":3000" },
settings: { type: String },
verbose: { type: Boolean, short: "v" },
// Undocumented
'for-deploy': { type: Boolean }
}
};
main.registerCommand(_.extend({ name: 'build' }, buildCommands),
function (options) {
cordova.setVerboseness(options.verbose);
// XXX output, to stderr, the name of the file written to (for human
// comfort, especially since we might change the name)
// XXX name the root directory in the bundle based on the basename
// of the file, not a constant 'bundle' (a bit obnoxious for
// machines, but worth it for humans)
// Error handling for options.architecture. We must pass in only one of three
// architectures. See archinfo.js for more information on what the
// architectures are, what they mean, et cetera.
var VALID_ARCHITECTURES =
["os.osx.x86_64", "os.linux.x86_64", "os.linux.x86_32"];
if (options.architecture &&
_.indexOf(VALID_ARCHITECTURES, options.architecture) === -1) {
Console.stderr.write("Invalid architecture: " + options.architecture + "\n");
Console.stderr.write(
"Please use one of the following: " + VALID_ARCHITECTURES + "\n");
return 1;
}
var bundleArch = options.architecture || archinfo.host();
var webArchs = project.getWebArchs();
var localPath = path.join(options.appDir, '.meteor', 'local');
var mobilePlatforms = project.getCordovaPlatforms();
var appName = path.basename(options.appDir);
if (! _.isEmpty(mobilePlatforms)) {
try {
var parsedHostPort = parseHostPort(options.port);
} catch (err) {
Console.stderr.write(err.message);
return 1;
}
// For Cordova builds, if a host isn't specified, use localhost, but
// warn about it.
var cordovaBuildHost = parsedHostPort.host || DEFAULT_BUILD_HOST;
if (cordovaBuildHost === DEFAULT_BUILD_HOST) {
process.stdout.write("WARNING: Building your app with host: localhost.\n" +
"Pass a -p argument to specify a host URL.\n");
}
var cordovaSettings = {};
cordova.buildPlatforms(localPath, mobilePlatforms,
_.extend({}, options, {
host: cordovaBuildHost,
port: parsedHostPort.port,
appName: appName
}));
}
var buildDir = path.join(localPath, 'build_tar');
var outputPath = path.resolve(options.args[0]); // get absolute path
var bundlePath = options['directory'] ?
path.join(outputPath, 'bundle') : path.join(buildDir, 'bundle');
var loader;
var messages = buildmessage.capture(function () {
loader = project.getPackageLoader();
});
if (messages.hasMessages()) {
Console.stderr.write("Errors prevented bundling your app:\n");
Console.stderr.write(messages.formatMessages());
return 1;
}
var statsMessages = buildmessage.capture(function () {
stats.recordPackages("sdk.bundle");
});
if (statsMessages.hasMessages()) {
Console.stdout.write("Error recording package list:\n" +
statsMessages.formatMessages());
// ... but continue;
}
var bundler = require(path.join(__dirname, 'bundler.js'));
var bundleResult = bundler.bundle({
outputPath: bundlePath,
buildOptions: {
minify: ! options.debug,
// XXX is this a good idea, or should linux be the default since
// that's where most people are deploying
// default? i guess the problem with using DEPLOY_ARCH as default
// is then 'meteor bundle' with no args fails if you have any local
// packages with binary npm dependencies
serverArch: bundleArch,
webArchs: webArchs
}
});
if (bundleResult.errors) {
Console.stderr.write("Errors prevented bundling:\n");
Console.stderr.write(bundleResult.errors.formatMessages());
return 1;
}
files.mkdir_p(outputPath);
if (!options['directory']) {
try {
var outputTar = path.join(outputPath, appName + '.tar.gz');
files.createTarball(path.join(buildDir, 'bundle'), outputTar);
} catch (err) {
console.log(JSON.stringify(err));
Console.stderr.write("Couldn't create tarball\n");
}
}
// Copy over the Cordova builds AFTER we bundle so that they are not included
// in the main bundle.
_.each(mobilePlatforms, function (platformName) {
var buildPath = path.join(localPath, 'cordova-build',
'platforms', platformName);
var platformPath = path.join(outputPath, platformName);
files.cp_r(buildPath, platformPath);
});
files.rm_recursive(buildDir);
});
// Deprecated -- identical functionality to 'build'
main.registerCommand(_.extend({ name: 'bundle', hidden: true }, buildCommands),
function (options) {
cordova.setVerboseness(options.verbose);
Console.stdout.write("WARNING: 'bundle' has been deprecated. " +
"Use 'build' instead.\n");
// XXX if they pass a file that doesn't end in .tar.gz or .tgz, add
// the former for them
// XXX output, to stderr, the name of the file written to (for human
// comfort, especially since we might change the name)
// XXX name the root directory in the bundle based on the basename
// of the file, not a constant 'bundle' (a bit obnoxious for
// machines, but worth it for humans)
// Error handling for options.architecture. We must pass in only one of three
// architectures. See archinfo.js for more information on what the
// architectures are, what they mean, et cetera.
var VALID_ARCHITECTURES =
["os.osx.x86_64", "os.linux.x86_64", "os.linux.x86_32"];
if (options.architecture &&
_.indexOf(VALID_ARCHITECTURES, options.architecture) === -1) {
Console.stderr.write("Invalid architecture: " + options.architecture + "\n");
Console.stderr.write(
"Please use one of the following: " + VALID_ARCHITECTURES + "\n");
return 1;
}
var bundleArch = options.architecture || archinfo.host();
var buildDir = path.join(options.appDir, '.meteor', 'local', 'build_tar');
var outputPath = path.resolve(options.args[0]); // get absolute path
var bundlePath = options['directory'] ?
outputPath : path.join(buildDir, 'bundle');
var loader;
var messages = buildmessage.capture(function () {
loader = project.getPackageLoader();
});
if (messages.hasMessages()) {
Console.stderr.write("Errors prevented bundling your app:\n");
Console.stderr.write(messages.formatMessages());
return 1;
}
var statsMessages = buildmessage.capture(function () {
stats.recordPackages("sdk.bundle");
});
if (statsMessages.hasMessages()) {
Console.stdout.write("Error recording package list:\n" +
statsMessages.formatMessages());
// ... but continue;
}
var bundler = require(path.join(__dirname, 'bundler.js'));
var bundleResult = bundler.bundle({
outputPath: bundlePath,
buildOptions: {
minify: ! options.debug,
// XXX is this a good idea, or should linux be the default since
// that's where most people are deploying
// default? i guess the problem with using DEPLOY_ARCH as default
// is then 'meteor bundle' with no args fails if you have any local
// packages with binary npm dependencies
serverArch: bundleArch
}
});
if (bundleResult.errors) {
Console.stderr.write("Errors prevented bundling:\n");
Console.stderr.write(bundleResult.errors.formatMessages());
return 1;
}
if (!options['directory']) {
try {
files.createTarball(path.join(buildDir, 'bundle'), outputPath);
} catch (err) {
console.log(JSON.stringify(err));
Console.stderr.write("Couldn't create tarball\n");
}
}
files.rm_recursive(buildDir);
});
///////////////////////////////////////////////////////////////////////////////
// mongo
///////////////////////////////////////////////////////////////////////////////
main.registerCommand({
name: 'mongo',
maxArgs: 1,
options: {
url: { type: Boolean, short: 'U' }
},
requiresApp: function (options) {
return options.args.length === 0;
}
}, function (options) {
var mongoUrl;
var usedMeteorAccount = false;
if (options.args.length === 0) {
// localhost mode
var findMongoPort =
require('./run-mongo.js').findMongoPort;
var mongoPort = findMongoPort(options.appDir);
// XXX detect the case where Meteor is running, but MONGO_URL was
// specified?
if (! mongoPort) {
Console.stdout.write(
"mongo: Meteor isn't running a local MongoDB server.\n" +
"\n" +
"This command only works while Meteor is running your application\n" +
"locally. Start your application first. (This error will also occur if\n" +
"you asked Meteor to use a different MongoDB server with $MONGO_URL when\n" +
"you ran your application.)\n" +
"\n" +
"If you're trying to connect to the database of an app you deployed\n" +
"with 'meteor deploy', specify your site's name with this command.\n"
);
return 1;
}
mongoUrl = "mongodb://127.0.0.1:" + mongoPort + "/meteor";
} else {
// remote mode
var site = qualifySitename(options.args[0]);
config.printUniverseBanner();
if (hostedWithGalaxy(site)) {
var deployGalaxy = require('./deploy-galaxy.js');
mongoUrl = deployGalaxy.temporaryMongoUrl(site);
} else {
mongoUrl = deploy.temporaryMongoUrl(site);
usedMeteorAccount = true;
}
if (! mongoUrl)
// temporaryMongoUrl() will have printed an error message
return 1;
}
if (options.url) {
console.log(mongoUrl);
} else {
if (usedMeteorAccount)
auth.maybePrintRegistrationLink();
process.stdin.pause();
var runMongo = require('./run-mongo.js');
runMongo.runMongoShell(mongoUrl);
throw new main.WaitForExit;
}
});
///////////////////////////////////////////////////////////////////////////////
// reset
///////////////////////////////////////////////////////////////////////////////
main.registerCommand({
name: 'reset',
// Doesn't actually take an argument, but we want to print an custom
// error message if they try to pass one.
maxArgs: 1,
requiresApp: true
}, function (options) {
if (options.args.length !== 0) {
Console.stderr.write(
"meteor reset only affects the locally stored database.\n" +
"\n" +
"To reset a deployed application use\n" +
" meteor deploy --delete appname\n" +
"followed by\n" +
" meteor deploy appname\n");
return 1;
}
// XXX detect the case where Meteor is running the app, but
// MONGO_URL was set, so we don't see a Mongo process
var findMongoPort =
require(path.join(__dirname, 'run-mongo.js')).findMongoPort;
var isRunning = !! findMongoPort(options.appDir);
if (isRunning) {
Console.stderr.write(
"reset: Meteor is running.\n" +
"\n" +
"This command does not work while Meteor is running your application.\n" +
"Exit the running Meteor development server.\n");
return 1;
}
var localDir = path.join(options.appDir, '.meteor', 'local');
files.rm_recursive(localDir);
Console.stdout.write("Project reset.\n");
});
///////////////////////////////////////////////////////////////////////////////
// deploy
///////////////////////////////////////////////////////////////////////////////
main.registerCommand({
name: 'deploy',
pretty: true,
minArgs: 1,
maxArgs: 1,
options: {
'delete': { type: Boolean, short: 'D' },
debug: { type: Boolean },
settings: { type: String },
star: { type: String },
// No longer supported, but we still parse it out so that we can
// print a custom error message.
password: { type: String },
// Shouldn't be documented until the Galaxy release. Marks the
// application as an admin app, so that it will be available in
// Galaxy admin interface.
admin: { type: Boolean },
// Override architecture to deploy whatever stuff we have locally, even if
// it contains binary packages that should be incompatible. A hack to allow
// people to deploy from checkout or do other weird shit. We are not
// responsible for the consequences.
'override-architecture-with-local' : { type: Boolean }
},
requiresApp: function (options) {
return options.delete || options.star ? false : true;
}
}, function (options) {
var site = qualifySitename(options.args[0]);
config.printUniverseBanner();
var useGalaxy = hostedWithGalaxy(site);
var deployGalaxy;
if (options.delete) {
if (useGalaxy) {
deployGalaxy = require('./deploy-galaxy.js');
return deployGalaxy.deleteApp(site);
} else {
return deploy.deleteApp(site);
}
}
// We are actually going to end up compiling an app at this point, so figure
// out its versions. . (XXX: Theoretically, we should not be doing it here. We
// should do it lazily, if the command calls for it. However, we do end up
// recalculating them for stats, for example, and, more importantly, we have
// noticed some issues if we just leave this in the air. We think that those
// issues are concurrency-related, or possibly some weird order-of-execution
// of interaction that we are failing to understand. This seems to fix it in a
// clear and understandable fashion.)
var messages = buildmessage.capture({ title: "Resolving versions" }, function () {
project.getVersions(); // #StructuredProjectInitialization
});
if (messages.hasMessages()) {
Console.stderr.write(messages.formatMessages());
return 1;
}
if (options.password) {
if (useGalaxy) {
Console.stderr.write("Galaxy does not support --password.\n");
} else {
Console.stderr.write(
"Setting passwords on apps is no longer supported. Now there are\n" +
"user accounts and your apps are associated with your account so that\n" +
"only you (and people you designate) can access them. See the\n" +
"'meteor claim' and 'meteor authorized' commands.\n");
}
return 1;
}
var starball = options.star;
if (starball && ! useGalaxy) {
// XXX it would be nice to support this for non-Galaxy deploys too
Console.stderr.write(
"--star: only supported when deploying to Galaxy.\n");
return 1;
}
var loggedIn = auth.isLoggedIn();
if (! loggedIn) {
Console.stderr.write(
"To instantly deploy your app on a free testing server, just enter your\n" +
"email address!\n" +
"\n");
if (! auth.registerOrLogIn())
return 1;
}
// Override architecture iff applicable.
var buildArch = DEPLOY_ARCH;
if (options['override-architecture-with-local']) {
Console.stdout.write(
"\n => WARNING: OVERRIDING DEPLOY ARCHITECTURE WITH LOCAL ARCHITECTURE\n");
Console.stdout.write(
" => If your app contains binary code, it may break terribly and you will be sad.\n\n");