-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
36 lines (30 loc) · 939 Bytes
/
gulpfile.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
/* eslint-disable no-console */
import { exec } from "child_process";
import fs from "fs-extra";
import gulp from "gulp";
import size from "gulp-size";
import zip from "gulp-zip";
const zipFile = "game.zip";
const clearOut = () => fs.emptyDir("./out");
const zipOut = () =>
gulp
.src(["./dist/*", "!./dist/*.json"])
.pipe(size({ showFiles: true }))
.pipe(zip(zipFile))
.pipe(size({ showFiles: true }))
.pipe(gulp.dest("./out"));
const shrink = (cb) => {
exec(`cd tools && advzip ../out/${zipFile} -z -4 -i 1000`, function (err, stdout, stderr) {
console.log(stdout);
cb(err);
});
};
const reportSize = (cb) => {
const stats = fs.statSync(`out/${zipFile}`);
const sizeKb = stats.size / 1024;
const ratio = (stats.size / (13 * 1024)) * 100;
console.log(`Size: ${sizeKb.toFixed(2)} KB
Ratio: ${ratio.toFixed(2)} %`);
cb();
};
export default gulp.series(clearOut, zipOut, shrink, reportSize);