-
Notifications
You must be signed in to change notification settings - Fork 67
/
main.js
executable file
·105 lines (90 loc) · 3.79 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
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
#!/usr/bin/env node
const { print } = require('./helpers.js');
const fs = require('fs-extra');
const pathLib = require('path');
// CLI Options
const program = require('commander');
const prompt = require('prompt');
const Q = require('bluebird');
const packageJson = require('./package.json');
// VARIABLES
const argPath = process.argv[2];
const 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('-y, --yci', 'Accept all questions and skip all warnings, use in CI/CD environments')
.option('-b, --usebuild <path>', 'If this flag is present, meteor-build-client will skip the `meteor build` step and opt for using your manually built <path> or ../build folder by default.', false)
.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(){
print(' Warning: \r\n');
print(' The content of the output folder will be deleted before building the new output!');
print(' Don\'t do something like: meteor-build-client /home !\r\n');
});
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() {
if (!program.yci) {
prompt.start();
return prompt.get({
properties: {
action: {
type: 'string',
description: `The content of the output folder (${process.argv[2]}) will be deleted! Y/n`,
message: 'Y or n',
default: 'n',
required: true
}
}
});
}
return { action: 'Y' };
}).then(function(result) {
if (result.action === 'Y') {
/**
* Allow the user to decide whether or not they want to use the
* meteor-build-client build or their own
*/
if(program.usebuild && fs.lstatSync(program.usebuild).isDirectory()) {
print(`Using ${program.usebuild}`);
print('Generating the index.html...');
return meteor.move(pathLib.resolve(program.usebuild));
}
print('Bundling Meteor app...');
return meteor.build(program).then(function() {
print('Generating the index.html...');
return meteor.move(pathLib.resolve(argPath));
});
}
throw new Error('Cancelled');
}).then(function() {
return meteor.addIndexFile(program);
}).then(function() {
return meteor.cleanUp(program);
}).then(function() {
print('Done!');
print('-----');
print(`You can find webapp files in "${pathLib.resolve(argPath)}".`);
}).catch(function(err) {
if (err.stderr || err.stdout) {
print('CAUGHT ERRORS:', err.stdout, err.stderr);
} else {
print('CAUGHT ERROR:', err);
}
process.exit(-1);
});