1
0
Fork 0

First steps towards generating a Foxx app

This commit is contained in:
Lucas Dohmen 2014-12-13 22:40:46 +01:00 committed by Michael Hackstein
parent 8914c18561
commit 93f520b723
3 changed files with 53 additions and 12 deletions

View File

@ -32,8 +32,7 @@
var FoxxController = require("org/arangodb/foxx").Controller, var FoxxController = require("org/arangodb/foxx").Controller,
controller = new FoxxController(applicationContext), controller = new FoxxController(applicationContext),
internal = require("internal"), internal = require("internal"),
templateEngine = new (require("lib/foxxTemplateEngine").Engine)(applicationContext.foxxFilename("templates")), TemplateEngine = require("lib/foxxTemplateEngine").Engine,
fs = require("fs"),
isDevMode = function() { isDevMode = function() {
return internal.developmentMode; return internal.developmentMode;
}; };
@ -44,16 +43,24 @@ controller.get("/devMode", function(req, res) {
controller.post("/generate", function(req, res) { controller.post("/generate", function(req, res) {
var path, var path,
name = "hansilein"; templateEngine;
if (isDevMode()) { if (isDevMode()) {
path = module.devAppPath(); path = module.devAppPath();
} else { } else {
path = module.appPath(); path = module.appPath();
} }
var folder = fs.join(path, name);
fs.makeDirectory(folder); templateEngine = new TemplateEngine({
var manifest = fs.join(folder, "manifest.json"); applicationContext: applicationContext,
fs.write(manifest, templateEngine.buildManifest({ path: path,
author: "Peterle" name: 'fancyApp',
})); collectionNames: ['people'],
authenticated: false,
author: 'Bob the Builder',
description: 'This app is pretty fancy',
license: 'Do Whatever You Want'
});
templateEngine.write();
}); });

View File

@ -4,8 +4,28 @@
var fs = require("fs"); var fs = require("fs");
var _ = require("underscore"); var _ = require("underscore");
var Engine = function(path) { var Engine = function(opts) {
this._path = path; this.applicationContext = opts.applicationContext;
this.path = opts.path;
this.name = opts.name;
this.collectionNames = opts.collectionNames;
this.authenticated = opts.authenticated;
this.author = opts.author;
this.description = opts.description;
this.license = opts.license;
this._path = this.applicationContext.foxxFilename("templates");
this.folder = fs.join(this.path, this.name);
};
Engine.prototype.write = function() {
fs.makeDirectory(this.folder);
fs.write(fs.join(this.folder, "manifest.json"), this.buildManifest({
name: this.name,
description: this.description,
author: this.author,
license: this.license
}));
}; };
Engine.prototype.buildManifest = function(info) { Engine.prototype.buildManifest = function(info) {

View File

@ -1,3 +1,17 @@
{ {
"author": "<%=author %>" "name": "<%= name %>",
"description": "<%= description %>",
"author": "<%= author %>",
"version": "0.0.1",
"license": "<%= license %>",
"isSystem": false,
"contributors": [
],
"controllers": {
},
"setup": "",
"teardown": ""
} }