var fs = require('fs'); var path = require('path'); var Builder = require('../libs/BuilderLibrary'); var Router = require('koa-router'); var router = module.exports = new Router(); router.post('/builder/compile', function *() { console.log(this.request.body); var sources = this.request.body.sources; var builder = new Builder('./build', sources); yield function(done) { builder.init(done); }; yield function(done) { builder.scanLibraries(done); }; yield function(done) { builder.generateSources(done); }; var liblist = yield function(done) { builder.scanSources(done); }; var prelinkOps = yield function(done) { builder.parseOps(liblist, done); }; var linkOps = yield function(done) { builder.parseDeps(liblist, prelinkOps, done); }; var CompileOps = yield function(done) { builder.generateCompileOps(linkOps, done); }; try { var hexFile = yield function(done) { builder.compile(CompileOps, done); }; } catch(e) { this.status = 500; return; } this.type = 'application/octet-stream'; this.body = fs.createReadStream(hexFile); });