forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompress.js
28 lines (24 loc) · 924 Bytes
/
compress.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
const glob = require('glob');
const computecluster = require('compute-cluster');
const path = require('path');
var clusterOpts = {
module: path.join(__dirname, "compress_worker.js"),
max_backlog: 10000
}
// by default, we'll create a cluster as big as the number of cores on your machine,
// set the CANVAS_BUILD_CONCURRENCY environment variable if you want it to be something else
if (process.env.CANVAS_BUILD_CONCURRENCY)
clusterOpts.max_processes = parseInt(process.env.CANVAS_BUILD_CONCURRENCY);
// allocate a compute cluster
var cc = new computecluster(clusterOpts);
var files = glob.sync("public/optimized/compiled/{*.js,**/*.js}");
var toRun = files.length;
for (var i = 0; i < files.length; i++) {
cc.enqueue(files[i], function(err, r) {
if (err) return console.log("an error occured:", err);
if (--toRun === 0) {
console.log(files.length + 'files minified')
cc.exit();
}
});
}