diff --git a/js/apps/system/aardvark/foxxTemplates.js b/js/apps/system/aardvark/foxxTemplates.js index 47b894caa9..9382217729 100644 --- a/js/apps/system/aardvark/foxxTemplates.js +++ b/js/apps/system/aardvark/foxxTemplates.js @@ -34,6 +34,7 @@ var FoxxController = require("org/arangodb/foxx").Controller, controller = new FoxxController(applicationContext), internal = require("internal"), TemplateEngine = require("lib/foxxTemplateEngine").Engine, + FoxxManager = require("org/arangodb/foxx/manager"), isDevMode = function() { return internal.developmentMode; }; @@ -49,15 +50,21 @@ controller.post("/generate", function(req, res) { if (isDevMode()) { path = module.devAppPath(); } else { - path = module.appPath(); + path = module.tmpPath(); } var conf = req.params("configuration"); conf.set("applicationContext", applicationContext); conf.set("path", path); templateEngine = new TemplateEngine(conf.forDB()); - templateEngine.write(); + + if (isDevMode()) { + FoxxManager.devSetup(conf.get("name")); + } else { + // TODO Zip and ship it + } + }).bodyParam("configuration", { description: "The configuration for the template.", type: Configuration diff --git a/js/apps/system/aardvark/lib/foxxTemplateEngine.js b/js/apps/system/aardvark/lib/foxxTemplateEngine.js index 4f77ffc072..3731a785dd 100644 --- a/js/apps/system/aardvark/lib/foxxTemplateEngine.js +++ b/js/apps/system/aardvark/lib/foxxTemplateEngine.js @@ -39,6 +39,10 @@ _.each(this.controllers, function (controller) { fs.write(fs.join(this.folder, controller.path), this.buildController(controller)); }, 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) { @@ -105,8 +109,8 @@ controllers: {}, - // setup: "", - // teardown: "" + setup: "scripts/setup.js", + teardown: "scripts/teardown.js" }; _.each(this.controllers, function (controller) { @@ -116,23 +120,40 @@ 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() { - var manifest = this.template("repository.js.tmpl"); + var templ = this.template("repository.js.tmpl"); - return manifest(); + return templ(); }, buildModel: function() { - var manifest = this.template("model.js.tmpl"); + var templ = this.template("model.js.tmpl"); - return manifest(); + return templ(); }, });