So I decided that this will work best if not just the build, but the entire project system would be JS-based. For example, here is the current project script for Sphere projects:
RequireScript('link.js');
// ES6 polyfills
String.prototype.startsWith = function(searchString, position)
{
position = position || 0;
return this.indexOf(searchString, position) === position;
};
function prep(source)
{
source.mkdir('scripts');
source.mkdir('maps');
source.mkdir('images');
source.mkdir('sounds');
source.mkdir('spritesets');
source.mkdir('windowstyles');
}
function build(source, target)
{
// Sphere filename filters
var filters = [
"*.rmp", "*.rss", "*.rts", "*.rws", "*.rfn",
"*.js", "*.coffee", "*.glsl",
"*.mp3", "*.ogg", "*.mid", "*.wav", "*.flac", "*.it", "*.s3m", "*.mod",
"*.png", "*.jpg", "*.bmp", "*.pcx",
];
// copy relevant files into the distribution
Print("Copying files to distribution");
Link(filters).each(function (filter) {
Link(source.ls(filter))
.where(function(filename) { return !filename.startsWith('dist/'); })
.where(function(filename) { return filename != 'build.js'; })
.each(function(filename)
{
source.cp(filename, target.path + filename);
});
});
// write game.sgm
Print("Generating game.sgm");
var sgmFile = new FileWriter(target.path + 'game.sgm');
sgmFile.write("name=" + source.name + "\n");
sgmFile.write("author=" + source.author + "\n");
sgmFile.write("description=" + source.description + "\n");
sgmFile.write("screen_width=" + source.screenWidth + "\n");
sgmFile.write("screen_height=" + source.screenHeight + "\n");
sgmFile.write("script=" + source.mainScript + "\n");
sgmFile.close();
Print("Getting everything eaten by PigGeta");
}
function clean(target)
{
target.rm('game.sgm');
}
This will make Sphere Studio truly engine-agnostic.
The one thing I am trying to figure out is how plugin integration will work. Plugins should be able to register to either run as part of the build process, or else provide additional functions which can be used in a build script. For example a plugin for minifying scripts might add a minify() method to the source object. The trick is to do this without introducing any external dependency on Jurassic...