Skip to content

Commit

Permalink
Merge pull request #120 from MitocGroup/dev
Browse files Browse the repository at this point in the history
Merge dev branch
  • Loading branch information
AlexanderC committed Feb 29, 2016
2 parents d92de16 + 1011419 commit bc6999c
Show file tree
Hide file tree
Showing 106 changed files with 3,902 additions and 766 deletions.
2 changes: 1 addition & 1 deletion .jshint.airbnb.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"eqeqeq": true,
"indent": 2,
"latedef": true,
"maxlen": 80,
"maxlen": 120,
"newcap": true,
"quotmark": "single",
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false
node_js:
- '0.12'
- '4.2'
- '5.3'
- '5.7'
cache:
directories:
- "$(npm root -g)"
Expand Down
1 change: 1 addition & 0 deletions src/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ test
tests
/lib
.gitignore
coverage
20 changes: 20 additions & 0 deletions src/bin/commands/assets/migration_tpl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Generated by deepify v{version}
*
* {date}
*/

'use strict';

module.exports = {
up: function(db, cb) {
// Your code goes here ...

cb();
},
down: function(db, cb) { // OPTIONAL
// Your code goes here ...

cb();
},
};
2 changes: 1 addition & 1 deletion src/bin/commands/build-frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(mainPath) {
var Config = require('deep-package-manager').Property_Config;
var Exec = require('../../lib.compiled/Helpers/Exec').Exec;

if (mainPath.indexOf('/') !== 0) {
if (mainPath.indexOf(path.sep) !== 0) {
mainPath = path.join(process.cwd(), mainPath);
}

Expand Down
7 changes: 6 additions & 1 deletion src/bin/commands/compile-es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

module.exports = function(mainPath) {
var path = require('path');
var os = require('os');
var Exec = require('../../lib.compiled/Helpers/Exec').Exec;

if (mainPath.indexOf('/') !== 0) {
var regExp = /(`\s*pwd\s*`|\$\(\s*pwd\s*\))/ig;

mainPath = mainPath.replace(regExp, process.cwd());

if (mainPath.indexOf(path.sep) !== 0 && os.type() !== 'Windows_NT') {
mainPath = path.join(process.cwd(), mainPath);
}

Expand Down
78 changes: 49 additions & 29 deletions src/bin/commands/compile-prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ module.exports = function(mainPath) {
var fs = require('fs');
var Exec = require('../../lib.compiled/Helpers/Exec').Exec;
var LambdaExtractor = require('../../lib.compiled/Helpers/LambdasExtractor').LambdasExtractor;
var ValidationSchemasSync = require('../../lib.compiled/Helpers/ValidationSchemasSync').ValidationSchemasSync;
var DepsTreeOptimizer = require('../../lib.compiled/NodeJS/DepsTreeOptimizer').DepsTreeOptimizer;
var NpmInstall = require('../../lib.compiled/NodeJS/NpmInstall').NpmInstall;
var NpmInstallLibs = require('../../lib.compiled/NodeJS/NpmInstallLibs').NpmInstallLibs;
var NpmPrune = require('../../lib.compiled/NodeJS/NpmPrune').NpmPrune;
var NpmDedupe = require('../../lib.compiled/NodeJS/NpmDedupe').NpmDedupe;
var NpmRun = require('../../lib.compiled/NodeJS/NpmRun').NpmRun;
var NpmChain = require('../../lib.compiled/NodeJS/NpmChain').NpmChain;
var Bin = require('../../lib.compiled/NodeJS/Bin').Bin;
Expand All @@ -29,21 +29,24 @@ module.exports = function(mainPath) {
var installSdk = this.opts.locate('aws-sdk').exists;
var microservicesToDeploy = this.opts.locate('partial').value;

if (mainPath.indexOf('/') !== 0) {
if (mainPath.indexOf(path.sep) !== 0) {
mainPath = path.join(process.cwd(), mainPath);
}

var property = new Property(mainPath);
property.microservicesToUpdate = getMicroservicesToDeploy();

var microservices = property.workingMicroservices;
var lambdas = {
path: [],
tmpPath: [],
};

lambdas.path = arrayUnique(new LambdaExtractor(property).extractWorking(LambdaExtractor.NPM_PACKAGE_FILTER));

console.log('Sync validation schemas into ' + lambdas.path.length + ' Lambdas');

new ValidationSchemasSync(property).syncWorking(ValidationSchemasSync.NPM_PACKAGE_FILTER);

for (var i in lambdas.path) {
if (!lambdas.path.hasOwnProperty(i)) {
continue;
Expand Down Expand Up @@ -96,17 +99,8 @@ module.exports = function(mainPath) {
}.bind(this), lambdas);

function prepareSources(cb, lambdas) {
var wait = new WaitFor();
var remaining = lambdas.path.length;

console.log(lambdas.path.length + ' Lambdas sources are going to be copied...');

wait.push(function() {
return remaining <= 0;
}.bind(this));

wait.ready(cb);

for (var i in lambdas.path) {
if (!lambdas.path.hasOwnProperty(i)) {
continue;
Expand All @@ -121,22 +115,22 @@ module.exports = function(mainPath) {
fse.removeSync(lambdaTmpPath);
}

fse.copy(lambdaPath, lambdaTmpPath, function(lambdaTmpPath, i, error) {
if (error) {
console.error(error);
try {
fse.copySync(lambdaPath, lambdaTmpPath);

lambdas.splice(i, 1);
} else {
var nodeModules = path.join(lambdaTmpPath, 'node_modules');
var nodeModules = path.join(lambdaTmpPath, 'node_modules');

if (fs.existsSync(nodeModules)) {
fse.removeSync(nodeModules);
}
if (fs.existsSync(nodeModules)) {
fse.removeSync(nodeModules);
}
} catch (error) {
console.error(error);

remaining--;
}.bind(this, lambdaTmpPath, i));
lambdas.splice(i, 1);
}
}

cb();
}

function optimize(cb, lambdas, final) {
Expand Down Expand Up @@ -182,19 +176,34 @@ module.exports = function(mainPath) {
}

function optimizeDeps(cb, lambdas) {
if (lambdas.tmpPath.length <= 0) {
cb();
return;
}

_optimizeDepsChunk(
NpmInstall._chunkArray(lambdas.tmpPath, NpmInstall.DEFAULT_CHUNK_SIZE),
cb,
lambdas
);
}

function _optimizeDepsChunk(chunks, cb, lambdas) {
var chunk = chunks.shift();

var wait = new WaitFor();
var remaining = lambdas.tmpPath.length;
var remaining = chunk.length;

wait.push(function() {
return remaining <= 0;
}.bind(this));

for (var i in lambdas.tmpPath) {
if (!lambdas.tmpPath.hasOwnProperty(i)) {
for (var i in chunk) {
if (!chunk.hasOwnProperty(i)) {
continue;
}

var lambdaTmpPath = lambdas.tmpPath[i];
var lambdaTmpPath = chunk[i];

console.log('Optimizing Lambda dependencies in ' + lambdaTmpPath);

Expand All @@ -210,7 +219,11 @@ module.exports = function(mainPath) {
}

wait.ready(function() {
optimize.bind(this)(cb, lambdas, true);
if (chunks.length <= 0) {
optimize.bind(this)(cb, lambdas, true);
} else {
_optimizeDepsChunk(chunks, cb, lambdas);
}
}.bind(this));
}

Expand Down Expand Up @@ -278,6 +291,11 @@ module.exports = function(mainPath) {
path.basename(lambdaPath) + '.zip'
);

if (fs.existsSync(outputFile)) {
console.log('Removing old Lambda build ' + outputFile);
fse.removeSync(outputFile);
}

console.log('Packing Lambda code into ' + outputFile + ' (' + lambdaTmpPath + ')');

// @todo: replace this with a node native
Expand Down Expand Up @@ -316,7 +334,9 @@ module.exports = function(mainPath) {

function arrayUnique(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
if (p.indexOf(c) < 0) {
p.push(c);
}
return p;
}, []);
}
Expand Down
32 changes: 32 additions & 0 deletions src/bin/commands/create-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node
/**
* Created by AlexanderC on 8/4/15.
*/

'use strict';

module.exports = function(microservicePath) {
var path = require('path');
var fs = require('fs');
var fse = require('fs-extra');
var Microservice = require('deep-package-manager').Microservice_Instance;

if (microservicePath.indexOf(path.sep) !== 0) {
microservicePath = path.join(process.cwd(), microservicePath);
}

var ms = Microservice.create(microservicePath);
var migrationsPath = ms.autoload.migration;

var migrationTpl = fs.readFileSync(path.join(__dirname, 'assets', 'migration_tpl.txt')).toString();
var migrationFile = path.join(migrationsPath, 'Version' + (new Date()).getTime() + '.js');

console.log('Creating migration in ' + migrationFile);

fse.outputFileSync(
migrationFile,
migrationTpl
.replace('{version}', this.version)
.replace('{date}', new Date().toLocaleString())
);
};
Loading

0 comments on commit bc6999c

Please sign in to comment.