You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
2.2 KiB
53 lines
2.2 KiB
module.exports = function (grunt) {
|
|
"use strict";
|
|
|
|
grunt.initConfig({
|
|
clean: ["./dist", "./tmp"],
|
|
copy: {
|
|
build: {
|
|
files: [{
|
|
expand: true,
|
|
cwd: "./src",
|
|
src: ["**/license*", "**/*.lua", "**/*.cfg"],
|
|
dest: "dist/",
|
|
filter: 'isFile'
|
|
}]
|
|
}
|
|
}
|
|
});
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
|
grunt.loadNpmTasks("grunt-contrib-copy");
|
|
grunt.loadNpmTasks('grunt-file-append');
|
|
|
|
grunt.registerTask("minify-lua-modules", "minifies lua modules", function () {
|
|
const fs = require('fs');
|
|
const luamin = require('luamin');
|
|
const util = require('util');
|
|
grunt.file.expand({filter: 'isDirectory'}, "dist/**/*").forEach(function (dir) {
|
|
grunt.file.expand({filter: 'isFile'}, dir + "/*.lua").forEach(function (file) {
|
|
const directory = file.substr(0, file.lastIndexOf('/'));
|
|
const file_name = file.substr(file.lastIndexOf('/') + 1);
|
|
const file_name_sans_ext = file_name.substr(0, file_name.lastIndexOf('.'));
|
|
|
|
const lua = fs.readFileSync(file, 'utf8');
|
|
const minified_contents = luamin.minify(lua);
|
|
|
|
const minified_file_name = file_name_sans_ext + '.min.lua';
|
|
const minified_file = directory + '/' + minified_file_name;
|
|
fs.writeFileSync(minified_file, minified_contents);
|
|
const file_stats = fs.statSync(file);
|
|
const minified_file_stats = fs.statSync(minified_file);
|
|
const saved_space = file_stats.size - minified_file_stats.size;
|
|
const saved_space_percent = (100 * (1 - minified_file_stats.size / file_stats.size)).toFixed(2);
|
|
console.log(util.format("Minified: %s: %f KB -> %s: %f KB. SAVED %d%% %d KB", file_name, file_stats.size / 1000, minified_file_name, minified_file_stats.size / 1000, saved_space_percent, saved_space / 1000));
|
|
});
|
|
});
|
|
});
|
|
|
|
grunt.registerTask("default", [
|
|
"clean",
|
|
"copy",
|
|
"minify-lua-modules"
|
|
]);
|
|
};
|