mirror of https://gitee.com/bigwinds/arangodb
Created code for setup and teardown. Also dev setup will be executed in development mode.
This commit is contained in:
parent
dc15329e64
commit
987dec185e
|
@ -34,6 +34,7 @@ var FoxxController = require("org/arangodb/foxx").Controller,
|
||||||
controller = new FoxxController(applicationContext),
|
controller = new FoxxController(applicationContext),
|
||||||
internal = require("internal"),
|
internal = require("internal"),
|
||||||
TemplateEngine = require("lib/foxxTemplateEngine").Engine,
|
TemplateEngine = require("lib/foxxTemplateEngine").Engine,
|
||||||
|
FoxxManager = require("org/arangodb/foxx/manager"),
|
||||||
isDevMode = function() {
|
isDevMode = function() {
|
||||||
return internal.developmentMode;
|
return internal.developmentMode;
|
||||||
};
|
};
|
||||||
|
@ -49,15 +50,21 @@ controller.post("/generate", function(req, res) {
|
||||||
if (isDevMode()) {
|
if (isDevMode()) {
|
||||||
path = module.devAppPath();
|
path = module.devAppPath();
|
||||||
} else {
|
} else {
|
||||||
path = module.appPath();
|
path = module.tmpPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
var conf = req.params("configuration");
|
var conf = req.params("configuration");
|
||||||
conf.set("applicationContext", applicationContext);
|
conf.set("applicationContext", applicationContext);
|
||||||
conf.set("path", path);
|
conf.set("path", path);
|
||||||
templateEngine = new TemplateEngine(conf.forDB());
|
templateEngine = new TemplateEngine(conf.forDB());
|
||||||
|
|
||||||
templateEngine.write();
|
templateEngine.write();
|
||||||
|
|
||||||
|
if (isDevMode()) {
|
||||||
|
FoxxManager.devSetup(conf.get("name"));
|
||||||
|
} else {
|
||||||
|
// TODO Zip and ship it
|
||||||
|
}
|
||||||
|
|
||||||
}).bodyParam("configuration", {
|
}).bodyParam("configuration", {
|
||||||
description: "The configuration for the template.",
|
description: "The configuration for the template.",
|
||||||
type: Configuration
|
type: Configuration
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
_.each(this.controllers, function (controller) {
|
_.each(this.controllers, function (controller) {
|
||||||
fs.write(fs.join(this.folder, controller.path), this.buildController(controller));
|
fs.write(fs.join(this.folder, controller.path), this.buildController(controller));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
fs.write(fs.join(this.folder, "scripts", "setup.js"), this.buildSetup(this.collectionNames));
|
||||||
|
|
||||||
|
fs.write(fs.join(this.folder, "scripts", "teardown.js"), this.buildTeardown(this.collectionNames));
|
||||||
},
|
},
|
||||||
|
|
||||||
template: function(name) {
|
template: function(name) {
|
||||||
|
@ -105,8 +109,8 @@
|
||||||
|
|
||||||
controllers: {},
|
controllers: {},
|
||||||
|
|
||||||
// setup: "",
|
setup: "scripts/setup.js",
|
||||||
// teardown: ""
|
teardown: "scripts/teardown.js"
|
||||||
};
|
};
|
||||||
|
|
||||||
_.each(this.controllers, function (controller) {
|
_.each(this.controllers, function (controller) {
|
||||||
|
@ -116,23 +120,40 @@
|
||||||
return JSON.stringify(manifest, 0, 2);
|
return JSON.stringify(manifest, 0, 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
buildController: function(controller) {
|
|
||||||
var manifest = this.template("controller.js.tmpl");
|
|
||||||
|
|
||||||
return manifest(controller);
|
buildSetup: function(collections) {
|
||||||
|
var templ = this.template("setup.js.tmpl");
|
||||||
|
|
||||||
|
return templ({
|
||||||
|
collections: collections
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
buildTeardown: function(collections) {
|
||||||
|
var templ = this.template("teardown.js.tmpl");
|
||||||
|
|
||||||
|
return templ({
|
||||||
|
collections: collections
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
buildController: function(controller) {
|
||||||
|
var templ = this.template("controller.js.tmpl");
|
||||||
|
|
||||||
|
return templ(controller);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
buildRepository: function() {
|
buildRepository: function() {
|
||||||
var manifest = this.template("repository.js.tmpl");
|
var templ = this.template("repository.js.tmpl");
|
||||||
|
|
||||||
return manifest();
|
return templ();
|
||||||
},
|
},
|
||||||
|
|
||||||
buildModel: function() {
|
buildModel: function() {
|
||||||
var manifest = this.template("model.js.tmpl");
|
var templ = this.template("model.js.tmpl");
|
||||||
|
|
||||||
return manifest();
|
return templ();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue