-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bundle.js
47 lines (36 loc) · 1.22 KB
/
.bundle.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
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
var BUNDLE_PATH = process.env.BUNDLE_PATH || path.join(__dirname, '.bundle');
var OUTPUT_PATH = process.env.OUTPUT_PATH || 'meteor.js';
var Bundler = {};
Bundler.gatherSources = function(callback) {
var starJson = require(path.join(BUNDLE_PATH, 'star.json'));
var program;
starJson.programs.forEach(function(_program) {
if (_program.name === 'client') {
program = _program;
return false;
}
});
var programJson = require(path.join(BUNDLE_PATH, program.path));
var programPath = path.join(BUNDLE_PATH, path.dirname(program.path));
programJson.manifest.forEach(function(pkg) {
if (pkg.type === 'js') {
var source = fs.readFileSync(path.join(programPath, pkg.path));
callback(null, source);
}
});
};
Bundler.bundle = function(distfilePath) {
fs.writeFileSync(distfilePath, '');
fs.appendFileSync(distfilePath, fs.readFileSync('.intro.js'));
Bundler.gatherSources(function(err, source) {
fs.appendFileSync(distfilePath, source);
});
fs.appendFileSync(distfilePath, fs.readFileSync('.outro.js'));
};
module.exports = Bundler;
if (!module.parent) {
Bundler.bundle(OUTPUT_PATH);
}