From 25960f100b7a68f1d3009a9fcf16999d9e6780d2 Mon Sep 17 00:00:00 2001 From: Peery Date: Thu, 22 Sep 2022 22:39:25 +0200 Subject: [PATCH] Added compilation tasks to Gruntfile.js Added tasks to flatten the folder structure and rename the files and requires() accordingly. Also added a task to insert a version.js with a global version variable as well as time-grunt to show the time it takes. --- Gruntfile.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9134189..1c652da 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,4 +1,6 @@ module.exports = function(grunt) { + require('time-grunt')(grunt); + var config = require('./.credentials.json'); var branch = grunt.option('branch') || config.branch; var email = grunt.option('email') || config.email; @@ -7,6 +9,14 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-screeps'); + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-file-append'); + + var current_date = new Date(); + + grunt.log.subhead('Task start: ' + current_date.toLocaleString()) + grunt.log.writeln('Branch: ' + branch) grunt.initConfig({ screeps: { @@ -19,6 +29,38 @@ module.exports = function(grunt) { dist: { src: ['dist/*.js'] } - } - }); + }, + + clean: { + 'dist': ['dist'] + }, + + copy: { // Copy all source files into the dist folder, flattening the folder structure + screeps: { + files: [{ + expand: true, + cwd: 'src/', + src: '**', + dest: 'dist/', + filter: 'isFile', + rename: function (dest, src) { + return dest + src.replace(/\//g, '_'); + } + }], + } + }, + + file_append: { + versioning: { + files: [ + { + append: "\nglobal.SCRIPT_VERSION = " + current_date.getTime() + "\n", + input: 'dist/version.js' + } + ] + } + }, + }) + + grunt.registerTask('default', ['clean', 'copy:screeps', 'file_append:versioning', 'screeps']); }