Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.5.1 bug fix: submit code multitimes when multiple source code inside working dir #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-screeps",
"description": "A Grunt plugin for committing code to your Screeps account",
"version": "1.5.0",
"version": "1.5.1",
"homepage": "https://github.com/screeps/grunt-screeps",
"author": "Artem Chivchalov <[email protected]> (https://screeps.com)",
"repository": {
Expand Down
100 changes: 50 additions & 50 deletions tasks/screeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,64 +60,64 @@ module.exports = function (grunt) {
modules[name] = {binary: grunt.file.read(filepath, {encoding: null}).toString('base64')};
}
});
});

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

if(res.statusCode < 200 || res.statusCode >= 300) {
grunt.fail.fatal('Screeps server returned error code ' + res.statusCode);
}
if(res.statusCode < 200 || res.statusCode >= 300) {
grunt.fail.fatal('Screeps server returned error code ' + res.statusCode);
}

res.on('data', function(chunk) {
data += chunk;
});

res.on('end', function() {
var serverText = server && (server.name || server.host) || 'Screeps';
try {
var parsed = JSON.parse(data);
if(parsed.ok) {
var msg = 'Committed to ' + serverText + ' account "' + options.email + '"';
if(options.branch) {
msg += ' branch "' + options.branch+'"';
}
msg += '.';
grunt.log.writeln(msg);
}
else {
grunt.log.error('Error while committing to ' + serverText + ': '+util.inspect(parsed));
}
} catch (e) {
grunt.log.error('Error while processing ' + serverText + ' json: '+e.message);
}
done();
});
res.on('data', function(chunk) {
data += chunk;
});

var postData = {modules: modules};
if(options.branch) {
postData.branch = options.branch;
}
req.write(JSON.stringify(postData));
req.end();
res.on('end', function() {
var serverText = server && (server.name || server.host) || 'Screeps';
try {
var parsed = JSON.parse(data);
if(parsed.ok) {
var msg = 'Committed to ' + serverText + ' account "' + options.email + '"';
if(options.branch) {
msg += ' branch "' + options.branch+'"';
}
msg += '.';
grunt.log.writeln(msg);
}
else {
grunt.log.error('Error while committing to ' + serverText + ': '+util.inspect(parsed));
}
} catch (e) {
grunt.log.error('Error while processing ' + serverText + ' json: '+e.message);
}
done();
});
});

var postData = {modules: modules};
if(options.branch) {
postData.branch = options.branch;
}
req.write(JSON.stringify(postData));
req.end();
});

};