module.exports = function (grunt) { "use strict"; grunt.initConfig({ clean: ["./dist", "./tmp"], copy: { build: { files: [{ expand: true, cwd: "./src", src: ["**/license*"], dest: "dist/", filter: 'isFile' }] } } }); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks("grunt-contrib-copy"); grunt.loadNpmTasks('grunt-file-append'); grunt.registerTask("add-rename-lua-module-tasks", "Finds and adds tasks to rename all main.lua to match their parent directory", function () { grunt.file.expand({filter: 'isDirectory'}, "src/*").forEach(function (dir) { var module_name = dir.substr(dir.lastIndexOf('/') + 1); if (module_name !== 'lib') { var copy_task = {}; try { copy_task = grunt.config.get('copy'); } catch (exception) { console.log("No copy config exists, generating empty one."); } copy_task[module_name] = { src: [dir + '/**/main.lua'], dest: 'dist/' + module_name + '/' + module_name + '.lua' }; console.log("Added copy task for module [" + module_name + "]"); grunt.config.set('copy', copy_task); } }); }); grunt.registerTask("minify-lua-modules", "minifies lua modules", function () { var fs = require('fs'); var luamin = require('luamin'); grunt.file.expand({filter: 'isDirectory'}, "dist/*").forEach(function (dir) { grunt.file.expand({filter: 'isFile'}, dir + "/*.lua").forEach(function (file) { var directory = file.substr(0, file.lastIndexOf('/')); var file_name = file.substr(file.lastIndexOf('/') + 1, file.lastIndexOf('.')); var lua = fs.readFileSync(file, 'utf8'); var minified = luamin.minify(lua); var minified_file_name = file_name + '.min.lua'; fs.writeFileSync(directory + '/' + minified_file_name, minified); console.log("Minified: " + file_name + ' -> ' + minified_file_name); }); }); }); grunt.registerTask("default", [ "clean", "add-rename-lua-module-tasks", "copy", "minify-lua-modules" ]); };