/**
* @file Apeman app configuration file.
* @namespace apemanfile
* @param {object} apeman - Apeman module.
* @returns {object} - An apeman file object.
* @see {@link http://www.npmjs.org/package/apeman | apeman}
* @author {{whoami}}
*
*/
var path = require('path');

function requireSafely(moduleId){
try{
return require(moduleId);
} catch (e) {
return null;
}
}

module.exports = (function (apeman) {
var cwd = process.cwd();
process.chdir(__dirname);

var Apemanfile = apeman.ApemanfileObject,
prototypePath = apeman.findupApp('{{prototype}}'),
prototype = require(prototypePath)(apeman),
basedir = __dirname;

//Create a new apeman file object.
var apemanfile = new Apemanfile(
prototype
).set({
basedir: basedir,
prototypePath: prototypePath,
meta: requireSafely('./ci/config/meta-config') || prototype.meta(),
tasks: requireSafely('./ci/tasks') || prototype.tasks()
});
process.chdir(cwd);
return  apemanfile;
});