Newer
Older
Lloyd Hilaiel
committed
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
#!/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');
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('/common/js/templates.js');
Lloyd Hilaiel
committed
if (ix !== -1) all[resource].splice(ix, 1, '/build/templates.js');
Lloyd Hilaiel
committed
// remove translation files from default and debug languages. #1905
[ config.get('debug_lang'), config.get('default_lang') ].forEach(function(l) {
var file = '/i18n/' + i18n.localeFrom(l) + '/client.json';
var ix = all[resource].indexOf(file);
if (-1 !== ix) all[resource].splice(ix, 1);
});
Lloyd Hilaiel
committed
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);
}
});
});