forked from DestinyItemManager/DIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
120 lines (104 loc) · 3.36 KB
/
Gruntfile.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
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
112
113
114
115
116
117
118
119
120
const child_process = require("child_process");
const fs = require("fs");
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
var betaVersion = pkg.version.toString() + "." + process.env.TRAVIS_BUILD_NUMBER;
grunt.initConfig({
pkg: pkg,
// Tasks for uploading the website versions
rsync: {
options: {
//dryRun: true,
args: ["--verbose"],
excludeFirst: ["chrome.zip", "stats.html"],
host: process.env.REMOTE_HOST,
recursive: true,
ssh: true,
privateKey: 'config/dim_travis.rsa',
sshCmdArgs: ["-o StrictHostKeyChecking=no"]
},
// Sync everything but the HTML first, so it's ready to go
app_content: {
options: {
exclude: ["*.html", "service-worker.js", "version.json"],
src: "dist/",
dest: process.env.REMOTE_PATH
}
},
// Then sync the HTML which will start using the new content
app_html: {
options: {
src: ["dist/*.html", "dist/service-worker.js", "dist/version.json"],
dest: process.env.REMOTE_PATH
}
}
},
precompress: {
web: {
src: "dist/**/*.{js,html,css,json,map,ttf,eot,svg,wasm}"
}
},
});
grunt.loadNpmTasks('grunt-rsync');
grunt.registerMultiTask(
'precompress',
'Create gzip and brotli versions of web assets',
function() {
const done = this.async();
const promises = [];
this.filesSrc.forEach(function(file) {
if (!fs.existsSync(file+".gz")) {
promises.push(new Promise(function(resolve, reject) {
child_process.exec("gzip -c --no-name " + file + " > " + file + ".gz", function(error, stdout, stderr) {
if (error) {
grunt.log.writeln("gzip " + file + " => error: " + stdout + stderr);
reject(error);
} else {
grunt.log.writeln("gzip " + file + " => success");
resolve();
}
});
}));
}
if (!fs.existsSync(file+".br")) {
const brotli = process.env.BROTLI || 'brotli/brotli';
const brotliArgs = [file];
promises.push(new Promise(function(resolve, reject) {
child_process.execFile(brotli, brotliArgs, function(error, stdout, stderr) {
if (error) {
grunt.log.writeln("brotli " + file + " => error: " + stdout + stderr);
reject(error);
} else {
grunt.log.writeln("brotli " + file + " => success");
resolve();
}
});
}).then(function() {
return new Promise(function(resolve, reject) {
fs.chmod(file + ".br", 0644, resolve);
});
}));
}
});
Promise.all(promises).then(done);
}
);
grunt.registerTask('publish_beta', [
'log_beta_version',
'precompress',
'rsync:app_content',
'rsync:app_html'
]);
grunt.registerTask('publish_release', [
'log_release_version',
'precompress',
'rsync:app_content',
'rsync:app_html'
]);
grunt.registerTask('log_beta_version', function() {
grunt.log.ok("New Beta version is " + betaVersion);
});
grunt.registerTask('log_release_version', function() {
grunt.log.ok("New production version is " + pkg.version);
});
};