1
0
Fork 0

Moved the foxx generator into a server module. It is now possible to generate a new app from command line

This commit is contained in:
Michael Hackstein 2015-01-20 15:33:28 +01:00
parent be7b542e27
commit d744425043
23 changed files with 85 additions and 7 deletions

View File

@ -1,4 +1,3 @@
/*jshint strict: false*/
/*global module, require, exports */
////////////////////////////////////////////////////////////////////////////////
@ -1205,6 +1204,7 @@ exports.initializeFoxx = function () {
var store = require("org/arangodb/foxx/store");
var console = require("console");
var ArangoApp = require("org/arangodb/foxx/arangoApp").ArangoApp;
var TemplateEngine = require("org/arangodb/foxx/templateEngine").Engine;
var routeApp = require("org/arangodb/foxx/routing").routeApp;
var arangodb = require("org/arangodb");
var ArangoError = arangodb.ArangoError;
@ -1521,6 +1521,47 @@ exports.initializeFoxx = function () {
return app;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief Generates an App with the given options into the targetPath
////////////////////////////////////////////////////////////////////////////////
var installAppFromGenerator = function(targetPath, options) {
// TODO validate options
var invalidOptions = [];
// Set default values:
options.name = options.name || "MyApp";
options.author = options.author || "Author";
options.description = options.description || "";
options.license = options.license || "Apache 2";
options.authenticated = options.authenticated || false;
options.collectionNames = options.collectionNames || [];
if (typeof options.name !== "string") {
invalidOptions.push("options.name has to be a string.");
}
if (typeof options.author !== "string") {
invalidOptions.push("options.author has to be a string.");
}
if (typeof options.description !== "string") {
invalidOptions.push("options.description has to be a string.");
}
if (typeof options.license !== "string") {
invalidOptions.push("options.license has to be a string.");
}
if (typeof options.authenticated !== "boolean") {
invalidOptions.push("options.authenticated has to be a boolean.");
}
if (!Array.isArray(options.collectionNames)) {
invalidOptions.push("options.array has to be an array.");
}
if (invalidOptions.length > 0) {
// TODO Pretty print
console.log(invalidOptions);
throw "Invalid options";
}
options.path = targetPath;
var engine = new TemplateEngine(options);
engine.write();
};
////////////////////////////////////////////////////////////////////////////////
/// @brief Extracts an app from zip and moves it to temporary path
///
@ -1761,7 +1802,7 @@ exports.initializeFoxx = function () {
if (appInfo === "EMPTY") {
// Make Empty app
throw "Not implemented yet";
installAppFromGenerator(targetPath, options || {});
} else if (/^GIT:/.test(appInfo)) {
installAppFromRemote(buildGithubUrl(appInfo), targetPath);
} else if (/^https?:/.test(appInfo)) {
@ -1785,7 +1826,7 @@ exports.initializeFoxx = function () {
////////////////////////////////////////////////////////////////////////////////
var install = function(appInfo, mount, options) {
checkParameter(
"mount(<appInfo>, <mount>, [<options>])",
"install(<appInfo>, <mount>, [<options>])",
[ [ "Install information", "string" ],
[ "Mount path", "string" ] ],
[ appInfo, mount ] );

View File

@ -1,22 +1,59 @@
/*global require, module, exports*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Foxx tempalte engine
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2013 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Lucas Dohmen
/// @author Michael Hackstein
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
(function() {
"use strict";
var fs = require("fs"),
_ = require("underscore"),
i = require('i')(),
templatePath = fs.join(
module.startupPath(),
"server",
"modules",
"org",
"arangodb",
"foxx",
"templates"
),
Engine;
Engine = function(opts) {
this.applicationContext = opts.applicationContext;
this.path = opts.path;
this._path = templatePath;
this.folder = opts.path;
this.name = opts.name;
this.authenticated = opts.authenticated;
this.author = opts.author;
this.description = opts.description;
this.license = opts.license;
this.determineFromCollectionNames(opts.collectionNames);
this._path = this.applicationContext.foxxFilename("templates");
this.folder = fs.join(this.path, this.name);
};
_.extend(Engine.prototype, {