Skip to content

Commit

Permalink
add binary files support
Browse files Browse the repository at this point in the history
  • Loading branch information
artch committed Sep 25, 2017
1 parent 2d2c02d commit 5b86619
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function(grunt) {
{
expand: true,
cwd: 'dist/',
src: ['**/*.js'],
src: ['**/*.{js,wasm}'],
flatten: true
}
]
Expand Down
14 changes: 11 additions & 3 deletions tasks/screeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ module.exports = function (grunt) {
return true;
}
}).map(function (filepath) {
var name = path.basename(filepath).replace(/\.js$/,'');
modules[name] = grunt.file.read(filepath);
var basename = path.basename(filepath),
ext = path.extname(basename),
name = basename.replace(ext,'');

if(ext === '.js') {
modules[name] = grunt.file.read(filepath, {encoding: 'utf8'});
}
else {
modules[name] = {binary: grunt.file.read(filepath, {encoding: null}).toString('base64')};
}
});

var proto = server.http ? http : https,
Expand Down Expand Up @@ -71,7 +79,7 @@ module.exports = function (grunt) {
var serverText = server && server.host || 'Screeps';
try {
var parsed = JSON.parse(data);
var serverText = server && server.host || 'Screeps';
serverText = server && server.host || 'Screeps';
if(parsed.ok) {
var msg = 'Committed to ' + serverText + ' account "' + options.email + '"';
if(options.branch) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/happy/native.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Native content
2 changes: 1 addition & 1 deletion test/screeps_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var grunt = require('grunt'),
happy = nock('https://screeps.com')
.post(
'/api/user/code',
{"branch": "default", "modules":{ "hello":"console.log(\"Hello world!\");", "main":"require(\"hello\");" }}
{"branch": "default", "modules":{ "hello":"console.log(\"Hello world!\");", "main":"require(\"hello\");", "native": {"binary": "TmF0aXZlIGNvbnRlbnQ=" } } }
)
.reply(200, '{"ok":1}');

Expand Down

0 comments on commit 5b86619

Please sign in to comment.