deep-package-manager
Version:
DEEP Package Manager
187 lines (160 loc) • 3.75 kB
JavaScript
/**
* Created by AlexanderC on 5/25/15.
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Autoload = undefined;
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Autoloading directories of a microservice
*/
class Autoload {
/**
* @param {Object} rawConfig
* @param {String} basePath
*/
constructor(rawConfig, basePath) {
let frontend = _path2.default.normalize(rawConfig.frontend);
let backend = _path2.default.normalize(rawConfig.backend);
let docs = _path2.default.normalize(rawConfig.docs);
let models = _path2.default.normalize(rawConfig.models);
let validation = _path2.default.normalize(rawConfig.validation);
let fixtures = _path2.default.normalize(rawConfig.fixtures);
let migration = _path2.default.normalize(rawConfig.migration);
let roles = _path2.default.normalize(rawConfig.roles);
this._frontend = this._getBuildAwareFrontendPath(_path2.default.join(basePath, frontend));
this._backend = _path2.default.join(basePath, backend);
this._docs = _path2.default.join(basePath, docs);
this._models = _path2.default.join(basePath, models);
this._validation = _path2.default.join(basePath, validation);
this._fixtures = _path2.default.join(basePath, fixtures);
this._migration = _path2.default.join(basePath, migration);
this._roles = _path2.default.join(basePath, roles);
}
/**
* @todo think on removing this
*
* Skip _build path if exists
*/
static _skipBuild() {
Autoload.__skipBuild = true;
}
/**
* @param {String} frontendPath
* @returns {String}
* @private
*/
_getBuildAwareFrontendPath(frontendPath) {
// @todo: remove this hook
if (Autoload.__skipBuild) {
return frontendPath;
}
let buildPath = _path2.default.join(frontendPath, Autoload.BUILD_FOLDER);
try {
let buildStats = _fs2.default.lstatSync(buildPath);
if (buildStats.isDirectory()) {
return buildPath;
}
} catch (e) {
// do nothing...
}
return frontendPath;
}
/**
* Get UI directory
*
* @returns {String}
*/
get frontend() {
return this._frontend;
}
/**
* @param {String} frontend
*/
set frontend(frontend) {
this._frontend = frontend;
}
/**
* Get backend directory
*
* @returns {String}
*/
get backend() {
return this._backend;
}
/**
* Get docs directory
*
* @returns {String}
*/
get docs() {
return this._docs;
}
/**
* Get models directory
*
* @returns {String}
*/
get models() {
return this._models;
}
/**
* Get migrations directory
*
* @returns {String}
*/
get migration() {
return this._migration;
}
/**
* Get fixtures directory
*
* @returns {String}
*/
get fixtures() {
return this._fixtures;
}
/**
* Get validation schemas directory
*
* @returns {String}
*/
get validation() {
return this._validation;
}
/**
* @returns {String}
*/
get roles() {
return this._roles;
}
/**
* @returns {Object}
*/
extract() {
return {
frontend: this._frontend,
backend: this._backend,
docs: this._docs,
models: this._models,
validation: this._validation,
fixtures: this._fixtures,
migration: this._migration,
roles: this._roles
};
}
/**
* @returns {String}
*/
static get BUILD_FOLDER() {
return '_build';
}
}
exports.Autoload = Autoload;
Autoload.__skipBuild = false;