1 | var spawn = require('child_process').spawn;
|
2 | var archiver = require('archiver');
|
3 | var fs = require('fs');
|
4 | var pathResolve = require('path').resolve;
|
5 | var _ = require('underscore');
|
6 | var ProgressBar = require('progress');
|
7 |
|
8 | module.exports = buildApp;
|
9 |
|
10 | function buildApp(appPath, buildLocaltion, buildOptions, callback) {
|
11 | buildMeteorApp(appPath, buildLocaltion, buildOptions, function(code) {
|
12 | if (code == 0) {
|
13 | archiveIt(buildLocaltion, callback);
|
14 | } else {
|
15 | console.log("\n=> Build Error. Check the logs printed above.");
|
16 | callback(new Error("build-error"));
|
17 | }
|
18 | });
|
19 | }
|
20 |
|
21 | function buildMeteorApp(appPath, buildLocaltion, buildOptions, callback) {
|
22 | var executable = "meteor";
|
23 | var args = [
|
24 | "build", "--directory", buildLocaltion,
|
25 | "--architecture", "os.linux.x86_64",
|
26 | ];
|
27 |
|
28 |
|
29 | if (buildOptions.serverOnly) {
|
30 | args.push("--server-only");
|
31 | }
|
32 |
|
33 | if (buildOptions.debug) {
|
34 | args.push("--debug");
|
35 | }
|
36 |
|
37 | if (buildOptions.mobileSettings) {
|
38 | args.push('--mobile-settings');
|
39 | args.push(JSON.stringify(buildOptions.mobileSettings));
|
40 | }
|
41 |
|
42 | console.info('[meteorup]'.magenta + ' - Meteor app path ' + appPath);
|
43 | var options = { cwd: appPath };
|
44 |
|
45 | var meteor = spawn(executable, args, options);
|
46 | var stdout = "";
|
47 | var stderr = "";
|
48 |
|
49 | meteor.stdout.pipe(process.stdout, { end: false });
|
50 | meteor.stderr.pipe(process.stderr, { end: false });
|
51 |
|
52 | meteor.on('close', callback);
|
53 | }
|
54 |
|
55 | function archiveIt(buildLocaltion, callback) {
|
56 | callback = _.once(callback);
|
57 | var bundlePath = pathResolve(buildLocaltion, 'bundle.tar.gz');
|
58 | var sourceDir = pathResolve(buildLocaltion, 'bundle');
|
59 |
|
60 |
|
61 | var output = fs.createWriteStream(bundlePath);
|
62 | var archive = archiver('tar', {
|
63 | gzip: true,
|
64 | gzipOptions: {
|
65 | level: 6,
|
66 | checkpoint: 100,
|
67 | "checkpoint-action": "dot",
|
68 | totals: true
|
69 | }
|
70 | });
|
71 |
|
72 |
|
73 | archive.on('entry', function() {
|
74 | process.stdout.cursorTo(0);
|
75 | process.stdout.write('Compressing by ' + archive.pointer() + ' bytes');
|
76 | process.stdout.clearLine(1);
|
77 | });
|
78 |
|
79 | archive.pipe(output);
|
80 |
|
81 | output.once('close', function() {
|
82 | process.stdout.clearLine();
|
83 | process.stdout.cursorTo(0);
|
84 | callback();
|
85 | });
|
86 |
|
87 | archive.once('error', function(err) {
|
88 | console.log("=> Archiving failed:", err.message);
|
89 | callback(err);
|
90 | });
|
91 | console.log('[meteorup]'.magenta + ' - Tar file path ' + sourceDir);
|
92 | archive.directory(sourceDir, 'bundle').finalize();
|
93 | }
|