Created
April 15, 2017 22:26
-
-
Save tedivm/6add17600d2079c1606e08dba07650c9 to your computer and use it in GitHub Desktop.
Gruntfile.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (grunt) { | |
require('time-grunt')(grunt); | |
// Pull defaults (including username and password) from .screeps.json | |
var config = require('./.screeps.json') | |
if(!config.branch) { | |
config.branch = 'sim' | |
} | |
if(!config.ptr) { | |
config.ptr = false | |
} | |
// Allow grunt options to override default configuration | |
var branch = grunt.option('branch') || config.branch; | |
var email = grunt.option('email') || config.email; | |
var password = grunt.option('password') || config.password; | |
var ptr = grunt.option('ptr') ? true : config.ptr | |
var intel_user = grunt.option('intel_user') || config.intel_user; | |
var intel_password = grunt.option('intel_password') || config.intel_password; | |
var currentdate = new Date(); | |
grunt.log.subhead('Task Start: ' + currentdate.toLocaleString()) | |
grunt.log.writeln('Branch: ' + branch) | |
// Load needed tasks | |
grunt.loadNpmTasks('grunt-screeps') | |
grunt.loadNpmTasks('grunt-contrib-clean') | |
grunt.loadNpmTasks('grunt-contrib-concat') | |
grunt.loadNpmTasks('grunt-contrib-copy') | |
grunt.loadNpmTasks('grunt-file-append') | |
grunt.loadNpmTasks("grunt-http") | |
grunt.loadNpmTasks("grunt-jsbeautifier") | |
grunt.loadNpmTasks("grunt-rsync") | |
grunt.initConfig({ | |
// Push all files in the dist folder to screeps. What is in the dist folder | |
// and gets sent will depend on the tasks used. | |
screeps: { | |
options: { | |
email: email, | |
password: password, | |
branch: branch, | |
ptr: ptr | |
}, | |
dist: { | |
src: ['dist/*.js'] | |
} | |
}, | |
// Combine groups of files to reduce the calls to 'require'. | |
concat: { | |
// Merge together additions to the default game objects into one file | |
extends: { | |
src: ['dist/extend_*.js'], | |
dest: 'dist/_extensions_packaged.js', | |
}, | |
// Merge ScreepsOS into a single file in the specified order | |
sos: { | |
options: { | |
banner: "var skip_includes = true\n\n", | |
separator: "\n\n\n", | |
}, | |
// Do not include console! It has to be redefined each tick | |
src: [ | |
'dist/sos_config.js', | |
'dist/sos_interrupt.js', | |
'dist/sos_process.js', | |
'dist/sos_scheduler.js', | |
'dist/sos_script.js', | |
'dist/sos_shell.js', | |
'dist/sos_kernel.js'], | |
dest: 'dist/_sos_packaged.js', | |
}, | |
}, | |
// Download intel packages from control server. | |
http: { | |
// A module that just exports an object containing portal destinations | |
// and time outs by room. | |
portals: { | |
options: { | |
url: 'https://uv4i6foh6l.execute-api.us-east-1.amazonaws.com/prod/portals.js', | |
method: 'GET', | |
headers: { | |
'x-api-key': intel_password | |
}, | |
}, | |
dest: 'dist/lib_portals.js' | |
}, | |
// A module that exposes user and alliance data, such as what alliance a | |
// user is a member of, their gcl, and their rooms. | |
intel: { | |
options: { | |
url: 'https://uv4i6foh6l.execute-api.us-east-1.amazonaws.com/prod/room_intel.js', | |
method: 'GET', | |
headers: { | |
'x-api-key': intel_password | |
}, | |
}, | |
dest: 'dist/lib_roomintel.js' | |
} | |
}, | |
// Copy all source files into the dist folder, flattening the folder | |
// structure by converting path delimiters to underscores | |
copy: { | |
// Pushes the game code to the dist folder so it can be modified before | |
// being send to the screeps server. | |
screeps: { | |
files: [{ | |
expand: true, | |
cwd: 'src/', | |
src: '**', | |
dest: 'dist/', | |
filter: 'isFile', | |
rename: function (dest, src) { | |
// Change the path name utilize underscores for folders | |
return dest + src.replace(/\//g,'_'); | |
} | |
}], | |
}, | |
// Prepares to push the "recovery console" up to screeps. It runs no code, | |
// basically pausing the program, but has tools for correcting issues. | |
recovery: { | |
files: [{ | |
expand: true, | |
cwd: 'recovery/', | |
src: '**', | |
dest: 'dist/', | |
filter: 'isFile', | |
rename: function (dest, src) { | |
// Change the path name utilize underscores for folders | |
return dest + src.replace(/\//g,'_'); | |
} | |
}] | |
} | |
}, | |
// Copy files to the folder the client uses to sink to the private server. | |
// Use rsync so the client only uploads the changed files. | |
rsync: { | |
options: { | |
args: ["--verbose", "--checksum"], | |
exclude: [".git*"], | |
recursive: true | |
}, | |
private: { | |
options: { | |
src: './dist/', | |
dest: '/Users/tedivm/Library/Application Support/Screeps/scripts/screeps_tedivm_com___21025/default', | |
} | |
}, | |
}, | |
// Add variable to mark this as packaged. | |
file_append: { | |
default_options: { | |
files: [ | |
{ | |
prepend: "'use strict';\nglobal.GRUNT_PACKAGE=true\n", | |
input: 'dist/main.js', | |
} | |
] | |
}, | |
versioning: { | |
files: [ | |
{ | |
append: "\nglobal.SCRIPT_VERSION = "+ currentdate.getTime() + "\n", | |
input: 'dist/sos_bootstrap.js', | |
} | |
] | |
} | |
}, | |
// Remove all files from the dist folder. | |
clean: { | |
'dist': ['dist'] | |
}, | |
// Apply code styling | |
jsbeautifier: { | |
modify: { | |
src: ["src/**/*.js"], | |
options: { | |
config: '.jsbeautifyrc' | |
} | |
}, | |
verify: { | |
src: ["src/**/*.js"], | |
options: { | |
mode: 'VERIFY_ONLY', | |
config: '.jsbeautifyrc' | |
} | |
} | |
} | |
}) | |
// Combine the above into a default task | |
grunt.registerTask('default', ['clean', 'copy:screeps', 'file_append:versioning', 'http:portals', 'http:intel', 'screeps']); | |
grunt.registerTask('simple', ['clean', 'copy:screeps', 'file_append:versioning', 'screeps']); | |
grunt.registerTask('package', ['clean', 'copy:screeps', 'file_append:versioning', 'http:portals', 'http:intel']); | |
grunt.registerTask('private', ['clean', 'copy:screeps', 'file_append:versioning', 'rsync:private']); | |
grunt.registerTask('recovery', ['clean', 'copy:recovery', 'screeps']); | |
grunt.registerTask('test', ['jsbeautifier:verify']); | |
grunt.registerTask('pretty', ['jsbeautifier:modify']); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment