Permalink
Browse files

basic coffee script working

  • Loading branch information...
matthewfl committed Jan 3, 2011
1 parent 7a1d353 commit cff8441208de8fff58ae4558f7dae9bf00ffbfac
Showing with 36 additions and 13 deletions.
  1. +2 −2 front-end.js
  2. +31 −9 sandbox/build.js
  3. +3 −2 test.js
View
@@ -115,7 +115,7 @@ var ajaxActions = {
}
db.get("fs_"+user+"_"+data.file, function (codeS) {
var con = http.createClient(config.testPort, 'localhost');
- var r = con.request('POST', '/?key='+config.testSKey+'&user='+user, {
+ var r = con.request('POST', '/?key='+config.testSKey+'&user='+user+"&file="+data.file, {
"host": config.testHost,
'Content-Length': codeS.length
});
@@ -129,7 +129,7 @@ var ajaxActions = {
back("Deploy failed due to error");
return;
}
- sandbox.build(codeS, user, function (build) {
+ sandbox.build(codeS, user, data.file, function (build) {
db.set("app_"+data.name, JSON.stringify({user: user, name: data.name, code: build, id: Date.now()}));
back("Deploy successful\nGive a few minutes for the application to update");
});
View
@@ -2,18 +2,36 @@ var db = require('../db');
var jsmin = require('../lib/jsmin').jsmin;
var modules = require('./modules');
-function builder (code, user, back) {
+function builder (code, user, Fname, back) {
this.back = back;
this.user = user;
this.need = {};
this.pub = {};
this.code = {};
this.counter=1;
- this.require(code);
- this.code._ = jsmin("",code,1);
+ this.compiler(code, Fname, true);
this.count();
}
+builder.prototype.compiler = function (code, name, root) {
+ try {
+ var suffix = /\.([a-zA-Z0-9]*)$/.exec(name)[1].toLowerCase();
+ // do compiling of code here
+ try {
+ switch(suffix) {
+ case 'coffee':
+ code = require('./compilers/coffee/lib/coffee-script').compile(code)
+ break;
+ }
+ }catch(e) {
+ // report errors to users
+ code = "throw "+JSON.stringify(e);
+ }
+ }catch(e){}
+ this.require(code);
+ this.code[root === true ? "_" : name] = jsmin("",code,1);
+};
+
builder.prototype.require = function (code) {
var self = this;
code.replace(/require\s*?\((.*?)\)/g, function (r, v) {
@@ -38,8 +56,10 @@ builder.prototype.searcher = function (name) {
this.counter++;
(function (name,self) {
db.get("fs_"+self.user+"_"+name.substring(2), function (code) {
- if(code) self.require(code);
- self.code[name] = code ? jsmin("",code,1) : "throw '"+name+" not found';";
+ if(code)
+ self.compiler(code,name);
+ else
+ self.code[name] = "throw '"+name+" not found';";
self.count();
});
})(name, this);
@@ -52,8 +72,10 @@ builder.prototype.searcher = function (name) {
(function (name, self) {
db.get("fs_"+user+"_"+file, function (code) {
console.log(code)
- if(code) self.require(code);
- self.code[name] = code ? jsmin("",code,1) : "throw '"+name+" not found';";
+ if(code)
+ self.compiler(code,name);
+ else
+ self.code[name] = "throw '"+name+" not found';";
self.count();
});
})(name, this);
@@ -85,6 +107,6 @@ builder.prototype.count = function () {
this.back(this.code);
};
-exports.build = function (code, user, back) {
- var b = new builder(code, user, back);
+exports.build = function (code, user, Fname, back) {
+ var b = new builder(code, user, Fname, back);
};
View
@@ -23,10 +23,11 @@ var server = http.createServer(function (req, res) {
res.end();
return;
}
- sandbox.build(data, urlInfo.query.user, function (d) {
+ sandbox.build(data, urlInfo.query.user, urlInfo.query.file, function (d) {
+ console.log(d)
var name;
if(urlInfo.query.user && urlInfo.query.user != "null" && urlInfo.query.file && urlInfo.query.file != "null")
- name = urlInfo.query.token+"."+urlInfo.query.file+"."+urlInfo.query.user+config.testBase;
+ name = urlInfo.query.token+"."+urlInfo.query.file.replace(/[^a-zA-Z0-9]/g,"-")+"."+urlInfo.query.user+config.testBase;
else
name = Math.random().toString().substring(2,12) + config.testBase;
name = name.toLowerCase();

0 comments on commit cff8441

Please sign in to comment.