Skip to content

Commit

Permalink
✨ season server support
Browse files Browse the repository at this point in the history
  • Loading branch information
o4kapuk committed Nov 25, 2020
1 parent dea06b8 commit feda117
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ module.exports = function(grunt) {
screeps: {
options: {
email: 'YOUR_EMAIL',
password: 'YOUR_PASSWORD',
token: 'AUTH_TOKEN',
branch: 'default',
ptr: false
// server: 'season'
},
dist: {
files: [
Expand All @@ -47,4 +47,4 @@ Now you can run this command to commit your code from `dist` folder to your Scre
grunt screeps
```

See more advanced usage examples in [this docs article](http://docs.screeps.com/contributed/advanced_grunt.html).
See more advanced usage examples in [this docs article](http://docs.screeps.com/contributed/advanced_grunt.html).
32 changes: 21 additions & 11 deletions tasks/screeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ var path = require('path'),
https = require('https'),
util = require('util');

var servers = {
persistent: { name: 'Screeps', host: 'screeps.com', path: '/api/user/code' },
ptr: { name: 'PTR', host: 'screeps.com', path: '/ptr/api/user/code' },
season: { name: 'Season', host: 'screeps.com', path: '/season/api/user/code' }
};

module.exports = function (grunt) {

grunt.registerMultiTask('screeps', 'A Grunt plugin for commiting code to your Screeps account', function () {

var options = this.options({});

var server = options.server || {};
var server = options.server || (options.ptr ? 'ptr' : 'persistent');
if(servers[server]) {
server = servers[server];
}

var modules = {};

Expand Down Expand Up @@ -52,17 +61,22 @@ module.exports = function (grunt) {
}
});

var proto = server.http ? http : https,
req = proto.request({
var requestOptions = {
hostname: server.host || 'screeps.com',
port: server.port || (server.http ? 80 : 443),
path: options.ptr ? '/ptr/api/user/code' : '/api/user/code',
path: server.path || '/api/user/code',
method: 'POST',
auth: options.email + ':' + options.password,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}, function(res) {
};
if(options.token) {
requestOptions.headers['X-Token'] = options.token;
} else {
requestOptions.auth = options.email + ':' + options.password;
}
var proto = server.http ? http : https,
req = proto.request(requestOptions, function(res) {
res.setEncoding('utf8');

var data = '';
Expand All @@ -76,18 +90,14 @@ module.exports = function (grunt) {
});

res.on('end', function() {
var serverText = server && server.host || 'Screeps';
var serverText = server && (server.name || server.host) || 'Screeps';
try {
var parsed = JSON.parse(data);
serverText = server && server.host || 'Screeps';
if(parsed.ok) {
var msg = 'Committed to ' + serverText + ' account "' + options.email + '"';
if(options.branch) {
msg += ' branch "' + options.branch+'"';
}
if(options.ptr) {
msg += ' [PTR]';
}
msg += '.';
grunt.log.writeln(msg);
}
Expand Down

0 comments on commit feda117

Please sign in to comment.