This repository has been archived by the owner on May 10, 2019. It is now read-only.
/
compress
executable file
·111 lines (93 loc) · 3.68 KB
/
compress
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
106
107
108
109
110
111
#!/usr/bin/env node
var
path = require('path')
resources = require('../lib/static_resources.js'),
config = require('../lib/configuration.js'),
generate_version_js = require('../lib/generate_code_version.js'),
i18n = require('i18n-abide'),
mkdirp = require('mkdirp'),
computecluster = require('compute-cluster'),
version = require('../lib/version.js');
const staticPath = path.join(__dirname, '..', 'resources', 'static');
var langs = config.get('supported_languages');
generate_version_js(function(err) {
if (err) {
console.error("Could not generate the code version, aborting: "
+ String(err));
process.exit(1);
}
var all = resources.all(langs);
var cc = new computecluster({
module: path.join(__dirname, 'compress-worker.js'),
max_backlog: -1
});
process.env['BUILD_DIR'] = path.join(staticPath, "build");
mkdirp.sync(process.env['BUILD_DIR']);
// generate include.js
require('./create_include.js')(function(err) {
if (err) console.error("Could not generate include.js, aborting: "
+ String(err));
process.exit(1);
});
// first 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['TEMPLATE_DIR'] = path.join(staticPath, "dialog", "views");
require('./create_templates.js')();
require('./create_font_css.js')();
var leftToBuild = Object.keys(all).length;
var errors = 0;
// bidbundle.js is a dependency for any module that includes crypto-loader.js
// build it first so a SHA can be calculated.
enqueueResource("/production/bidbundle.js", function() {
delete all["/production/bidbundle.js"];
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');
if (ix !== -1) all[resource].splice(ix, 1, '/build/templates.js');
// in dev, language specific font-css files are generated by the
// connect-fonts middleware.
// in prod, '*/fonts.css' files are pre-built for each language and
// combined with the rest of the bundle. Re-point location to fetch the
// font.css file from the prod location to the pre-built location.
for(var idx = 0, item; item=all[resource][idx]; idx++) {
if(/fonts\.css$/.test(item)) {
all[resource][idx] = "/build" + item;
}
}
// 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.js';
var ix = all[resource].indexOf(file);
if (-1 !== ix) all[resource].splice(ix, 1);
});
enqueueResource(resource, function() {
if (!leftToBuild) {
cc.exit();
if (errors) process.exit(1);
}
});
});
});
function enqueueResource(resource, done) {
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 + ")" : ""));
}
leftToBuild--
done && done();
});
}
});