BrickUp API Service for Docker version.

builder.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var fs = require('fs');
  2. var path = require('path');
  3. var Builder = require('../libs/BuilderLibrary');
  4. var Router = require('koa-router');
  5. var router = module.exports = new Router();
  6. router.post('/builder/compile', function *() {
  7. console.log(this.request.body);
  8. var sources = this.request.body.sources;
  9. var builder = new Builder('./build', sources);
  10. yield function(done) {
  11. builder.init(done);
  12. };
  13. yield function(done) {
  14. builder.scanLibraries(done);
  15. };
  16. yield function(done) {
  17. builder.generateSources(done);
  18. };
  19. var liblist = yield function(done) {
  20. builder.scanSources(done);
  21. };
  22. var prelinkOps = yield function(done) {
  23. builder.parseOps(liblist, done);
  24. };
  25. var linkOps = yield function(done) {
  26. builder.parseDeps(liblist, prelinkOps, done);
  27. };
  28. var CompileOps = yield function(done) {
  29. builder.generateCompileOps(linkOps, done);
  30. };
  31. try {
  32. var hexFile = yield function(done) {
  33. builder.compile(CompileOps, done);
  34. };
  35. } catch(e) {
  36. this.status = 500;
  37. return;
  38. }
  39. this.type = 'application/octet-stream';
  40. this.body = fs.createReadStream(hexFile);
  41. });