forked from frozeman/meteor-build-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·80 lines (65 loc) · 2.72 KB
/
main.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
#!/usr/bin/env node
var fs = require('fs');
// CLI Options
var program = require('commander');
var Q = require('bluebird');
var packageJson = require('./package.json');
// VARIABLES
var argPath = process.argv[2];
var meteor = require('./meteor.js');
program
.version(packageJson.version)
.usage('<output path> [options]')
.option('-p, --path <path>', 'The path used to link the files, default is "/", pass "" to link relative to the index.html.')
.option('-t, --template <file path>', 'Provide a custom index.html template. Use {{> head}}, {{> css}} and {{> scripts}} to place the meteor resources.')
.option('-s, --settings <settings.json>', 'Set optional data for Meteor.settings in your application.')
.option('-u, --url <url>', 'The Root URL of your app. If "default", Meteor will try to connect to the Server where it was served from. Default is: "" (empty string)')
.option('-D, --debug', 'Build in debug mode (don\'t minify, etc)')
.option('-v, --verbose', 'Add optional verbose option.');
// .option('-d, --ddp <url>', 'The URL of your Meteor DDP server, e.g. "ddp+sockjs://ddp.myapp.com/sockjs". If you don\'t add any it will also add call "Meteor.disconnect();" to prevent the app from conneting.');
program.on('--help', function(){
console.log(' Warning:');
console.log('');
console.log(' The content of the output folder will be deleted before building the new output!');
console.log(' Don\'t do something like: meteor-build-client /home !');
console.log('');
});
program.parse(process.argv);
Q.try(function() {
if (!argPath) {
throw new Error("You need to provide a path for the build output, for example:\n\n$ meteor-build-client myBuildFolder");
}
if (!fs.lstatSync('./.meteor').isDirectory()) {
throw new Error('You\'re not in a Meteor app folder or inside a sub folder of your app.');
}
if(program.template && !fs.lstatSync(program.template).isFile()) {
throw new Error('The template file "'+ program.template +'" doesn\'t exist or is not a valid template file');
}
})
.then(function() {
console.log('Bundling Meteor app...');
return meteor.build(program);
})
.then(function() {
console.log('Generating the index.html...');
return meteor.move();
})
.then(function() {
return meteor.addIndexFile(program);
})
.then(function() {
return meteor.cleanUp();
})
.then(function() {
console.log('Done!');
console.log('-----');
console.log('You can find your files in "'+ require('path').resolve(argPath) +'".');
})
.catch(function(err) {
if (err.stderr || err.stdout) {
console.error(err.stdout, err.stderr);
} else {
console.error(err);
}
process.exit(-1);
});