-
Notifications
You must be signed in to change notification settings - Fork 5
/
build
executable file
·79 lines (70 loc) · 1.71 KB
/
build
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
#!/usr/bin/env node
var opts = require('./src/cli/parse_args.js')()
.option('f', {
type: 'flag'
})
.option('m', {
type: 'flag' // minimal build
})
.parse(process.argv.slice(2));
var fs = require('fs');
var _ = require('underscore');
var path = require('path');
var ifile = opts.m ? 'src/proj-minimal.js' : 'src/proj.js';
var deps, ofile;
if (opts._.length > 0) {
deps = getRequestedDeps(opts._[0].split(','));
}
if (opts.m) {
ofile = "mproj-minimal.js";
} else if (deps) {
ofile = "mproj-custom.js";
} else {
ofile = "mproj.js";
}
if (!deps) {
deps = getAllDeps();
}
require("catty")({follow: !!opts.f})
.addLibrary("src")
.addLibrary("node_modules/geographiclib/src")
.addDeps(deps)
.cat(ifile, "dist/" + ofile);
function getRequestedDeps(projs) {
var index = {};
var deps = [];
var missing = [];
getAllDeps().forEach(function(name) {
findProjNames(name, index);
});
projs.forEach(function(proj) {
if (proj in index) {
deps.push(index[proj]);
} else {
missing.push(proj);
}
});
if (missing.length > 0) {
console.error("Missing:", missing.join(','));
process.exit(1);
}
return _.uniq(deps).join(',');
}
function getAllDeps() {
var deps = fs.readdirSync('src/projections').map(function(f) {
var match = /(.*)\.js$/.exec(f);
return match ? match[1] : null;
});
return _.compact(deps);
}
function findProjNames(fileName, index) {
var argsRx = /pj_add\(([^;]+)/g;
var trimRx = /['"\s]/g;
var filePath = path.join('src/projections', fileName + '.js');
var js = fs.readFileSync(filePath, 'utf8');
var args, m;
while (m = argsRx.exec(js)) {
args = m[1].split(',');
index[args[1].replace(trimRx, '')] = fileName;
}
}