Newer
Older
Lloyd Hilaiel
committed
#!/usr/bin/env node
var
path = require('path')
resources = require('../lib/static_resources.js'),
config = require('../lib/configuration.js'),
i18n = require('../lib/i18n'),
mkdirp = require('mkdirp'),
computecluster = require('compute-cluster');
const staticPath = path.join(__dirname, '..', 'resources', 'static');
var langs = config.get('supported_languages');
Lloyd Hilaiel
committed
// remove the "debug" language.
var i = langs.indexOf(config.get('debug_lang'));
if (i != -1) langs.splice(i, 1);
Lloyd Hilaiel
committed
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
var all = resources.all(langs);
var cc = new computecluster({
module: path.join(__dirname, 'compress-worker.js'),
max_backlog: -1
});
// first and foremost we'll "generate templates" - which is to concatenate
// a bunch of ejs into a javascript file
// NOTE: env setting could be cleaned up here, this is like this to minimally
// change things during migration of compress{,-locales}.sh to javascript
process.env['BUILD_DIR'] = path.join(staticPath, "build");
mkdirp.sync(process.env['BUILD_DIR']);
process.env['TEMPLATE_DIR'] = path.join(staticPath, "dialog", "views");
require('./create_templates.js')();
var leftToBuild = Object.keys(all).length;
var errors = 0;
Object.keys(all).forEach(function(resource) {
// in dev, '/shared/templates.js' creates an empty object and templates
// are fetched on demand.
// in prod '/build/templates.js' has all templates glommed into it,
// and is bundled into the Big Minified Piles Of Resources we ship.
// Here we sub the former with the latter.
var ix = all[resource].indexOf('/shared/templates.js');
if (ix != -1) all[resource].splice(ix, 1, '/build/templates.js');
cc.enqueue({
file: resource,
deps: all[resource],
staticPath: staticPath
}, function(err, r) {
if (err || r.error) {
console.log("failed to build", resource,":", err || r.error);
errors++;
} else {
console.log("built", resource, "in", r.time + "s" + (r.info ? " (" + r.info + ")" : ""));
}
if (--leftToBuild == 0) {
cc.exit();
if (errors) process.exit(1);
}
});
});