UNPKG

deepify

Version:
135 lines (102 loc) 3.34 kB
/** * Created by AlexanderC on 1/26/16. */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationSchemasSync = undefined; var _path = require('path'); var _path2 = _interopRequireDefault(_path); var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); var _fsExtra = require('fs-extra'); var _fsExtra2 = _interopRequireDefault(_fsExtra); var _deepCore = require('deep-core'); var _deepCore2 = _interopRequireDefault(_deepCore); var _deepPackageManager = require('deep-package-manager'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class ValidationSchemasSync { /** * @param {Property} property */ constructor(property) { this._property = property; } /** * @param {Server} server * @returns {ValidationSchemasSync} */ static createFromServer(server) { return new this(server.property); } /** * @returns {Property} */ get property() { return this._property; } /** * @param {Function|null} filter * @returns {ValidationSchemasSync} */ syncWorking(filter = null) { return ValidationSchemasSync._sync(this._property.workingMicroservices, filter); } /** * @param {Function|null} filter * @returns {ValidationSchemasSync} */ sync(filter = null) { return ValidationSchemasSync._sync(this._property.microservices, filter); } /** * @param {Object} microservices * @param {Function|null} filter * @returns {ValidationSchemasSync} */ static _sync(microservices, filter = null) { let lambdas = []; let validationSchemasDirs = []; for (let i in microservices) { if (!microservices.hasOwnProperty(i)) { continue; } let microservice = microservices[i]; validationSchemasDirs.push(microservice.autoload.validation); for (let j in microservice.resources.actions) { if (!microservice.resources.actions.hasOwnProperty(j)) { continue; } let microserviceRoute = microservice.resources.actions[j]; if (microserviceRoute.type === _deepPackageManager.Microservice_Metadata_Action.LAMBDA) { let lambdaPath = _path2.default.join(microservice.autoload.backend, microserviceRoute.source); lambdas.push(lambdaPath); } } } let validationSchemas = _deepPackageManager.Property_ValidationSchema.create(...validationSchemasDirs); lambdas = filter ? lambdas.filter(filter) : lambdas; lambdas.forEach(lambdaPath => { let schemasPath = _path2.default.join(lambdaPath, _deepCore2.default.AWS.Lambda.Runtime.VALIDATION_SCHEMAS_DIR); if (_fs2.default.existsSync(schemasPath)) { _fsExtra2.default.removeSync(schemasPath); } validationSchemas.forEach(schema => { let schemaPath = schema.schemaPath; let destinationSchemaPath = _path2.default.join(schemasPath, `${schema.name}.js`); _fsExtra2.default.copySync(schemaPath, destinationSchemaPath); }); }); return this; } /** * @returns {Function} */ static get NPM_PACKAGE_FILTER() { return lambdaPath => { return _fs2.default.existsSync(_path2.default.join(lambdaPath, 'package.json')); }; } } exports.ValidationSchemasSync = ValidationSchemasSync;