From 43122c109b390cf9baace83783f22347154d6262 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 12 Jan 2016 17:29:52 +0200 Subject: [PATCH 001/133] Add new bash scripts --- bin/compile.sh | 5 +++++ bin/obfuscate-compiled.sh | 7 +++++++ bin/test.sh | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 bin/compile.sh create mode 100644 bin/obfuscate-compiled.sh create mode 100644 bin/test.sh diff --git a/bin/compile.sh b/bin/compile.sh new file mode 100644 index 00000000..8729b3ac --- /dev/null +++ b/bin/compile.sh @@ -0,0 +1,5 @@ +if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ]; then + BABEL_ENV=production babel lib/ --out-dir lib.compiled/; +elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ]; then + echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" +fi diff --git a/bin/obfuscate-compiled.sh b/bin/obfuscate-compiled.sh new file mode 100644 index 00000000..35ef6971 --- /dev/null +++ b/bin/obfuscate-compiled.sh @@ -0,0 +1,7 @@ +if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ]; then + npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; +elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ]; then + echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" +elseif [ -d 'lib/' ] && [ "$OSTYPE" == "msys" ] + echo "Running obfuscate-compiled from git-bash without results" +fi diff --git a/bin/test.sh b/bin/test.sh new file mode 100644 index 00000000..28a0076e --- /dev/null +++ b/bin/test.sh @@ -0,0 +1,8 @@ +if [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ]; then + babel-node `which isparta` cover --include 'lib/**/*.js' _mocha -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive +elif [ "$OSTYPE" == "win32" ]; then + echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" +else + echo "Running from git-bash without gathering coverage" + mocha --ui tdd --compilers js:mocha-babel --recursive --reporter spec +fi From 88d1f0e10b5dee68166468044f8f26593e8b5044 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 10:59:31 +0200 Subject: [PATCH 002/133] Refactor bash scripts --- {bin => src/bin}/compile.sh | 0 {bin => src/bin}/obfuscate-compiled.sh | 0 {bin => src/bin}/test.sh | 0 src/package.json | 11 ++++------- 4 files changed, 4 insertions(+), 7 deletions(-) rename {bin => src/bin}/compile.sh (100%) rename {bin => src/bin}/obfuscate-compiled.sh (100%) rename {bin => src/bin}/test.sh (100%) diff --git a/bin/compile.sh b/src/bin/compile.sh similarity index 100% rename from bin/compile.sh rename to src/bin/compile.sh diff --git a/bin/obfuscate-compiled.sh b/src/bin/obfuscate-compiled.sh similarity index 100% rename from bin/obfuscate-compiled.sh rename to src/bin/obfuscate-compiled.sh diff --git a/bin/test.sh b/src/bin/test.sh similarity index 100% rename from bin/test.sh rename to src/bin/test.sh diff --git a/src/package.json b/src/package.json index ea9aa9c1..12c078f1 100644 --- a/src/package.json +++ b/src/package.json @@ -48,10 +48,10 @@ }, "scripts": { "preinstall": "npm run compile", - "postinstall": "hooks/autocomplete_deepify.sh", - "test": "babel-node `which isparta` cover --include 'lib/**/*.js' _mocha -- 'test/**/*.js' --reporter spec --ui tdd", - "compile": "if [ -d 'lib/' ]; then BABEL_ENV=production babel lib/ --out-dir lib.compiled/; fi", - "obfuscate-compiled": "if [ -d 'lib/' ]; then npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; fi", + "postinstall": "bash hooks/autocomplete_deepify.sh", + "test": "bash bin/test.sh", + "compile": "bash bin/compile.sh", + "obfuscate-compiled": "bash bin/obfuscate-compiled.sh", "prepublish": "npm run obfuscate-compiled" }, "dependencies": { @@ -78,9 +78,6 @@ "node": ">=0.12 <5.0", "npm": ">=2.10 <3.0" }, - "os": [ - "!win32" - ], "preferGlobal": true, "analyze": true } From c2c8a2060ba76cb44afdb947b1a1d1e52bc5131a Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 15:24:49 +0200 Subject: [PATCH 003/133] Add x64 --- src/bin/compile.sh | 5 +++-- src/bin/deepify.js | 2 +- src/bin/obfuscate-compiled.sh | 4 ++-- src/bin/test.sh | 4 ++-- src/package.json | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bin/compile.sh b/src/bin/compile.sh index 8729b3ac..eb600c34 100644 --- a/src/bin/compile.sh +++ b/src/bin/compile.sh @@ -1,5 +1,6 @@ -if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ]; then +if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then BABEL_ENV=production babel lib/ --out-dir lib.compiled/; -elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ]; then +elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ] && [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" fi + diff --git a/src/bin/deepify.js b/src/bin/deepify.js index 30f0d0da..96d1efe5 100755 --- a/src/bin/deepify.js +++ b/src/bin/deepify.js @@ -35,7 +35,7 @@ for (var cmdName in manifest.commands) { } var optData = cmdData.opts[optName]; - + console.log('cmd.opts.create: ', JSON.stringify(optData) ); cmd.opts .create(optName, optData.alias, optData.description, optData.required); } diff --git a/src/bin/obfuscate-compiled.sh b/src/bin/obfuscate-compiled.sh index 35ef6971..3f0f98eb 100644 --- a/src/bin/obfuscate-compiled.sh +++ b/src/bin/obfuscate-compiled.sh @@ -1,6 +1,6 @@ -if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ]; then +if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; -elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ]; then +elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ] && [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" elseif [ -d 'lib/' ] && [ "$OSTYPE" == "msys" ] echo "Running obfuscate-compiled from git-bash without results" diff --git a/src/bin/test.sh b/src/bin/test.sh index 28a0076e..c4b5b43e 100644 --- a/src/bin/test.sh +++ b/src/bin/test.sh @@ -1,6 +1,6 @@ -if [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ]; then +if [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then babel-node `which isparta` cover --include 'lib/**/*.js' _mocha -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive -elif [ "$OSTYPE" == "win32" ]; then +elif [ "$OSTYPE" == "win32" ] && [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" else echo "Running from git-bash without gathering coverage" diff --git a/src/package.json b/src/package.json index 12c078f1..7fb71ccb 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "^1.x.x", + "deep-package-manager": "file:../../deep-package-manager/src", "deep-log": "^1.x.x", "deep-db": "^1.x.x", "deep-core": "^1.x.x", From 4d728ac58a5e4df3d73f8945743617f55cd0a680 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 15:35:54 +0200 Subject: [PATCH 004/133] Fix bashes --- src/bin/compile.sh | 2 +- src/bin/obfuscate-compiled.sh | 2 +- src/bin/test.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/compile.sh b/src/bin/compile.sh index eb600c34..da29c5ef 100644 --- a/src/bin/compile.sh +++ b/src/bin/compile.sh @@ -1,6 +1,6 @@ if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then BABEL_ENV=production babel lib/ --out-dir lib.compiled/; -elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ] && [ "$OSTYPE" == "win64" ]; then +elif [ -d 'lib/' ] && [[ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" fi diff --git a/src/bin/obfuscate-compiled.sh b/src/bin/obfuscate-compiled.sh index 3f0f98eb..7f5f158e 100644 --- a/src/bin/obfuscate-compiled.sh +++ b/src/bin/obfuscate-compiled.sh @@ -1,6 +1,6 @@ if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; -elif [ -d 'lib/' ] && [ "$OSTYPE" == "win32" ] && [ "$OSTYPE" == "win64" ]; then +elif [ -d 'lib/' ] && [[ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" elseif [ -d 'lib/' ] && [ "$OSTYPE" == "msys" ] echo "Running obfuscate-compiled from git-bash without results" diff --git a/src/bin/test.sh b/src/bin/test.sh index c4b5b43e..cdd80647 100644 --- a/src/bin/test.sh +++ b/src/bin/test.sh @@ -1,6 +1,6 @@ if [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then babel-node `which isparta` cover --include 'lib/**/*.js' _mocha -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive -elif [ "$OSTYPE" == "win32" ] && [ "$OSTYPE" == "win64" ]; then +elif [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" else echo "Running from git-bash without gathering coverage" From b713dd4017c82f756eb7271ede12c87af6295602 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 15:42:46 +0200 Subject: [PATCH 005/133] Update deep-package-manager version --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 7fb71ccb..12c078f1 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "file:../../deep-package-manager/src", + "deep-package-manager": "^1.x.x", "deep-log": "^1.x.x", "deep-db": "^1.x.x", "deep-core": "^1.x.x", From 747046be9186b275c525d7eb9e85317f0ea2ab19 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 15:50:59 +0200 Subject: [PATCH 006/133] Fix issues --- src/bin/compile.sh | 2 +- src/bin/obfuscate-compiled.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/compile.sh b/src/bin/compile.sh index da29c5ef..13a59c56 100644 --- a/src/bin/compile.sh +++ b/src/bin/compile.sh @@ -1,6 +1,6 @@ if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then BABEL_ENV=production babel lib/ --out-dir lib.compiled/; -elif [ -d 'lib/' ] && [[ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]]; then +elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" fi diff --git a/src/bin/obfuscate-compiled.sh b/src/bin/obfuscate-compiled.sh index 7f5f158e..2ef771e3 100644 --- a/src/bin/obfuscate-compiled.sh +++ b/src/bin/obfuscate-compiled.sh @@ -1,6 +1,6 @@ if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; -elif [ -d 'lib/' ] && [[ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]]; then +elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" elseif [ -d 'lib/' ] && [ "$OSTYPE" == "msys" ] echo "Running obfuscate-compiled from git-bash without results" From edab746f49104b1403852e8c9532d4be8b05a982 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 16:11:09 +0200 Subject: [PATCH 007/133] Remove mocha-babel --- src/bin/test.sh | 2 +- test/bin/_head.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/test.sh b/src/bin/test.sh index cdd80647..362e36fe 100644 --- a/src/bin/test.sh +++ b/src/bin/test.sh @@ -4,5 +4,5 @@ elif [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" else echo "Running from git-bash without gathering coverage" - mocha --ui tdd --compilers js:mocha-babel --recursive --reporter spec + babel-node _mocha --ui tdd --recursive --reporter spec fi diff --git a/test/bin/_head.sh b/test/bin/_head.sh index a960070f..cbadb925 100644 --- a/test/bin/_head.sh +++ b/test/bin/_head.sh @@ -24,7 +24,7 @@ function eval_or_exit() { if [[ ${RET_CODE} != 0 ]] && [[ $1 == "npm run test" ]]; then #Run DEBUG_TEST_CMD command to show error in log echo "[FAILED] $1 -> try to re-run to show error in debug mode" - local DEBUG_TEST_CMD="mocha --ui tdd --compilers js:mocha-babel --recursive --reporter spec" + local DEBUG_TEST_CMD="babel-node _mocha --ui tdd --recursive --reporter spec" eval_or_exit "$DEBUG_TEST_CMD" elif [ ${RET_CODE} != 0 ]; then echo "[FAILED] $1" From def4dd7d1f2b12853b7476ec1f2397445eeb7c10 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 16:27:20 +0200 Subject: [PATCH 008/133] Fix _mocha to which mocha --- test/bin/_head.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bin/_head.sh b/test/bin/_head.sh index cbadb925..b10e47ba 100644 --- a/test/bin/_head.sh +++ b/test/bin/_head.sh @@ -24,7 +24,7 @@ function eval_or_exit() { if [[ ${RET_CODE} != 0 ]] && [[ $1 == "npm run test" ]]; then #Run DEBUG_TEST_CMD command to show error in log echo "[FAILED] $1 -> try to re-run to show error in debug mode" - local DEBUG_TEST_CMD="babel-node _mocha --ui tdd --recursive --reporter spec" + local DEBUG_TEST_CMD="babel-node `which _mocha` --ui tdd --recursive --reporter spec" eval_or_exit "$DEBUG_TEST_CMD" elif [ ${RET_CODE} != 0 ]; then echo "[FAILED] $1" From 9d155ca88842777b0d210990afda9a0ae7d77fb4 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 17:39:46 +0200 Subject: [PATCH 009/133] Change calling _mocha --- src/bin/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/test.sh b/src/bin/test.sh index 362e36fe..4d656d94 100644 --- a/src/bin/test.sh +++ b/src/bin/test.sh @@ -1,8 +1,8 @@ if [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then - babel-node `which isparta` cover --include 'lib/**/*.js' _mocha -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive + babel-node `which isparta` cover --include 'lib/**/*.js' `which _mocha` -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive elif [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" else echo "Running from git-bash without gathering coverage" - babel-node _mocha --ui tdd --recursive --reporter spec + babel-node `which _mocha` --ui tdd --recursive --reporter spec fi From b2b67072415453f7411f068231452573baadfb17 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 13 Jan 2016 17:42:43 +0200 Subject: [PATCH 010/133] Remove console.log --- src/bin/deepify.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/deepify.js b/src/bin/deepify.js index 96d1efe5..2fdf0b0e 100755 --- a/src/bin/deepify.js +++ b/src/bin/deepify.js @@ -35,7 +35,6 @@ for (var cmdName in manifest.commands) { } var optData = cmdData.opts[optName]; - console.log('cmd.opts.create: ', JSON.stringify(optData) ); cmd.opts .create(optName, optData.alias, optData.description, optData.required); } From 2ef754900bbabf5c7273e8625164c3c65b44bbe2 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Thu, 14 Jan 2016 10:49:26 +0200 Subject: [PATCH 011/133] Add log --- src/bin/compile.sh | 1 - src/bin/deepify.js | 2 +- src/bin/obfuscate-compiled.sh | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bin/compile.sh b/src/bin/compile.sh index 13a59c56..ea85155a 100644 --- a/src/bin/compile.sh +++ b/src/bin/compile.sh @@ -3,4 +3,3 @@ if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" fi - diff --git a/src/bin/deepify.js b/src/bin/deepify.js index 2fdf0b0e..a26f1ed4 100755 --- a/src/bin/deepify.js +++ b/src/bin/deepify.js @@ -5,9 +5,9 @@ 'use strict'; +var path = require('path'); var Program = require('../lib.compiled/Terminal/Program').Program; var ValidationException = require('../lib.compiled/Terminal/Exception/ValidationException').ValidationException; -var path = require('path'); var manifest = require('./manifest'); diff --git a/src/bin/obfuscate-compiled.sh b/src/bin/obfuscate-compiled.sh index 2ef771e3..3408b7b2 100644 --- a/src/bin/obfuscate-compiled.sh +++ b/src/bin/obfuscate-compiled.sh @@ -2,6 +2,6 @@ if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$O npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" -elseif [ -d 'lib/' ] && [ "$OSTYPE" == "msys" ] +elif [ -d 'lib/' ] && [ "$OSTYPE" == "msys" ]; then echo "Running obfuscate-compiled from git-bash without results" fi From 176e5715bf492ad56be2b7b7f7b99a5961527538 Mon Sep 17 00:00:00 2001 From: Vitali Date: Fri, 15 Jan 2016 00:41:12 +0200 Subject: [PATCH 012/133] Enable Win --- src/lib/NodeJS/Bin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/NodeJS/Bin.js b/src/lib/NodeJS/Bin.js index 50a0c478..2ea517c1 100644 --- a/src/lib/NodeJS/Bin.js +++ b/src/lib/NodeJS/Bin.js @@ -76,7 +76,9 @@ export class Bin { */ static resolve(bin) { if (Bin._isWin) { - throw new Error('Unable to resolve a binary on win* platform'); + console.log('Resolving on windows'); + //don't fail on Win + //throw new Error('Unable to resolve a binary on win* platform'); } let cmd = new Exec('which', bin).runSync(); From bbe29a78d5b2a54f96d82adeeeee5845fcaa7bfe Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 15 Jan 2016 11:52:30 +0200 Subject: [PATCH 013/133] Rename test files --- src/test/Lambda/{Runtime.js => Runtime.spec.js} | 0 src/test/Lambda/{Thread.js => Thread.spec.js} | 0 src/test/Server/{Instance.js => Instance.spec.js} | 0 src/test/Terminal/{Argument.js => Argument.spec.js} | 0 src/test/Terminal/{Arguments.js => Arguments.spec.js} | 0 src/test/Terminal/{Help.js => Help.spec.js} | 0 src/test/Terminal/{Option.js => Option.spec.js} | 0 src/test/Terminal/{Options.js => Options.spec.js} | 0 src/test/Terminal/{Program.js => Program.spec.js} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename src/test/Lambda/{Runtime.js => Runtime.spec.js} (100%) rename src/test/Lambda/{Thread.js => Thread.spec.js} (100%) rename src/test/Server/{Instance.js => Instance.spec.js} (100%) rename src/test/Terminal/{Argument.js => Argument.spec.js} (100%) rename src/test/Terminal/{Arguments.js => Arguments.spec.js} (100%) rename src/test/Terminal/{Help.js => Help.spec.js} (100%) rename src/test/Terminal/{Option.js => Option.spec.js} (100%) rename src/test/Terminal/{Options.js => Options.spec.js} (100%) rename src/test/Terminal/{Program.js => Program.spec.js} (100%) diff --git a/src/test/Lambda/Runtime.js b/src/test/Lambda/Runtime.spec.js similarity index 100% rename from src/test/Lambda/Runtime.js rename to src/test/Lambda/Runtime.spec.js diff --git a/src/test/Lambda/Thread.js b/src/test/Lambda/Thread.spec.js similarity index 100% rename from src/test/Lambda/Thread.js rename to src/test/Lambda/Thread.spec.js diff --git a/src/test/Server/Instance.js b/src/test/Server/Instance.spec.js similarity index 100% rename from src/test/Server/Instance.js rename to src/test/Server/Instance.spec.js diff --git a/src/test/Terminal/Argument.js b/src/test/Terminal/Argument.spec.js similarity index 100% rename from src/test/Terminal/Argument.js rename to src/test/Terminal/Argument.spec.js diff --git a/src/test/Terminal/Arguments.js b/src/test/Terminal/Arguments.spec.js similarity index 100% rename from src/test/Terminal/Arguments.js rename to src/test/Terminal/Arguments.spec.js diff --git a/src/test/Terminal/Help.js b/src/test/Terminal/Help.spec.js similarity index 100% rename from src/test/Terminal/Help.js rename to src/test/Terminal/Help.spec.js diff --git a/src/test/Terminal/Option.js b/src/test/Terminal/Option.spec.js similarity index 100% rename from src/test/Terminal/Option.js rename to src/test/Terminal/Option.spec.js diff --git a/src/test/Terminal/Options.js b/src/test/Terminal/Options.spec.js similarity index 100% rename from src/test/Terminal/Options.js rename to src/test/Terminal/Options.spec.js diff --git a/src/test/Terminal/Program.js b/src/test/Terminal/Program.spec.js similarity index 100% rename from src/test/Terminal/Program.js rename to src/test/Terminal/Program.spec.js From 7ba58180041e0c265cbc4927b84b9699bf5a58e0 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 15 Jan 2016 11:53:23 +0200 Subject: [PATCH 014/133] Add last version of node --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5f0328b4..99d331b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ node_js: - '0.12' - '4.2' - '5.3' + - '5.4' cache: directories: - "$(npm root -g)" From 5fabad2bfd78716db76ac21219ae321f2094d179 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 18 Jan 2016 12:18:33 +0200 Subject: [PATCH 015/133] Use LFS on dev server --- src/lib/Server/Instance.js | 149 ++++++++++++++++++++++++++----------- src/package.json | 1 + 2 files changed, 105 insertions(+), 45 deletions(-) diff --git a/src/lib/Server/Instance.js b/src/lib/Server/Instance.js index 60a73aa2..716a452a 100644 --- a/src/lib/Server/Instance.js +++ b/src/lib/Server/Instance.js @@ -21,6 +21,7 @@ import {Property_Frontend as Frontend} from 'deep-package-manager'; import {Microservice_Metadata_Action as Action} from 'deep-package-manager'; import {Property_Config as Config} from 'deep-package-manager'; import DeepDB from 'deep-db'; +import DeepFS from 'deep-fs'; import {Hook} from './Hook'; export class Instance { @@ -37,6 +38,8 @@ export class Instance { }; this._property = property; this._server = null; + this._fs = null; + this._host = null; this._localId = 0; @@ -54,6 +57,13 @@ export class Instance { this._setup(); } + /** + * @returns {DeepFS} + */ + get fs() { + return this._fs; + } + /** * @returns {String} */ @@ -235,6 +245,41 @@ export class Instance { return new Instance(new Property(mainPath, configFile)); } + /** + * @returns {Object} + * @private + */ + get _kernelMock() { + let lambdasArns = Object.keys(this._defaultLambdasConfig); + + let kernel = { + config: { + buckets: { + system: { + name: '' + }, + public: { + name: '' + }, + temp: { + name: '' + } + }, + }, + microservice: () => { + return { + identifier: '', + }; + }, + }; + + if (lambdasArns.length > 0) { + kernel.config = this._defaultLambdasConfig[lambdasArns[0]]; + } + + return kernel; + } + /** * @param {Number} port * @param {String} dbServer @@ -245,56 +290,63 @@ export class Instance { let hook = new Hook(this); hook.runBefore(() => { - this._log(`Creating server on port ${port}`); + this._log('Booting local FS'); - this._server = Http.createServer((...args) => { - this._handler(...args); - }); + this._fs = new DeepFS(); + this._fs.localBackend = true; - var localDbInstance = null; + this._fs.boot(this._kernelMock, () => { + this._log(`Creating server on port ${port}`); - this._server.listen(port, (error) => { - if (error) { - throw new FailedToStartServerException(port, error); - } + this._server = Http.createServer((...args) => { + this._handler(...args); + }); - this._host = `http://localhost:${port}`; + var localDbInstance = null; - this._log('HTTP Server is up and running!'); + this._server.listen(port, (error) => { + if (error) { + throw new FailedToStartServerException(port, error); + } - if (!dbServer) { - hook.runAfter(() => { - callback(this); - }); + this._host = `http://localhost:${port}`; - return; - } + this._log('HTTP Server is up and running!'); - this._log(`Creating local DynamoDB instance on port ${DeepDB.LOCAL_DB_PORT}`); + if (!dbServer) { + hook.runAfter(() => { + callback(this); + }); - localDbInstance = DeepDB.startLocalDynamoDBServer((error) => { - if (error) { - throw new FailedToStartServerException(port, error); + return; } - this._log(`You can access DynamoDB Console via http://localhost:${DeepDB.LOCAL_DB_PORT}/shell`); + this._log(`Creating local DynamoDB instance on port ${DeepDB.LOCAL_DB_PORT}`); - hook.runAfter(() => { - callback(this); - }); - }, dbServer); - }); + localDbInstance = DeepDB.startLocalDynamoDBServer((error) => { + if (error) { + throw new FailedToStartServerException(port, error); + } - // @todo: move it in destructor? - process.on('exit', () => { - this.stop(() => { - if (localDbInstance) { - localDbInstance.stop(() => { - process.exit(0); + this._log(`You can access DynamoDB Console via http://localhost:${DeepDB.LOCAL_DB_PORT}/shell`); + + hook.runAfter(() => { + callback(this); }); - } else { - process.exit(0); - } + }, dbServer); + }); + + // @todo: move it in destructor? + process.on('exit', () => { + this.stop(() => { + if (localDbInstance) { + localDbInstance.stop(() => { + process.exit(0); + }); + } else { + process.exit(0); + } + }); }); }); }); @@ -449,14 +501,21 @@ export class Instance { return; } - FileSystem.exists(filename, function(exists) { + FileSystem.exists(filename, (exists) => { if (!exists) { - this._log(`File ${filename} not found`); - this._send404(response); - return; + if (this._fs.public.existsSync(uri)) { + filename = Path.join(this._fs.public._rootFolder, uri); + + this._log(`{LFS} ${uri} resolved into ${filename}`); + } else { + this._log(`File ${filename} not found`); + this._send404(response); + + return; + } } - FileSystem.stat(filename, function(error, stats) { + FileSystem.stat(filename, (error, stats) => { if (error) { this._log(`Unable to stat file ${filename}: ${error}`); this._send500(response, error); @@ -469,7 +528,7 @@ export class Instance { filename = Path.join(filename, 'index.html'); } - FileSystem.readFile(filename, 'binary', function(error, file) { + FileSystem.readFile(filename, 'binary', (error, file) => { if (error) { this._log(`Unable to read file ${filename}: ${error}`); this._send500(response, error); @@ -480,9 +539,9 @@ export class Instance { this._log(`Serving file ${filename} of type ${mimeType}`); this._send(response, file, 200, mimeType, true); - }.bind(this)); - }.bind(this)); - }.bind(this)); + }); + }); + }); } /** diff --git a/src/package.json b/src/package.json index ea9aa9c1..4a82a3f8 100644 --- a/src/package.json +++ b/src/package.json @@ -57,6 +57,7 @@ "dependencies": { "deep-package-manager": "^1.x.x", "deep-log": "^1.x.x", + "deep-fs": "^1.x.x", "deep-db": "^1.x.x", "deep-core": "^1.x.x", "proxyquire": "^1.5.x", From 388e1cdf9fb5818554c955d0058e88fa32e539bc Mon Sep 17 00:00:00 2001 From: Vitali Date: Mon, 18 Jan 2016 12:23:56 +0200 Subject: [PATCH 016/133] Add logging --- src/bin/commands/build-frontend.js | 1 + src/bin/commands/compile-es6.js | 1 + src/bin/commands/compile-prod.js | 1 + src/bin/commands/deploy.js | 1 + src/bin/commands/helloworld.js | 2 +- src/bin/commands/init-backend.js | 6 +++++- src/bin/commands/install.js | 1 + src/bin/commands/pull-deps.js | 1 + src/bin/commands/push-deps.js | 1 + src/bin/commands/run-lambda.js | 1 + src/bin/commands/server.js | 1 + src/bin/commands/undeploy.js | 1 + src/lib/NodeJS/Bin.js | 8 +++++++- src/lib/NodeJS/NpmChain.js | 4 +++- src/lib/NodeJS/NpmDedupe.js | 1 + src/lib/NodeJS/NpmInstall.js | 21 ++++++++++++++++++++- src/lib/NodeJS/NpmInstallLibs.js | 1 + src/lib/NodeJS/NpmLink.js | 1 + src/lib/NodeJS/NpmListDependencies.js | 1 + src/lib/NodeJS/NpmPrune.js | 1 + src/lib/NodeJS/NpmRun.js | 1 + src/lib/NodeJS/NpmShrinkwrap.js | 1 + src/lib/NodeJS/NpmUninstallLibs.js | 1 + src/lib/NodeJS/NpmUpdate.js | 1 + src/lib/NodeJS/PackageVersionResolver.js | 1 + 25 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/bin/commands/build-frontend.js b/src/bin/commands/build-frontend.js index 58c6c5ef..c663b87a 100644 --- a/src/bin/commands/build-frontend.js +++ b/src/bin/commands/build-frontend.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting build-frontend'); var path = require('path'); var fs = require('fs'); var fse = require('fs-extra'); diff --git a/src/bin/commands/compile-es6.js b/src/bin/commands/compile-es6.js index e85f38ce..fb411231 100644 --- a/src/bin/commands/compile-es6.js +++ b/src/bin/commands/compile-es6.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting compile-es6'); var path = require('path'); var Exec = require('../../lib.compiled/Helpers/Exec').Exec; diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index 6e929f0f..003fc72c 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting compile-prod'); var path = require('path'); var fse = require('fs-extra'); var fs = require('fs'); diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 946e5d1a..1838ae47 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting deploy'); var path = require('path'); var fs = require('fs'); var fse = require('fs-extra'); diff --git a/src/bin/commands/helloworld.js b/src/bin/commands/helloworld.js index 5def3214..9b827de3 100644 --- a/src/bin/commands/helloworld.js +++ b/src/bin/commands/helloworld.js @@ -6,7 +6,7 @@ 'use strict'; module.exports = function(dumpPath) { - + console.log('Starting helloworld'); // @todo: put it anywhere in a config var helloWorldRepoUrl = 'https://github.com/MitocGroup/deep-microservices-helloworld.git'; diff --git a/src/bin/commands/init-backend.js b/src/bin/commands/init-backend.js index 97444528..48962127 100644 --- a/src/bin/commands/init-backend.js +++ b/src/bin/commands/init-backend.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting init-backend'); var path = require('path'); var Autoload = require('deep-package-manager').Microservice_Metadata_Autoload; var Property = require('deep-package-manager').Property_Instance; @@ -41,7 +42,9 @@ module.exports = function(mainPath) { } property.runInitMsHooks(function() { + console.log('run init hook cb') if (!Bin.npmModuleInstalled('aws-sdk', true)) { + console.log('in !bin.npmModuleInstalled'); var awsSdkGlobalCmd = new NpmInstallLibs(); awsSdkGlobalCmd.libs = 'aws-sdk'; awsSdkGlobalCmd.global = true; @@ -80,8 +83,9 @@ module.exports = function(mainPath) { linkCmd.libs = 'aws-sdk'; chain.add(linkCmd); - + console.log('calling chain.runChunk') chain.runChunk(function() { + console.log('in cb chain.runChunk') var lambdasConfig = property.fakeBuild(); for (var lambdaArn in lambdasConfig) { diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index 65345e98..768437b9 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(microserviceRepo, dumpPath) { + console.log('Starting install'); var fs = require('fs'); var tmp = require('tmp'); var path = require('path'); diff --git a/src/bin/commands/pull-deps.js b/src/bin/commands/pull-deps.js index 3fe4dee9..de7eec5c 100644 --- a/src/bin/commands/pull-deps.js +++ b/src/bin/commands/pull-deps.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting pull-deps'); var aws = require('aws-sdk'); var path = require('path'); var fs = require('fs'); diff --git a/src/bin/commands/push-deps.js b/src/bin/commands/push-deps.js index 18493b1a..5b39f2da 100644 --- a/src/bin/commands/push-deps.js +++ b/src/bin/commands/push-deps.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting push-deps'); var aws = require('aws-sdk'); var path = require('path'); var fs = require('fs'); diff --git a/src/bin/commands/run-lambda.js b/src/bin/commands/run-lambda.js index fcbcffbf..f7190166 100644 --- a/src/bin/commands/run-lambda.js +++ b/src/bin/commands/run-lambda.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(lambdaPath) { + console.log('Starting run-lambda'); var Runtime = require('../../lib.compiled/Lambda/Runtime').Runtime; var ForksManager = require('../../lib.compiled/Lambda/ForksManager').ForksManager; var DeepDB = require('deep-db'); diff --git a/src/bin/commands/server.js b/src/bin/commands/server.js index 6680af0c..0a9477e7 100644 --- a/src/bin/commands/server.js +++ b/src/bin/commands/server.js @@ -6,6 +6,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting server'); var path = require('path'); var LambdaExtractor = require('../../lib.compiled/Helpers/LambdasExtractor').LambdasExtractor; var NpmInstall = require('../../lib.compiled/NodeJS/NpmInstall').NpmInstall; diff --git a/src/bin/commands/undeploy.js b/src/bin/commands/undeploy.js index 89c5df14..57f69341 100644 --- a/src/bin/commands/undeploy.js +++ b/src/bin/commands/undeploy.js @@ -5,6 +5,7 @@ 'use strict'; module.exports = function(mainPath) { + console.log('Starting undeploy'); var Property = require('deep-package-manager').Property_Instance; var Config = require('deep-package-manager').Property_Config; var Undeploy = require('deep-package-manager').Provisioning_Undeploy; diff --git a/src/lib/NodeJS/Bin.js b/src/lib/NodeJS/Bin.js index 2ea517c1..067178f9 100644 --- a/src/lib/NodeJS/Bin.js +++ b/src/lib/NodeJS/Bin.js @@ -22,6 +22,7 @@ export class Bin { * @returns {Number} */ static get npmMajorVersion() { + console.log('npmMajorVersion'); let versionResult = new Exec(Bin.npm, '--version').runSync(); if (versionResult.failed) { @@ -47,7 +48,7 @@ export class Bin { } Bin._npm = Bin.resolve('npm'); - + console.log('Bin._npm here', Bin._npm); return Bin._npm; } @@ -61,10 +62,12 @@ export class Bin { try { Bin._node = Bin.resolve(Bin._envBin()); + console.log('Bin._node', Bin._node) } catch (e) { // fallback here Bin._node = Bin.resolve('node'); + console.log('catch Bin._node', Bin._node) } return Bin._node; @@ -75,6 +78,8 @@ export class Bin { * @returns {String} */ static resolve(bin) { + console.log('bin: ', bin); + if (Bin._isWin) { console.log('Resolving on windows'); //don't fail on Win @@ -82,6 +87,7 @@ export class Bin { } let cmd = new Exec('which', bin).runSync(); + console.log('cmd: ', cmd); if (cmd.failed) { throw cmd.error; diff --git a/src/lib/NodeJS/NpmChain.js b/src/lib/NodeJS/NpmChain.js index 0af3606e..7d279e4c 100644 --- a/src/lib/NodeJS/NpmChain.js +++ b/src/lib/NodeJS/NpmChain.js @@ -12,6 +12,7 @@ export class NpmChain { * @param {NpmInstall|*} commands */ constructor(...commands) { + console.log('Constructor NpmChain commands: ', commands); this._commands = commands; } @@ -57,13 +58,14 @@ export class NpmChain { * @private */ _trigger(method, cb, ...args) { + console.log('this._commands.length <= 0: ', this._commands.length <= 0) if (this._commands.length <= 0) { cb(); return; } let instance = this._commands.shift(); - + console.log('instance method: ', method); instance[method](() => { this._trigger(method, cb, ...args); }, ...args); diff --git a/src/lib/NodeJS/NpmDedupe.js b/src/lib/NodeJS/NpmDedupe.js index 191749a4..47fec675 100644 --- a/src/lib/NodeJS/NpmDedupe.js +++ b/src/lib/NodeJS/NpmDedupe.js @@ -20,6 +20,7 @@ export class NpmDedupe extends NpmInstall { * @private */ get _mainCmd() { + console.log('_mainCmd'); return `${Bin.npm} dedupe`; } } diff --git a/src/lib/NodeJS/NpmInstall.js b/src/lib/NodeJS/NpmInstall.js index ee09a5cf..031f07ad 100644 --- a/src/lib/NodeJS/NpmInstall.js +++ b/src/lib/NodeJS/NpmInstall.js @@ -13,6 +13,7 @@ export class NpmInstall { * @param {String|*} dirs */ constructor(...dirs) { + console.log('Constructor NpmInstall commands: ', dirs); // try to make it compatible with ES5 if (dirs.length === 1 && Array.isArray(dirs[0])) { dirs = dirs[0]; @@ -53,6 +54,8 @@ export class NpmInstall { * @returns {NpmInstall} */ runChunk(cb, chunkSize = NpmInstall.DEFAULT_CHUNK_SIZE, silent = NpmInstall.DEFAULT_SILENT_STATE) { + + console.log('start runChunk, chunkSize: ', chunkSize); let wait = new WaitFor(); let chunks = NpmInstall._chunkArray(this._dirs, chunkSize); let remaining = chunks.length; @@ -61,6 +64,7 @@ export class NpmInstall { return remaining <= 0; }); + console.log('chunks: ', chunks); for (let i in chunks) { if (!chunks.hasOwnProperty(i)) { continue; @@ -69,8 +73,10 @@ export class NpmInstall { let chunk = chunks[i]; let instance = this._newInstance(...chunk); + console.log('instance.constructor.name: ', instance.constructor.name); instance.run(() => { + console.log('instance.run cb, remaining: ', remaining); remaining--; }, silent); } @@ -98,6 +104,7 @@ export class NpmInstall { * @returns {NpmInstall} */ run(cb, silent = NpmInstall.DEFAULT_SILENT_STATE) { + console.log('NpmInstall run:', silent); let wait = new WaitFor(); let remaining = this._dirs.length; let cmdStack = []; @@ -106,6 +113,7 @@ export class NpmInstall { return remaining <= 0; }); + console.log('this._dirs:', this._dirs); for (let i in this._dirs) { if (!this._dirs.hasOwnProperty(i)) { continue; @@ -113,7 +121,10 @@ export class NpmInstall { let dir = this._dirs[i]; - let cmd = new Exec(...this._execArgs); + + let cmd = new Exec(...this._execArgs) + console.log('cmd:', cmd); + cmd.cwd = dir; @@ -124,8 +135,14 @@ export class NpmInstall { cmdStack.push(cmd); } + console.log('cmdStack:', cmdStack); + + cmdStack.forEach((cmd) => { + console.log('cmd.constructor.name: ', cmd.constructor.name); cmd.run((result) => { + console.log('result: ', result); + if (result.failed && !this._silent) { console.error(result.error); } @@ -144,6 +161,7 @@ export class NpmInstall { * @private */ get _execArgs() { + console.log('_execArgs: ', this._extraArgs); return [this._mainCmd, ...this._extraArgs]; } @@ -152,6 +170,7 @@ export class NpmInstall { * @private */ get _mainCmd() { + console.log('mainCmd'); return `${Bin.npm} install`; } diff --git a/src/lib/NodeJS/NpmInstallLibs.js b/src/lib/NodeJS/NpmInstallLibs.js index 337d3c11..71bec004 100644 --- a/src/lib/NodeJS/NpmInstallLibs.js +++ b/src/lib/NodeJS/NpmInstallLibs.js @@ -67,6 +67,7 @@ export class NpmInstallLibs extends NpmInstall { * @private */ get _mainCmd() { + console.log('npm install _mainCmd'); return `${Bin.npm} install ${this._libsPlain} ${this._global ? '-g' : ''}`; } } diff --git a/src/lib/NodeJS/NpmLink.js b/src/lib/NodeJS/NpmLink.js index f664046c..54031c9d 100644 --- a/src/lib/NodeJS/NpmLink.js +++ b/src/lib/NodeJS/NpmLink.js @@ -48,6 +48,7 @@ export class NpmLink extends NpmInstall { * @private */ get _mainCmd() { + console.log('npm link _mainCmd'); return `${Bin.npm} link ${this._libsPlain}`; } } diff --git a/src/lib/NodeJS/NpmListDependencies.js b/src/lib/NodeJS/NpmListDependencies.js index c513c265..98d338e8 100644 --- a/src/lib/NodeJS/NpmListDependencies.js +++ b/src/lib/NodeJS/NpmListDependencies.js @@ -29,6 +29,7 @@ export class NpmListDependencies { * @returns {NpmDependency} */ list(depth = null) { + console.log('npm deps _mainCmd'); let cmd = new Exec( `${Bin.npm} ls --json true --parseable true --loglevel silent --production`, depth ? `--depth ${depth}` : '' diff --git a/src/lib/NodeJS/NpmPrune.js b/src/lib/NodeJS/NpmPrune.js index 5cb9d859..32380922 100644 --- a/src/lib/NodeJS/NpmPrune.js +++ b/src/lib/NodeJS/NpmPrune.js @@ -20,6 +20,7 @@ export class NpmPrune extends NpmInstall { * @private */ get _mainCmd() { + console.log('npm prune _mainCmd'); return `${Bin.npm} prune`; } } diff --git a/src/lib/NodeJS/NpmRun.js b/src/lib/NodeJS/NpmRun.js index cb7707e6..7c00561a 100644 --- a/src/lib/NodeJS/NpmRun.js +++ b/src/lib/NodeJS/NpmRun.js @@ -48,6 +48,7 @@ export class NpmRun extends NpmInstall { * @private */ get _mainCmd() { + console.log('npmRun _mainCmd'); return `${Bin.npm} run ${this._cmd}`; } } diff --git a/src/lib/NodeJS/NpmShrinkwrap.js b/src/lib/NodeJS/NpmShrinkwrap.js index 6421c19d..02292d75 100644 --- a/src/lib/NodeJS/NpmShrinkwrap.js +++ b/src/lib/NodeJS/NpmShrinkwrap.js @@ -20,6 +20,7 @@ export class NpmShrinkwrap extends NpmInstall { * @private */ get _mainCmd() { + console.log('npmShrink _mainCmd'); return `${Bin.npm} shrinkwrap`; } } diff --git a/src/lib/NodeJS/NpmUninstallLibs.js b/src/lib/NodeJS/NpmUninstallLibs.js index d3a9d407..02a2efdb 100644 --- a/src/lib/NodeJS/NpmUninstallLibs.js +++ b/src/lib/NodeJS/NpmUninstallLibs.js @@ -20,6 +20,7 @@ export class NpmUninstallLibs extends NpmInstallLibs { * @private */ get _mainCmd() { + console.log('npmUninstall _mainCmd'); return `${Bin.npm} uninstall ${this._libsPlain} ${this._global ? '-g' : ''}`; } } diff --git a/src/lib/NodeJS/NpmUpdate.js b/src/lib/NodeJS/NpmUpdate.js index a6d1e22a..6d48c400 100644 --- a/src/lib/NodeJS/NpmUpdate.js +++ b/src/lib/NodeJS/NpmUpdate.js @@ -20,6 +20,7 @@ export class NpmUpdate extends NpmInstall { * @private */ get _mainCmd() { + console.log('npmUpdate _mainCmd'); return `${Bin.npm} update`; } } diff --git a/src/lib/NodeJS/PackageVersionResolver.js b/src/lib/NodeJS/PackageVersionResolver.js index d3b727a0..f9a568c0 100644 --- a/src/lib/NodeJS/PackageVersionResolver.js +++ b/src/lib/NodeJS/PackageVersionResolver.js @@ -125,6 +125,7 @@ export class PackageVersionResolver { * @private */ get _command() { + console.log('package version _mainCmd'); return `${Bin.npm} ls --loglevel silent --json ${this._fullName}`; } From 624ffd5a6f1f41e3936f6f9e927670ccd82a27df Mon Sep 17 00:00:00 2001 From: mgoria Date: Mon, 18 Jan 2016 14:50:06 +0200 Subject: [PATCH 017/133] Use AWS services instanciated by Property/Provisioning class with right region --- src/bin/commands/deploy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 946e5d1a..1d323fb0 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -129,7 +129,7 @@ module.exports = function(mainPath) { function getConfigFromS3(propertyInstance, cb) { console.log('Trying to retrieve .cfg.deeploy.json from S3 ' + cfgBucket); - var s3 = new propertyInstance.AWS.S3(); + var s3 = propertyInstance.provisioning.s3; var payload = { Bucket: cfgBucket, @@ -148,7 +148,7 @@ module.exports = function(mainPath) { } var plainConfig = JSON.stringify(propertyInstance.config); - var s3 = new propertyInstance.AWS.S3(); + var s3 = propertyInstance.provisioning.s3; var payload = { Bucket: propertyInstance.config.provisioning.s3.buckets[S3Service.SYSTEM_BUCKET].name, From f506f6135b66463d3d328526db6372bfbff829fa Mon Sep 17 00:00:00 2001 From: mgoria Date: Mon, 18 Jan 2016 15:02:10 +0200 Subject: [PATCH 018/133] Use bucket region for public site address --- src/bin/commands/deploy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 1d323fb0..337e50ea 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -516,7 +516,8 @@ module.exports = function(mainPath) { function getPublicWebsite(propertyInstance) { var config = propertyInstance.config; var bucketName = config.provisioning.s3.buckets[S3Service.PUBLIC_BUCKET].name; + var bucketRegion = propertyInstance.config.region; - return 'http://' + bucketName + '.s3-website-' + config.awsRegion + '.amazonaws.com'; + return 'http://' + bucketName + '.s3-website-' + bucketRegion + '.amazonaws.com'; } }; From 5c8f995bee3b4e858619c5a1d5da09dabf906286 Mon Sep 17 00:00:00 2001 From: mgoria Date: Mon, 18 Jan 2016 15:09:11 +0200 Subject: [PATCH 019/133] Use bucket region for public site address --- src/bin/commands/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 337e50ea..3b6f5b82 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -516,7 +516,7 @@ module.exports = function(mainPath) { function getPublicWebsite(propertyInstance) { var config = propertyInstance.config; var bucketName = config.provisioning.s3.buckets[S3Service.PUBLIC_BUCKET].name; - var bucketRegion = propertyInstance.config.region; + var bucketRegion = propertyInstance.provisioning.s3.config.region; return 'http://' + bucketName + '.s3-website-' + bucketRegion + '.amazonaws.com'; } From 5ed0e2ca45db6b5a7451764f2d4f18933caed914 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 18 Jan 2016 16:03:09 +0200 Subject: [PATCH 020/133] Fix compile prod --- src/bin/commands/compile-prod.js | 60 +++++++++++++++++++------------- src/lib/NodeJS/NpmInstall.js | 45 +++++++++++++----------- 2 files changed, 59 insertions(+), 46 deletions(-) diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index 6e929f0f..e667c694 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -96,17 +96,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; @@ -121,22 +112,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) { @@ -182,19 +173,29 @@ module.exports = function(mainPath) { } function optimizeDeps(cb, lambdas) { + _optimizeDepsChunk( + NpmInstall._chunkArray(lambdas.tmpPath, NpmInstall.DEFAULT_CHUNK_SIZE), + cb, + lambdas + ); + } + + function _optimizeDepsChunk(chunks, cb, lambdas) { + let 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); @@ -210,7 +211,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)); } @@ -278,6 +283,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 diff --git a/src/lib/NodeJS/NpmInstall.js b/src/lib/NodeJS/NpmInstall.js index ee09a5cf..6cace5ff 100644 --- a/src/lib/NodeJS/NpmInstall.js +++ b/src/lib/NodeJS/NpmInstall.js @@ -53,31 +53,34 @@ export class NpmInstall { * @returns {NpmInstall} */ runChunk(cb, chunkSize = NpmInstall.DEFAULT_CHUNK_SIZE, silent = NpmInstall.DEFAULT_SILENT_STATE) { - let wait = new WaitFor(); - let chunks = NpmInstall._chunkArray(this._dirs, chunkSize); - let remaining = chunks.length; - - wait.push(() => { - return remaining <= 0; - }); + this._runChunkItem( + NpmInstall._chunkArray(this._dirs, chunkSize), + silent, + cb + ); - for (let i in chunks) { - if (!chunks.hasOwnProperty(i)) { - continue; - } - - let chunk = chunks[i]; + return this; + } - let instance = this._newInstance(...chunk); + /** + * @param {Array} chunks + * @param {Boolean} silent + * @param {Function} cb + * @private + */ + _runChunkItem(chunks, silent, cb) { + let chunk = chunks.shift(); - instance.run(() => { - remaining--; - }, silent); - } + let instance = this._newInstance(...chunk); - wait.ready(cb); + instance.run(() => { + if (chunks.length <= 0) { + cb(); + return; + } - return this; + this._runChunkItem(chunks, silent, cb); + }, silent); } /** @@ -184,6 +187,6 @@ export class NpmInstall { * @returns {Number} */ static get DEFAULT_CHUNK_SIZE() { - return 4; + return 3; } } From c7669b4c4399eb8b537b79b04d9e3004f78f4e9e Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 18 Jan 2016 16:15:43 +0200 Subject: [PATCH 021/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 4a82a3f8..fb20b91f 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.0", + "version": "1.5.1", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 3d0d192c2dce9b66166c1e6d2b38130b15e9e007 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 18 Jan 2016 17:22:24 +0200 Subject: [PATCH 022/133] Fix typo --- src/bin/commands/compile-prod.js | 2 +- src/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index e667c694..225830af 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -181,7 +181,7 @@ module.exports = function(mainPath) { } function _optimizeDepsChunk(chunks, cb, lambdas) { - let chunk = chunks.shift(); + var chunk = chunks.shift(); var wait = new WaitFor(); var remaining = chunk.length; diff --git a/src/package.json b/src/package.json index fb20b91f..485fefc3 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.1", + "version": "1.5.2", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 459bd95654ead3c7512f3cad83a25347111e100a Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 19 Jan 2016 18:22:14 +0200 Subject: [PATCH 023/133] Add undeploy log msg --- src/bin/commands/undeploy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/commands/undeploy.js b/src/bin/commands/undeploy.js index 89c5df14..a0087d44 100644 --- a/src/bin/commands/undeploy.js +++ b/src/bin/commands/undeploy.js @@ -68,6 +68,8 @@ module.exports = function(mainPath) { } if (backupConfig) { + console.log('Create configuration backup in ' + this.fileNameBck); + matcher.bckConfigFile(function(error) { if (error) { console.error(error); From 22af322ab8968aee50e9b7655abb7ab0922ccc01 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 19 Jan 2016 19:04:54 +0200 Subject: [PATCH 024/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 485fefc3..a0d83647 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.2", + "version": "1.5.3", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From cc538b75d6db186efb90fbbdb220fb65c67aacf4 Mon Sep 17 00:00:00 2001 From: Vitali Date: Wed, 20 Jan 2016 10:59:09 +0200 Subject: [PATCH 025/133] Fix compile es6 --- src/bin/commands/compile-es6.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/compile-es6.js b/src/bin/commands/compile-es6.js index fb411231..dc2c09aa 100644 --- a/src/bin/commands/compile-es6.js +++ b/src/bin/commands/compile-es6.js @@ -9,8 +9,11 @@ module.exports = function(mainPath) { console.log('Starting compile-es6'); var path = require('path'); var Exec = require('../../lib.compiled/Helpers/Exec').Exec; + console.log('mainPath: ', mainPath); - if (mainPath.indexOf('/') !== 0) { + if (mainPath === '`pwd`') { + mainPath = process.cwd(); + } else if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } @@ -20,5 +23,5 @@ module.exports = function(mainPath) { console.error(result.error); this.exit(1); } - }.bind(this), true); + }.bind(this), false); }; From 764feb4b337f47b5433e496cf2739dca78e55a84 Mon Sep 17 00:00:00 2001 From: Vitali Date: Wed, 20 Jan 2016 14:43:46 +0200 Subject: [PATCH 026/133] Fix separate --- src/bin/compile.sh | 1 + src/bin/obfuscate-compiled.sh | 1 + src/bin/test.sh | 1 + src/lib/Server/Instance.js | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/compile.sh b/src/bin/compile.sh index ea85155a..7e75a105 100644 --- a/src/bin/compile.sh +++ b/src/bin/compile.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then BABEL_ENV=production babel lib/ --out-dir lib.compiled/; elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then diff --git a/src/bin/obfuscate-compiled.sh b/src/bin/obfuscate-compiled.sh index 3408b7b2..eafe4546 100644 --- a/src/bin/obfuscate-compiled.sh +++ b/src/bin/obfuscate-compiled.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then diff --git a/src/bin/test.sh b/src/bin/test.sh index 4d656d94..fee5458b 100644 --- a/src/bin/test.sh +++ b/src/bin/test.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash if [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then babel-node `which isparta` cover --include 'lib/**/*.js' `which _mocha` -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive elif [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then diff --git a/src/lib/Server/Instance.js b/src/lib/Server/Instance.js index 716a452a..0359363e 100644 --- a/src/lib/Server/Instance.js +++ b/src/lib/Server/Instance.js @@ -570,7 +570,7 @@ export class Instance { * @private */ _resolveMicroservice(uri) { - let parts = uri.replace(/^\/(.+)$/, '$1').split(Path.sep); + let parts = uri.replace(/^\/(.+)$/, '$1').split('/'); if (parts.length > 0) { for (let identifier in this._microservices) { From 3811916677726dba9a0d85375716b8737634bd72 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 20 Jan 2016 15:27:22 +0200 Subject: [PATCH 027/133] Add env var for windows --- src/hooks/autocomplete_deepify.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hooks/autocomplete_deepify.sh b/src/hooks/autocomplete_deepify.sh index 6967a784..544ce0da 100755 --- a/src/hooks/autocomplete_deepify.sh +++ b/src/hooks/autocomplete_deepify.sh @@ -6,6 +6,11 @@ COMPLETION_ADD=". $SCRIPT_PATH/deepify_comp.sh" IS_MAC=$(uname -a | grep Darwin) CURRENT_USER=$(whoami) +if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then + export DEEP_NO_INTERACTION=1 + echo "Added environment variable DEEP_NO_INTERACTION=1 for windows" +fi + if [ "$IS_MAC" = "" ]; then BASH_PROFILE="$HOME/.bashrc" fi From 83527eaa93cbff9b955393b45e29e03e5eac954f Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 20 Jan 2016 15:47:58 +0200 Subject: [PATCH 028/133] Remove console.log --- src/bin/commands/build-frontend.js | 1 - src/bin/commands/compile-es6.js | 2 -- src/bin/commands/compile-prod.js | 1 - src/bin/commands/deploy.js | 1 - src/bin/commands/helloworld.js | 2 +- src/bin/commands/init-backend.js | 8 +------- src/bin/commands/install.js | 1 - src/bin/commands/pull-deps.js | 1 - src/bin/commands/push-deps.js | 1 - src/bin/commands/run-lambda.js | 1 - src/bin/commands/server.js | 1 - src/bin/commands/undeploy.js | 1 - src/bin/deepify.js | 1 + src/lib/NodeJS/Bin.js | 16 +++++----------- src/lib/NodeJS/NpmChain.js | 4 +--- src/lib/NodeJS/NpmDedupe.js | 1 - src/lib/NodeJS/NpmInstallLibs.js | 1 - src/lib/NodeJS/NpmLink.js | 1 - src/lib/NodeJS/NpmListDependencies.js | 1 - src/lib/NodeJS/NpmPrune.js | 1 - src/lib/NodeJS/NpmRun.js | 1 - src/lib/NodeJS/NpmShrinkwrap.js | 1 - src/lib/NodeJS/NpmUninstallLibs.js | 1 - src/lib/NodeJS/NpmUpdate.js | 1 - src/lib/NodeJS/PackageVersionResolver.js | 1 - 25 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/bin/commands/build-frontend.js b/src/bin/commands/build-frontend.js index c663b87a..58c6c5ef 100644 --- a/src/bin/commands/build-frontend.js +++ b/src/bin/commands/build-frontend.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting build-frontend'); var path = require('path'); var fs = require('fs'); var fse = require('fs-extra'); diff --git a/src/bin/commands/compile-es6.js b/src/bin/commands/compile-es6.js index dc2c09aa..9f2d34b6 100644 --- a/src/bin/commands/compile-es6.js +++ b/src/bin/commands/compile-es6.js @@ -6,10 +6,8 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting compile-es6'); var path = require('path'); var Exec = require('../../lib.compiled/Helpers/Exec').Exec; - console.log('mainPath: ', mainPath); if (mainPath === '`pwd`') { mainPath = process.cwd(); diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index 05a96511..225830af 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting compile-prod'); var path = require('path'); var fse = require('fs-extra'); var fs = require('fs'); diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index bdd5f5f8..3b6f5b82 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting deploy'); var path = require('path'); var fs = require('fs'); var fse = require('fs-extra'); diff --git a/src/bin/commands/helloworld.js b/src/bin/commands/helloworld.js index 9b827de3..5def3214 100644 --- a/src/bin/commands/helloworld.js +++ b/src/bin/commands/helloworld.js @@ -6,7 +6,7 @@ 'use strict'; module.exports = function(dumpPath) { - console.log('Starting helloworld'); + // @todo: put it anywhere in a config var helloWorldRepoUrl = 'https://github.com/MitocGroup/deep-microservices-helloworld.git'; diff --git a/src/bin/commands/init-backend.js b/src/bin/commands/init-backend.js index 48962127..ab210033 100644 --- a/src/bin/commands/init-backend.js +++ b/src/bin/commands/init-backend.js @@ -6,11 +6,8 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting init-backend'); var path = require('path'); - var Autoload = require('deep-package-manager').Microservice_Metadata_Autoload; var Property = require('deep-package-manager').Property_Instance; - var WaitFor = require('deep-package-manager').Helpers_WaitFor; var Config = require('deep-package-manager').Property_Config; var fs = require('fs'); var fse = require('fs-extra'); @@ -42,9 +39,7 @@ module.exports = function(mainPath) { } property.runInitMsHooks(function() { - console.log('run init hook cb') if (!Bin.npmModuleInstalled('aws-sdk', true)) { - console.log('in !bin.npmModuleInstalled'); var awsSdkGlobalCmd = new NpmInstallLibs(); awsSdkGlobalCmd.libs = 'aws-sdk'; awsSdkGlobalCmd.global = true; @@ -83,9 +78,8 @@ module.exports = function(mainPath) { linkCmd.libs = 'aws-sdk'; chain.add(linkCmd); - console.log('calling chain.runChunk') + chain.runChunk(function() { - console.log('in cb chain.runChunk') var lambdasConfig = property.fakeBuild(); for (var lambdaArn in lambdasConfig) { diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index 768437b9..65345e98 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(microserviceRepo, dumpPath) { - console.log('Starting install'); var fs = require('fs'); var tmp = require('tmp'); var path = require('path'); diff --git a/src/bin/commands/pull-deps.js b/src/bin/commands/pull-deps.js index de7eec5c..3fe4dee9 100644 --- a/src/bin/commands/pull-deps.js +++ b/src/bin/commands/pull-deps.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting pull-deps'); var aws = require('aws-sdk'); var path = require('path'); var fs = require('fs'); diff --git a/src/bin/commands/push-deps.js b/src/bin/commands/push-deps.js index 5b39f2da..18493b1a 100644 --- a/src/bin/commands/push-deps.js +++ b/src/bin/commands/push-deps.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting push-deps'); var aws = require('aws-sdk'); var path = require('path'); var fs = require('fs'); diff --git a/src/bin/commands/run-lambda.js b/src/bin/commands/run-lambda.js index f7190166..fcbcffbf 100644 --- a/src/bin/commands/run-lambda.js +++ b/src/bin/commands/run-lambda.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(lambdaPath) { - console.log('Starting run-lambda'); var Runtime = require('../../lib.compiled/Lambda/Runtime').Runtime; var ForksManager = require('../../lib.compiled/Lambda/ForksManager').ForksManager; var DeepDB = require('deep-db'); diff --git a/src/bin/commands/server.js b/src/bin/commands/server.js index 0a9477e7..6680af0c 100644 --- a/src/bin/commands/server.js +++ b/src/bin/commands/server.js @@ -6,7 +6,6 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting server'); var path = require('path'); var LambdaExtractor = require('../../lib.compiled/Helpers/LambdasExtractor').LambdasExtractor; var NpmInstall = require('../../lib.compiled/NodeJS/NpmInstall').NpmInstall; diff --git a/src/bin/commands/undeploy.js b/src/bin/commands/undeploy.js index abab0897..a0087d44 100644 --- a/src/bin/commands/undeploy.js +++ b/src/bin/commands/undeploy.js @@ -5,7 +5,6 @@ 'use strict'; module.exports = function(mainPath) { - console.log('Starting undeploy'); var Property = require('deep-package-manager').Property_Instance; var Config = require('deep-package-manager').Property_Config; var Undeploy = require('deep-package-manager').Provisioning_Undeploy; diff --git a/src/bin/deepify.js b/src/bin/deepify.js index a26f1ed4..2ebb6c8c 100755 --- a/src/bin/deepify.js +++ b/src/bin/deepify.js @@ -35,6 +35,7 @@ for (var cmdName in manifest.commands) { } var optData = cmdData.opts[optName]; + cmd.opts .create(optName, optData.alias, optData.description, optData.required); } diff --git a/src/lib/NodeJS/Bin.js b/src/lib/NodeJS/Bin.js index 067178f9..e1571fbc 100644 --- a/src/lib/NodeJS/Bin.js +++ b/src/lib/NodeJS/Bin.js @@ -22,7 +22,6 @@ export class Bin { * @returns {Number} */ static get npmMajorVersion() { - console.log('npmMajorVersion'); let versionResult = new Exec(Bin.npm, '--version').runSync(); if (versionResult.failed) { @@ -48,7 +47,7 @@ export class Bin { } Bin._npm = Bin.resolve('npm'); - console.log('Bin._npm here', Bin._npm); + return Bin._npm; } @@ -62,12 +61,10 @@ export class Bin { try { Bin._node = Bin.resolve(Bin._envBin()); - console.log('Bin._node', Bin._node) } catch (e) { // fallback here Bin._node = Bin.resolve('node'); - console.log('catch Bin._node', Bin._node) } return Bin._node; @@ -78,16 +75,13 @@ export class Bin { * @returns {String} */ static resolve(bin) { - console.log('bin: ', bin); - if (Bin._isWin) { - console.log('Resolving on windows'); - //don't fail on Win - //throw new Error('Unable to resolve a binary on win* platform'); - } + //don't fail on Win + //if (Bin._isWin) { + // throw new Error('Unable to resolve a binary on win* platform'); + //} let cmd = new Exec('which', bin).runSync(); - console.log('cmd: ', cmd); if (cmd.failed) { throw cmd.error; diff --git a/src/lib/NodeJS/NpmChain.js b/src/lib/NodeJS/NpmChain.js index 7d279e4c..0af3606e 100644 --- a/src/lib/NodeJS/NpmChain.js +++ b/src/lib/NodeJS/NpmChain.js @@ -12,7 +12,6 @@ export class NpmChain { * @param {NpmInstall|*} commands */ constructor(...commands) { - console.log('Constructor NpmChain commands: ', commands); this._commands = commands; } @@ -58,14 +57,13 @@ export class NpmChain { * @private */ _trigger(method, cb, ...args) { - console.log('this._commands.length <= 0: ', this._commands.length <= 0) if (this._commands.length <= 0) { cb(); return; } let instance = this._commands.shift(); - console.log('instance method: ', method); + instance[method](() => { this._trigger(method, cb, ...args); }, ...args); diff --git a/src/lib/NodeJS/NpmDedupe.js b/src/lib/NodeJS/NpmDedupe.js index 47fec675..191749a4 100644 --- a/src/lib/NodeJS/NpmDedupe.js +++ b/src/lib/NodeJS/NpmDedupe.js @@ -20,7 +20,6 @@ export class NpmDedupe extends NpmInstall { * @private */ get _mainCmd() { - console.log('_mainCmd'); return `${Bin.npm} dedupe`; } } diff --git a/src/lib/NodeJS/NpmInstallLibs.js b/src/lib/NodeJS/NpmInstallLibs.js index 71bec004..337d3c11 100644 --- a/src/lib/NodeJS/NpmInstallLibs.js +++ b/src/lib/NodeJS/NpmInstallLibs.js @@ -67,7 +67,6 @@ export class NpmInstallLibs extends NpmInstall { * @private */ get _mainCmd() { - console.log('npm install _mainCmd'); return `${Bin.npm} install ${this._libsPlain} ${this._global ? '-g' : ''}`; } } diff --git a/src/lib/NodeJS/NpmLink.js b/src/lib/NodeJS/NpmLink.js index 54031c9d..f664046c 100644 --- a/src/lib/NodeJS/NpmLink.js +++ b/src/lib/NodeJS/NpmLink.js @@ -48,7 +48,6 @@ export class NpmLink extends NpmInstall { * @private */ get _mainCmd() { - console.log('npm link _mainCmd'); return `${Bin.npm} link ${this._libsPlain}`; } } diff --git a/src/lib/NodeJS/NpmListDependencies.js b/src/lib/NodeJS/NpmListDependencies.js index 98d338e8..c513c265 100644 --- a/src/lib/NodeJS/NpmListDependencies.js +++ b/src/lib/NodeJS/NpmListDependencies.js @@ -29,7 +29,6 @@ export class NpmListDependencies { * @returns {NpmDependency} */ list(depth = null) { - console.log('npm deps _mainCmd'); let cmd = new Exec( `${Bin.npm} ls --json true --parseable true --loglevel silent --production`, depth ? `--depth ${depth}` : '' diff --git a/src/lib/NodeJS/NpmPrune.js b/src/lib/NodeJS/NpmPrune.js index 32380922..5cb9d859 100644 --- a/src/lib/NodeJS/NpmPrune.js +++ b/src/lib/NodeJS/NpmPrune.js @@ -20,7 +20,6 @@ export class NpmPrune extends NpmInstall { * @private */ get _mainCmd() { - console.log('npm prune _mainCmd'); return `${Bin.npm} prune`; } } diff --git a/src/lib/NodeJS/NpmRun.js b/src/lib/NodeJS/NpmRun.js index 7c00561a..cb7707e6 100644 --- a/src/lib/NodeJS/NpmRun.js +++ b/src/lib/NodeJS/NpmRun.js @@ -48,7 +48,6 @@ export class NpmRun extends NpmInstall { * @private */ get _mainCmd() { - console.log('npmRun _mainCmd'); return `${Bin.npm} run ${this._cmd}`; } } diff --git a/src/lib/NodeJS/NpmShrinkwrap.js b/src/lib/NodeJS/NpmShrinkwrap.js index 02292d75..6421c19d 100644 --- a/src/lib/NodeJS/NpmShrinkwrap.js +++ b/src/lib/NodeJS/NpmShrinkwrap.js @@ -20,7 +20,6 @@ export class NpmShrinkwrap extends NpmInstall { * @private */ get _mainCmd() { - console.log('npmShrink _mainCmd'); return `${Bin.npm} shrinkwrap`; } } diff --git a/src/lib/NodeJS/NpmUninstallLibs.js b/src/lib/NodeJS/NpmUninstallLibs.js index 02a2efdb..d3a9d407 100644 --- a/src/lib/NodeJS/NpmUninstallLibs.js +++ b/src/lib/NodeJS/NpmUninstallLibs.js @@ -20,7 +20,6 @@ export class NpmUninstallLibs extends NpmInstallLibs { * @private */ get _mainCmd() { - console.log('npmUninstall _mainCmd'); return `${Bin.npm} uninstall ${this._libsPlain} ${this._global ? '-g' : ''}`; } } diff --git a/src/lib/NodeJS/NpmUpdate.js b/src/lib/NodeJS/NpmUpdate.js index 6d48c400..a6d1e22a 100644 --- a/src/lib/NodeJS/NpmUpdate.js +++ b/src/lib/NodeJS/NpmUpdate.js @@ -20,7 +20,6 @@ export class NpmUpdate extends NpmInstall { * @private */ get _mainCmd() { - console.log('npmUpdate _mainCmd'); return `${Bin.npm} update`; } } diff --git a/src/lib/NodeJS/PackageVersionResolver.js b/src/lib/NodeJS/PackageVersionResolver.js index f9a568c0..d3b727a0 100644 --- a/src/lib/NodeJS/PackageVersionResolver.js +++ b/src/lib/NodeJS/PackageVersionResolver.js @@ -125,7 +125,6 @@ export class PackageVersionResolver { * @private */ get _command() { - console.log('package version _mainCmd'); return `${Bin.npm} ls --loglevel silent --json ${this._fullName}`; } From 5a7c8ad19eee423dbae70ede4fd48de563a8b69f Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 20 Jan 2016 15:53:09 +0200 Subject: [PATCH 029/133] Undo changes for deepify --- src/bin/deepify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/deepify.js b/src/bin/deepify.js index 2ebb6c8c..30f0d0da 100755 --- a/src/bin/deepify.js +++ b/src/bin/deepify.js @@ -5,9 +5,9 @@ 'use strict'; -var path = require('path'); var Program = require('../lib.compiled/Terminal/Program').Program; var ValidationException = require('../lib.compiled/Terminal/Exception/ValidationException').ValidationException; +var path = require('path'); var manifest = require('./manifest'); From c8994233fd407dca6021327c8176e0384496708b Mon Sep 17 00:00:00 2001 From: Vitali Date: Wed, 20 Jan 2016 19:05:31 +0200 Subject: [PATCH 030/133] Relative path --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 828c1d61..553c21a0 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "^1.x.x", + "deep-package-manager": "file:../../deep-package-manager/src", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From d558cbb2167976805501451dfb89ca1588b6de1c Mon Sep 17 00:00:00 2001 From: Vitali Date: Wed, 20 Jan 2016 19:08:47 +0200 Subject: [PATCH 031/133] Fix intalling env vars --- src/hooks/autocomplete_deepify.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/autocomplete_deepify.sh b/src/hooks/autocomplete_deepify.sh index 544ce0da..84760e68 100755 --- a/src/hooks/autocomplete_deepify.sh +++ b/src/hooks/autocomplete_deepify.sh @@ -6,7 +6,7 @@ COMPLETION_ADD=". $SCRIPT_PATH/deepify_comp.sh" IS_MAC=$(uname -a | grep Darwin) CURRENT_USER=$(whoami) -if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then +if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "msys" ]; then export DEEP_NO_INTERACTION=1 echo "Added environment variable DEEP_NO_INTERACTION=1 for windows" fi From f32f5d800023be30cff6e53eaa5e9ee15fcd96d1 Mon Sep 17 00:00:00 2001 From: Vitali Date: Wed, 20 Jan 2016 19:13:31 +0200 Subject: [PATCH 032/133] Fix package.json paths --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 553c21a0..828c1d61 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "file:../../deep-package-manager/src", + "deep-package-manager": "^1.x.x", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From 8fe2e08b19179ab0ec7be5549268be8baaf6c3bf Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Thu, 21 Jan 2016 10:49:16 +0200 Subject: [PATCH 033/133] Add --prod flag for init-backend cmd --- src/bin/commands/init-backend.js | 16 ++++++++++------ src/bin/manifest.js | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/bin/commands/init-backend.js b/src/bin/commands/init-backend.js index 97444528..8ba3d9d4 100644 --- a/src/bin/commands/init-backend.js +++ b/src/bin/commands/init-backend.js @@ -21,6 +21,7 @@ module.exports = function(mainPath) { var LambdaExtractor = require('../../lib.compiled/Helpers/LambdasExtractor').LambdasExtractor; var microservicesToInit = this.opts.locate('partial').value; + var useProd = this.opts.locate('prod').exists; if (mainPath.indexOf('/') !== 0) { mainPath = path.join(process.cwd(), mainPath); @@ -68,14 +69,17 @@ module.exports = function(mainPath) { var lambdaPaths = new LambdaExtractor(property).extractWorking(LambdaExtractor.NPM_PACKAGE_FILTER); var chain = new NpmChain(); - - chain.add( - new NpmInstall(lambdaPaths) - .addExtraArg( - '--loglevel silent' - ) + var installCmd = new NpmInstall(lambdaPaths) + .addExtraArg( + '--loglevel silent' ); + if (useProd) { + installCmd.addExtraArg('--prod'); + } + + chain.add(installCmd); + var linkCmd = new NpmLink(lambdaPaths); linkCmd.libs = 'aws-sdk'; diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 24d6f907..2db705b5 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -228,6 +228,11 @@ module.exports = { description: 'Partial init (one or several comma separated microservices identifiers)', required: false, }, + prod: { + alias: 'p', + description: 'Run npm install with --prod flag', + required: false, + }, }, args: { path: { From 5ecedb2fcc7985895abb7630bcfc1385f7149534 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Thu, 21 Jan 2016 11:09:14 +0200 Subject: [PATCH 034/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index a0d83647..2a3e5a20 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.3", + "version": "1.5.4", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 4ed46651f2d889f90d3da4458cc04e86fd022a65 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Thu, 21 Jan 2016 12:57:35 +0200 Subject: [PATCH 035/133] Fix cwd and fix structure --- src/bin/commands/compile-es6.js | 8 +++++--- src/lib/NodeJS/Bin.js | 5 ----- src/{bin => node-bin}/compile.sh | 0 src/{bin => node-bin}/obfuscate-compiled.sh | 0 src/{bin => node-bin}/test.sh | 0 src/package.json | 6 +++--- 6 files changed, 8 insertions(+), 11 deletions(-) rename src/{bin => node-bin}/compile.sh (100%) rename src/{bin => node-bin}/obfuscate-compiled.sh (100%) rename src/{bin => node-bin}/test.sh (100%) diff --git a/src/bin/commands/compile-es6.js b/src/bin/commands/compile-es6.js index 9f2d34b6..77da5236 100644 --- a/src/bin/commands/compile-es6.js +++ b/src/bin/commands/compile-es6.js @@ -9,9 +9,11 @@ module.exports = function(mainPath) { var path = require('path'); var Exec = require('../../lib.compiled/Helpers/Exec').Exec; - if (mainPath === '`pwd`') { - mainPath = process.cwd(); - } else if (mainPath.indexOf(path.sep) !== 0) { + var regExp = /(`\s*pwd\s*`|\$\(\s*pwd\s*\))/ig; + + mainPath = mainPath.replace(regExp, process.cwd()); + + if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } diff --git a/src/lib/NodeJS/Bin.js b/src/lib/NodeJS/Bin.js index e1571fbc..d4f80c2b 100644 --- a/src/lib/NodeJS/Bin.js +++ b/src/lib/NodeJS/Bin.js @@ -76,11 +76,6 @@ export class Bin { */ static resolve(bin) { - //don't fail on Win - //if (Bin._isWin) { - // throw new Error('Unable to resolve a binary on win* platform'); - //} - let cmd = new Exec('which', bin).runSync(); if (cmd.failed) { diff --git a/src/bin/compile.sh b/src/node-bin/compile.sh similarity index 100% rename from src/bin/compile.sh rename to src/node-bin/compile.sh diff --git a/src/bin/obfuscate-compiled.sh b/src/node-bin/obfuscate-compiled.sh similarity index 100% rename from src/bin/obfuscate-compiled.sh rename to src/node-bin/obfuscate-compiled.sh diff --git a/src/bin/test.sh b/src/node-bin/test.sh similarity index 100% rename from src/bin/test.sh rename to src/node-bin/test.sh diff --git a/src/package.json b/src/package.json index 828c1d61..2031a1d7 100644 --- a/src/package.json +++ b/src/package.json @@ -49,9 +49,9 @@ "scripts": { "preinstall": "npm run compile", "postinstall": "bash hooks/autocomplete_deepify.sh", - "test": "bash bin/test.sh", - "compile": "bash bin/compile.sh", - "obfuscate-compiled": "bash bin/obfuscate-compiled.sh", + "test": "bash node-bin/test.sh", + "compile": "bash node-bin/compile.sh", + "obfuscate-compiled": "bash node-bin/obfuscate-compiled.sh", "prepublish": "npm run obfuscate-compiled" }, "dependencies": { From c8947336ec646f42ef682ed2294b90bb8cce2ba6 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Thu, 21 Jan 2016 18:21:07 +0200 Subject: [PATCH 036/133] Fix no interaction mode --- src/hooks/autocomplete_deepify.sh | 41 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/hooks/autocomplete_deepify.sh b/src/hooks/autocomplete_deepify.sh index 84760e68..fef4f91f 100755 --- a/src/hooks/autocomplete_deepify.sh +++ b/src/hooks/autocomplete_deepify.sh @@ -5,10 +5,45 @@ BASH_PROFILE="$HOME/.bash_profile" COMPLETION_ADD=". $SCRIPT_PATH/deepify_comp.sh" IS_MAC=$(uname -a | grep Darwin) CURRENT_USER=$(whoami) +NODE_VERSION=$(node -v) +NODE_VERSION="${NODE_VERSION/v/}" -if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "msys" ]; then - export DEEP_NO_INTERACTION=1 - echo "Added environment variable DEEP_NO_INTERACTION=1 for windows" +do_version_check() { + + [ "$1" == "$2" ] && return 2 + + ver1front=`echo $1 | cut -d "." -f -1` + ver1back=`echo $1 | cut -d "." -f 2-` + + ver2front=`echo $2 | cut -d "." -f -1` + ver2back=`echo $2 | cut -d "." -f 2-` + + if [ "$ver1front" != "$1" ] || [ "$ver2front" != "$2" ]; then + [ "$ver1front" -gt "$ver2front" ] && return 3 + [ "$ver1front" -lt "$ver2front" ] && return 1 + + [ "$ver1front" == "$1" ] || [ -z "$ver1back" ] && ver1back=0 + [ "$ver2front" == "$2" ] || [ -z "$ver2back" ] && ver2back=0 + do_version_check "$ver1back" "$ver2back" + return $? + else + [ "$1" -gt "$2" ] && return 3 || return 1 + fi +} + +do_version_check "${NODE_VERSION}" "4.2.4" + +VERSION_STATUS=$? + +if ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ] || [ "$OSTYPE" == "msys" ]) && [ $VERSION_STATUS -lt 2 ]; then + echo "Node ${NODE_VERSION} on Windows doesn’t support prompt! Do you want to use in no interaction mode?" + read answer + if echo "$answer" | grep -iq "^y" ;then + export DEEP_NO_INTERACTION=1 + echo "Added environment variable DEEP_NO_INTERACTION=1 for Windows" + else + echo "Please update your node version on Windows to minimum 4.2.4" + fi fi if [ "$IS_MAC" = "" ]; then From fc80c9adbc7aa703b871d755ba6eeb79200deb02 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 22 Jan 2016 13:29:54 +0200 Subject: [PATCH 037/133] Fix es6 compile --- src/bin/commands/compile-es6.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bin/commands/compile-es6.js b/src/bin/commands/compile-es6.js index 77da5236..3df046c2 100644 --- a/src/bin/commands/compile-es6.js +++ b/src/bin/commands/compile-es6.js @@ -7,16 +7,20 @@ module.exports = function(mainPath) { var path = require('path'); + var os = require('os'); var Exec = require('../../lib.compiled/Helpers/Exec').Exec; var regExp = /(`\s*pwd\s*`|\$\(\s*pwd\s*\))/ig; mainPath = mainPath.replace(regExp, process.cwd()); + console.log('mainPath before if: ', mainPath) - if (mainPath.indexOf(path.sep) !== 0) { + if (mainPath.indexOf(path.sep) !== 0 && os.type() !== 'Windows_NT') { mainPath = path.join(process.cwd(), mainPath); } + console.log('mainPath after if: ', mainPath) + new Exec(path.join(__dirname, 'bin/compile-es6.sh'), mainPath) .run(function(result) { if (result.failed) { From 5ee4c09e1d6c6092a902deb8208674f9f544f30a Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 22 Jan 2016 14:35:33 +0200 Subject: [PATCH 038/133] Windows support --- src/bin/commands/compile-es6.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/bin/commands/compile-es6.js b/src/bin/commands/compile-es6.js index 3df046c2..35e31219 100644 --- a/src/bin/commands/compile-es6.js +++ b/src/bin/commands/compile-es6.js @@ -13,14 +13,11 @@ module.exports = function(mainPath) { var regExp = /(`\s*pwd\s*`|\$\(\s*pwd\s*\))/ig; mainPath = mainPath.replace(regExp, process.cwd()); - console.log('mainPath before if: ', mainPath) if (mainPath.indexOf(path.sep) !== 0 && os.type() !== 'Windows_NT') { mainPath = path.join(process.cwd(), mainPath); } - console.log('mainPath after if: ', mainPath) - new Exec(path.join(__dirname, 'bin/compile-es6.sh'), mainPath) .run(function(result) { if (result.failed) { From 445fa9890f7aeb190f421006891e6b4b36b609e9 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 22 Jan 2016 19:37:45 +0200 Subject: [PATCH 039/133] Fix paths in bin --- src/bin/commands/build-frontend.js | 2 +- src/bin/commands/compile-prod.js | 2 +- src/bin/commands/deploy.js | 2 +- src/bin/commands/init-backend.js | 18 +++++++++++------- src/bin/commands/install.js | 2 +- src/bin/commands/pull-deps.js | 2 +- src/bin/commands/push-deps.js | 2 +- src/bin/commands/run-lambda.js | 2 +- src/bin/commands/server.js | 2 +- src/bin/commands/undeploy.js | 2 +- src/bin/manifest.js | 5 +++++ src/package.json | 4 ++-- 12 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/bin/commands/build-frontend.js b/src/bin/commands/build-frontend.js index 58c6c5ef..fec8c297 100644 --- a/src/bin/commands/build-frontend.js +++ b/src/bin/commands/build-frontend.js @@ -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); } diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index 225830af..e383eea6 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -29,7 +29,7 @@ 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); } diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 3b6f5b82..a78352b4 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -26,7 +26,7 @@ module.exports = function(mainPath) { var hasToPullDeps = this.opts.locate('pull-deps').exists; var microservicesToDeploy = this.opts.locate('partial').value; - if (mainPath.indexOf('/') !== 0) { + if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } diff --git a/src/bin/commands/init-backend.js b/src/bin/commands/init-backend.js index ab210033..f026212e 100644 --- a/src/bin/commands/init-backend.js +++ b/src/bin/commands/init-backend.js @@ -19,8 +19,9 @@ module.exports = function(mainPath) { var LambdaExtractor = require('../../lib.compiled/Helpers/LambdasExtractor').LambdasExtractor; var microservicesToInit = this.opts.locate('partial').value; + var useProd = this.opts.locate('prod').exists; - if (mainPath.indexOf('/') !== 0) { + if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } @@ -66,14 +67,17 @@ module.exports = function(mainPath) { var lambdaPaths = new LambdaExtractor(property).extractWorking(LambdaExtractor.NPM_PACKAGE_FILTER); var chain = new NpmChain(); - - chain.add( - new NpmInstall(lambdaPaths) - .addExtraArg( - '--loglevel silent' - ) + var installCmd = new NpmInstall(lambdaPaths) + .addExtraArg( + '--loglevel silent' ); + if (useProd) { + installCmd.addExtraArg('--prod'); + } + + chain.add(installCmd); + var linkCmd = new NpmLink(lambdaPaths); linkCmd.libs = 'aws-sdk'; diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index 65345e98..e4e750dd 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -14,7 +14,7 @@ module.exports = function(microserviceRepo, dumpPath) { var Bin = require('../../lib.compiled/NodeJS/Bin').Bin; var Prompt = require('../../lib.compiled/Terminal/Prompt').Prompt; - if (dumpPath.indexOf('/') !== 0) { + if (dumpPath.indexOf(path.sep) !== 0) { dumpPath = path.join(process.cwd(), dumpPath); } diff --git a/src/bin/commands/pull-deps.js b/src/bin/commands/pull-deps.js index 3fe4dee9..ce003367 100644 --- a/src/bin/commands/pull-deps.js +++ b/src/bin/commands/pull-deps.js @@ -29,7 +29,7 @@ module.exports = function(mainPath) { mainPath = mainPath.substr(0, semicolonIndex); } - if (mainPath.indexOf('/') !== 0) { + if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } diff --git a/src/bin/commands/push-deps.js b/src/bin/commands/push-deps.js index 18493b1a..ca8ac13d 100644 --- a/src/bin/commands/push-deps.js +++ b/src/bin/commands/push-deps.js @@ -29,7 +29,7 @@ module.exports = function(mainPath) { mainPath = mainPath.substr(0, semicolonIndex); } - if (mainPath.indexOf('/') !== 0) { + if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } diff --git a/src/bin/commands/run-lambda.js b/src/bin/commands/run-lambda.js index fcbcffbf..6076cdf4 100644 --- a/src/bin/commands/run-lambda.js +++ b/src/bin/commands/run-lambda.js @@ -26,7 +26,7 @@ module.exports = function(lambdaPath) { Autoload._skipBuild(); } - if (lambdaPath.indexOf('/') !== 0) { + if (lambdaPath.indexOf(path.sep) !== 0) { lambdaPath = path.join(process.cwd(), lambdaPath); } diff --git a/src/bin/commands/server.js b/src/bin/commands/server.js index 6680af0c..81b912de 100644 --- a/src/bin/commands/server.js +++ b/src/bin/commands/server.js @@ -35,7 +35,7 @@ module.exports = function(mainPath) { Autoload._skipBuild(); } - if (mainPath.indexOf('/') !== 0) { + if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } diff --git a/src/bin/commands/undeploy.js b/src/bin/commands/undeploy.js index a0087d44..71643182 100644 --- a/src/bin/commands/undeploy.js +++ b/src/bin/commands/undeploy.js @@ -34,7 +34,7 @@ module.exports = function(mainPath) { } } - if (mainPath.indexOf('/') !== 0) { + if (mainPath.indexOf(path.sep) !== 0) { mainPath = path.join(process.cwd(), mainPath); } diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 24d6f907..2db705b5 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -228,6 +228,11 @@ module.exports = { description: 'Partial init (one or several comma separated microservices identifiers)', required: false, }, + prod: { + alias: 'p', + description: 'Run npm install with --prod flag', + required: false, + }, }, args: { path: { diff --git a/src/package.json b/src/package.json index 2031a1d7..e2b2a8b6 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.3", + "version": "1.5.4", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "^1.x.x", + "deep-package-manager": "file:../../../deep-package-manager/src", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From a23428e36a1b8cfcee26ecabb0dd008e6bee9a00 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 22 Jan 2016 19:43:12 +0200 Subject: [PATCH 040/133] Fix deep-package-manager version --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index e2b2a8b6..ec061bc8 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "file:../../../deep-package-manager/src", + "deep-package-manager": "^1.x.x", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From 9a22da0e0a4159a174e319ffa4b19170d6dab79a Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 22 Jan 2016 19:51:47 +0200 Subject: [PATCH 041/133] Fix paths separator --- src/bin/commands/deploy.js | 2 +- src/bin/commands/server.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index a78352b4..ff0ddabf 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -30,7 +30,7 @@ module.exports = function(mainPath) { mainPath = path.join(process.cwd(), mainPath); } - if (dumpCodePath && dumpCodePath.indexOf('/') !== 0) { + if (dumpCodePath && dumpCodePath.indexOf(path.sep) !== 0) { dumpCodePath = path.join(process.cwd(), dumpCodePath); } diff --git a/src/bin/commands/server.js b/src/bin/commands/server.js index 81b912de..f22729cc 100644 --- a/src/bin/commands/server.js +++ b/src/bin/commands/server.js @@ -39,7 +39,7 @@ module.exports = function(mainPath) { mainPath = path.join(process.cwd(), mainPath); } - if (buildPath && buildPath.indexOf('/') !== 0) { + if (buildPath && buildPath.indexOf(path.sep) !== 0) { buildPath = path.join(process.cwd(), buildPath); } From 9474bb752ac660e1134428122c6e04306a7250ca Mon Sep 17 00:00:00 2001 From: Vitali Date: Sat, 23 Jan 2016 11:53:58 +0200 Subject: [PATCH 042/133] Tem fix for interactive mode --- src/hooks/autocomplete_deepify.sh | 5 +++-- src/package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hooks/autocomplete_deepify.sh b/src/hooks/autocomplete_deepify.sh index fef4f91f..af2ce626 100755 --- a/src/hooks/autocomplete_deepify.sh +++ b/src/hooks/autocomplete_deepify.sh @@ -35,8 +35,9 @@ do_version_check "${NODE_VERSION}" "4.2.4" VERSION_STATUS=$? -if ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ] || [ "$OSTYPE" == "msys" ]) && [ $VERSION_STATUS -lt 2 ]; then - echo "Node ${NODE_VERSION} on Windows doesn’t support prompt! Do you want to use in no interaction mode?" +#if ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ] || [ "$OSTYPE" == "msys" ]) && [ $VERSION_STATUS -lt 2 ]; then +if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ] || [ "$OSTYPE" == "msys" ]; then + echo "Node ${NODE_VERSION} on Windows doesn’t support prompt! Do you want to use in no interaction mode?[Y/N]" read answer if echo "$answer" | grep -iq "^y" ;then export DEEP_NO_INTERACTION=1 diff --git a/src/package.json b/src/package.json index ec061bc8..ffa57d0f 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "^1.x.x", + "deep-package-manager": "file:../../deep-package-manager/src", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From c2bf759ca91b6f4756683c1e0aa63e5fc31807ff Mon Sep 17 00:00:00 2001 From: Vitali Date: Sat, 23 Jan 2016 16:16:58 +0200 Subject: [PATCH 043/133] Add y/n for node --- src/hooks/autocomplete_deepify.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hooks/autocomplete_deepify.sh b/src/hooks/autocomplete_deepify.sh index af2ce626..ade95d0d 100755 --- a/src/hooks/autocomplete_deepify.sh +++ b/src/hooks/autocomplete_deepify.sh @@ -35,8 +35,7 @@ do_version_check "${NODE_VERSION}" "4.2.4" VERSION_STATUS=$? -#if ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ] || [ "$OSTYPE" == "msys" ]) && [ $VERSION_STATUS -lt 2 ]; then -if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ] || [ "$OSTYPE" == "msys" ]; then +if ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ] || [ "$OSTYPE" == "msys" ]) && [ $VERSION_STATUS -lt 2 ]; then echo "Node ${NODE_VERSION} on Windows doesn’t support prompt! Do you want to use in no interaction mode?[Y/N]" read answer if echo "$answer" | grep -iq "^y" ;then From 3e9022a6ffbb77c3f3a72121ddc4a4f734499c16 Mon Sep 17 00:00:00 2001 From: Vitali Date: Sat, 23 Jan 2016 16:24:42 +0200 Subject: [PATCH 044/133] Fix deep-package-manager path --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index ffa57d0f..ec061bc8 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "file:../../deep-package-manager/src", + "deep-package-manager": "^1.x.x", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From 93a60e28bd84e350dfc23a961fc2b604da99db82 Mon Sep 17 00:00:00 2001 From: Vitali Date: Sun, 24 Jan 2016 18:47:53 +0200 Subject: [PATCH 045/133] Temporary solution for Windows --- src/lib/NodeJS/Bin.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/NodeJS/Bin.js b/src/lib/NodeJS/Bin.js index d4f80c2b..08ee7d41 100644 --- a/src/lib/NodeJS/Bin.js +++ b/src/lib/NodeJS/Bin.js @@ -48,6 +48,9 @@ export class Bin { Bin._npm = Bin.resolve('npm'); + //@todo - temporary solution for windows -> node exists globally so we can use without full path + Bin._npm = (Bin._isWin) ? 'npm': Bin._npm; + return Bin._npm; } @@ -56,6 +59,7 @@ export class Bin { */ static get node() { if (Bin._node) { + return Bin._node; } @@ -67,6 +71,9 @@ export class Bin { Bin._node = Bin.resolve('node'); } + //@todo - temporary solution for windows -> node exists globally so we can use without full path + Bin._node = (Bin._isWin) ? 'node': Bin._node; + return Bin._node; } @@ -75,8 +82,8 @@ export class Bin { * @returns {String} */ static resolve(bin) { - - let cmd = new Exec('which', bin).runSync(); + let locatorCmd = (Bin._isWin) ? 'where': 'which'; + let cmd = new Exec(locatorCmd, bin).runSync(); if (cmd.failed) { throw cmd.error; From e98409656c221f70f26df5a7462de9a73ff14384 Mon Sep 17 00:00:00 2001 From: Vitali Date: Mon, 25 Jan 2016 01:09:02 +0200 Subject: [PATCH 046/133] Add workarround to avoid memory exception --- src/bin/commands/install.js | 6 ++++++ src/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index e4e750dd..e52739f1 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -29,6 +29,12 @@ module.exports = function(microserviceRepo, dumpPath) { console.error('Error while installing babel: ' + error); } + //@todo - temporary workarround for FATAL ERROR- JS Allocation failed – process out of memory + if(/^win/.test(process.platform)) { + console.log('The web application was successfully installed.'); + return; + } + var prompt = new Prompt('Initialize backend?'); prompt.readConfirm(function(result) { diff --git a/src/package.json b/src/package.json index ec061bc8..ffa57d0f 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "^1.x.x", + "deep-package-manager": "file:../../deep-package-manager/src", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From 1b6dff7670aad03add1cc4caa3ec1ee1305dda25 Mon Sep 17 00:00:00 2001 From: Vitali Date: Mon, 25 Jan 2016 01:10:06 +0200 Subject: [PATCH 047/133] Undo package.json changes --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index ffa57d0f..ec061bc8 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "file:../../deep-package-manager/src", + "deep-package-manager": "^1.x.x", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From 0293156cd76e58dcffe371a98d861b2f19ffb287 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 25 Jan 2016 12:38:30 +0200 Subject: [PATCH 048/133] Update compile_es6 from sync to async --- src/bin/commands/compile-es6.js | 2 +- src/bin/commands/install.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/compile-es6.js b/src/bin/commands/compile-es6.js index 35e31219..b69553f5 100644 --- a/src/bin/commands/compile-es6.js +++ b/src/bin/commands/compile-es6.js @@ -24,5 +24,5 @@ module.exports = function(mainPath) { console.error(result.error); this.exit(1); } - }.bind(this), false); + }.bind(this), true); }; diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index e52739f1..f37afb57 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -31,7 +31,9 @@ module.exports = function(microserviceRepo, dumpPath) { //@todo - temporary workarround for FATAL ERROR- JS Allocation failed – process out of memory if(/^win/.test(process.platform)) { - console.log('The web application was successfully installed.'); + console.warn('The web application was successfully installed on Windows!\n'); + console.info('To initialize backend use "deepify init-backend path/to" command'); + console.info('To run local development server use "deepify server path/to" command'); return; } From 849ddfa27e201dabb46d56e3600b5dccb5350ab7 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 25 Jan 2016 19:09:38 +0200 Subject: [PATCH 049/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index ec061bc8..a1d5df1d 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.4", + "version": "1.5.5", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 437e617e19fe2be1edf3f1542ece5e388f493e05 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 25 Jan 2016 19:18:55 +0200 Subject: [PATCH 050/133] Publish depeify --- src/.npmignore | 1 + src/package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/.npmignore b/src/.npmignore index b2d892dc..a917fce7 100644 --- a/src/.npmignore +++ b/src/.npmignore @@ -2,3 +2,4 @@ test tests /lib .gitignore +coverage \ No newline at end of file diff --git a/src/package.json b/src/package.json index a1d5df1d..82210782 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.5", + "version": "1.5.6", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 4de2f746732316e4d029ddacc5f1c3d56c002957 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 25 Jan 2016 19:30:11 +0200 Subject: [PATCH 051/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 82210782..2f9b789b 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.6", + "version": "1.5.7", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 9ed0d117769e1b6f25b886a2e3f0b867c20ec1c3 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 26 Jan 2016 15:43:04 +0200 Subject: [PATCH 052/133] Integrate custom validations schema --- src/bin/commands/compile-prod.js | 4 + src/lib/Helpers/ValidationSchemasSync.js | 127 +++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/lib/Helpers/ValidationSchemasSync.js diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index e383eea6..ec6f0047 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -11,6 +11,7 @@ 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; @@ -55,6 +56,9 @@ module.exports = function(mainPath) { lambdas.tmpPath.push(lambdaTmpPath); } + console.log('Sync validation schemas into ' + lambdas.path.length + ' Lambdas'); + new ValidationSchemasSync(property).syncWorking(LambdaExtractor.NPM_PACKAGE_FILTER); + prepareSources.bind(this)(function() { var chain = new NpmChain(); diff --git a/src/lib/Helpers/ValidationSchemasSync.js b/src/lib/Helpers/ValidationSchemasSync.js new file mode 100644 index 00000000..aa038e82 --- /dev/null +++ b/src/lib/Helpers/ValidationSchemasSync.js @@ -0,0 +1,127 @@ +/** + * Created by AlexanderC on 1/26/16. + */ + +'use strict'; + +import path from 'path'; +import fs from 'fs'; +import fse from 'fs-extra'; +import Core from 'deep-core'; +import {Microservice_Metadata_Action as Action} from 'deep-package-manager'; +import {Microservice_Property_ValidationSchema as ValidationSchema} from 'deep-package-manager'; + +export 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 === Action.LAMBDA) { + let lambdaPath = path.join( + microservice.autoload.backend, + microserviceRoute.source + ); + + lambdas.push(lambdaPath); + } + } + } + + let validationSchemas = ValidationSchema.create(...validationSchemasDirs); + + lambdas = filter + ? lambdas.filter(filter) + : lambdas; + + lambdas.forEach((lambdaPath) => { + let schemasPath = path.join(lambdaPath, Core.AWS.Lambda.Runtime.VALIDATION_SCHEMAS_DIR); + + if (fs.existsSync(validationSchemas)) { + fse.removeSync(validationSchemas); + } + + validationSchemas.forEach((schema) => { + let schemaPath = schema.schemaPath; + let destinationSchemaPath = path.join(schemasPath, `${schema.name}.js`); + + fse.copySync(schemaPath, destinationSchemaPath); + }); + }); + + return this; + } + + /** + * @returns {Function} + */ + static get NPM_PACKAGE_FILTER() { + return (lambdaPath) => { + return fs.existsSync(path.join(lambdaPath, 'package.json')); + }; + } +} From 7f94f3abc184357ce7a3cc53de2eb4829128a5a8 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 26 Jan 2016 16:29:03 +0200 Subject: [PATCH 053/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 2f9b789b..826dba51 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.5.7", + "version": "1.6.0", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 58c590e22f9411d38dfe0a551b9981a0ebb586ba Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 26 Jan 2016 16:32:40 +0200 Subject: [PATCH 054/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 826dba51..e0e8e4bf 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.0", + "version": "1.6.1", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From cfbafd4a4ad60caf7b07acc694815b5dfccd4a84 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 26 Jan 2016 17:01:27 +0200 Subject: [PATCH 055/133] Fix validation --- src/bin/commands/compile-prod.js | 7 ++++--- src/lib/Helpers/ValidationSchemasSync.js | 2 +- src/package.json | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index ec6f0047..c9b2b002 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -45,6 +45,10 @@ module.exports = function(mainPath) { 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; @@ -56,9 +60,6 @@ module.exports = function(mainPath) { lambdas.tmpPath.push(lambdaTmpPath); } - console.log('Sync validation schemas into ' + lambdas.path.length + ' Lambdas'); - new ValidationSchemasSync(property).syncWorking(LambdaExtractor.NPM_PACKAGE_FILTER); - prepareSources.bind(this)(function() { var chain = new NpmChain(); diff --git a/src/lib/Helpers/ValidationSchemasSync.js b/src/lib/Helpers/ValidationSchemasSync.js index aa038e82..c7b84ade 100644 --- a/src/lib/Helpers/ValidationSchemasSync.js +++ b/src/lib/Helpers/ValidationSchemasSync.js @@ -9,7 +9,7 @@ import fs from 'fs'; import fse from 'fs-extra'; import Core from 'deep-core'; import {Microservice_Metadata_Action as Action} from 'deep-package-manager'; -import {Microservice_Property_ValidationSchema as ValidationSchema} from 'deep-package-manager'; +import {Property_ValidationSchema as ValidationSchema} from 'deep-package-manager'; export class ValidationSchemasSync { /** diff --git a/src/package.json b/src/package.json index e0e8e4bf..52db7b0a 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.1", + "version": "1.6.2", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 5d10db6c6c3111ea9f46335361010b42ab72327d Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 29 Jan 2016 12:19:58 +0200 Subject: [PATCH 056/133] Add enable/disable-ssl commands --- src/bin/commands/disable-ssl.js | 132 +++++++++++++++++++++ src/bin/commands/enable-ssl.js | 199 ++++++++++++++++++++++++++++++++ src/bin/manifest.js | 29 +++++ 3 files changed, 360 insertions(+) create mode 100644 src/bin/commands/disable-ssl.js create mode 100644 src/bin/commands/enable-ssl.js diff --git a/src/bin/commands/disable-ssl.js b/src/bin/commands/disable-ssl.js new file mode 100644 index 00000000..119e3330 --- /dev/null +++ b/src/bin/commands/disable-ssl.js @@ -0,0 +1,132 @@ +#!/usr/bin/env node +/** + * Created by AlexanderC on 8/4/15. + */ + +'use strict'; + +module.exports = function(mainPath) { + var path = require('path'); + var fse = require('fs-extra'); + var fs = require('fs'); + var Property = require('deep-package-manager').Property_Instance; + var ACMListing = require('deep-package-manager').Provisioning_ListingDriver_ACMDriver; + var Hash = require('deep-package-manager').Helpers_Hash; + var Config = require('deep-package-manager').Property_Config; + + if (mainPath.indexOf(path.sep) !== 0) { + mainPath = path.join(process.cwd(), mainPath); + } + + var propertyConfigFile = path.join(mainPath, Config.DEFAULT_FILENAME); + var deployConfigFile = path.join(mainPath, '.cfg.deeploy.json'); + + if (!fs.existsSync(propertyConfigFile) || !fs.existsSync(deployConfigFile)) { + console.error('You should have the application deployed'); + } + + var deployConfig = fse.readJsonSync(deployConfigFile); + var cfDomain = deployConfig.provisioning.cloudfront.domain; + var cfId = deployConfig.provisioning.cloudfront.id; + + var property = new Property(mainPath); + var acm = property.provisioning.acm; + var cf = property.provisioning.cloudFront; + var domain = property.config.domain; + + if (!domain) { + console.error('Please add a domain to \'' + Config.DEFAULT_FILENAME + '\' config file in order to deactivate SSL!'); + } + + getCertArn.bind(this)(function(certArn) { + deactivateForCf.bind(this)(certArn, function() { + console.log( + 'Certificate \'' + certArn + '\' have been successfully unassigned on the \'' + + cfDomain + '\' CloudFront distribution' + ); + }.bind(this)); + }.bind(this)); + + function getCertArn(cb) { + var domainRegex = new RegExp('^' + _escapeRegExp(domain) + '$', 'i'); + + var listing = new ACMListing( + acm, + domainRegex + ); + + console.log('Fetching account certificates'); + + listing.list(function() { + var certificates = listing.extractResetStack; + + for (var certArn in certificates) { + if (!certificates.hasOwnProperty(certArn)) { + continue; + } + + var certData = certificates[certArn]; + + if (domain === certData.DomainName) { + console.log('Certificate \'' + certArn + '\' available for domain \'' + domain + '\''); + cb(certArn); + return; + } + } + + console.error('There is no certificate available for the domain \'' + domain + '\''); + this.exit(1); + }.bind(this)); + } + + function deactivateForCf(certArn, cb) { + console.log('Fetching CloudFront distribution \'' + cfDomain + '\' configuration'); + + getCfConfig.bind(this)(function(distConfig, eTag) { + var payload = { + DistributionConfig: distConfig, + Id: cfId, + IfMatch: eTag, + }; + + payload.DistributionConfig.DefaultCacheBehavior.ViewerProtocolPolicy = 'allow-all'; + delete payload.DistributionConfig.ViewerCertificate.Certificate; + payload.DistributionConfig.ViewerCertificate.CertificateSource = 'cloudfront'; + payload.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate = true; + payload.DistributionConfig.Aliases = { + Quantity: 0, + Items: [], + }; + + console.log('Updating CloudFront distribution \'' + cfDomain + '\' configuration'); + + cf.updateDistribution(payload, function (error) { + if (error) { + console.error(error); + this.exit(1); + } + + cb(); + }.bind(this)); + }.bind(this)); + } + + function getCfConfig(cb) { + var payload = { + Id: cfId, + }; + + cf.getDistributionConfig(payload, function (error, data) { + if (error) { + console.error(error); + this.exit(1); + } + + cb(data.DistributionConfig, data.ETag); + }.bind(this)); + } + + function _escapeRegExp(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } +}; diff --git a/src/bin/commands/enable-ssl.js b/src/bin/commands/enable-ssl.js new file mode 100644 index 00000000..3b700cfb --- /dev/null +++ b/src/bin/commands/enable-ssl.js @@ -0,0 +1,199 @@ +#!/usr/bin/env node +/** + * Created by AlexanderC on 8/4/15. + */ + +'use strict'; + +module.exports = function(mainPath) { + var path = require('path'); + var fse = require('fs-extra'); + var fs = require('fs'); + var Property = require('deep-package-manager').Property_Instance; + var ACMListing = require('deep-package-manager').Provisioning_ListingDriver_ACMDriver; + var Hash = require('deep-package-manager').Helpers_Hash; + var Config = require('deep-package-manager').Property_Config; + + var domain = this.opts.locate('domain').value || null; + + if (mainPath.indexOf(path.sep) !== 0) { + mainPath = path.join(process.cwd(), mainPath); + } + + var propertyConfigFile = path.join(mainPath, Config.DEFAULT_FILENAME); + var deployConfigFile = path.join(mainPath, '.cfg.deeploy.json'); + + if (!fs.existsSync(propertyConfigFile) || !fs.existsSync(deployConfigFile)) { + console.error('You should have the application deployed'); + } + + var deployConfig = fse.readJsonSync(deployConfigFile); + var cfDomain = deployConfig.provisioning.cloudfront.domain; + var cfId = deployConfig.provisioning.cloudfront.id; + + if (domain) { + let config = null; + + config = fse.readJsonSync(propertyConfigFile); + config.domain = domain; + + fse.outputJsonSync(propertyConfigFile, config); + } + + var property = new Property(mainPath); + var acm = property.provisioning.acm; + var cf = property.provisioning.cloudFront; + + domain = property.config.domain; + + if (!domain) { + console.error('Please add a domain to \'' + Config.DEFAULT_FILENAME + '\' config file in order to activate SSL!'); + console.log('You may add \'--domain\' option to add it to the config automatically.'); + } + + getCertArn.bind(this)(function(certArn) { + ensureActive.bind(this)(certArn, function() { + activateForCf.bind(this)(certArn, function() { + console.log( + 'Certificate \'' + certArn + '\' have been successfully assigned to the \'' + + cfDomain + '\' CloudFront distribution' + ); + }.bind(this)); + }.bind(this)); + }.bind(this)); + + function getCertArn(cb) { + var domainRegex = new RegExp('^' + _escapeRegExp(domain) + '$', 'i'); + + var listing = new ACMListing( + acm, + domainRegex + ); + + console.log('Fetching account certificates'); + + listing.list(function() { + var certificates = listing.extractResetStack; + + for (var certArn in certificates) { + if (!certificates.hasOwnProperty(certArn)) { + continue; + } + + var certData = certificates[certArn]; + + if (domain === certData.DomainName) { + console.log('Certificate \'' + certArn + '\' available for domain \'' + domain + '\''); + cb(certArn); + return; + } + } + + console.log('Creating certificate for domain \'' + domain + '\''); + + createCert.bind(this)(cb); + }.bind(this)); + } + + function createCert(cb) { + var payload = { + DomainName: domain, + IdempotencyToken: Hash.md5(property.identifier + '|' + domain), + }; + + acm.requestCertificate(payload, function (error, data) { + if (error) { + console.error(error); + this.exit(1); + } + + cb(data.CertificateArn); + }.bind(this)); + } + + function ensureActive(certArn, cb) { + var payload = { + CertificateArn: certArn, + }; + + acm.describeCertificate(payload, function (error, data) { + if (error) { + console.error(error); + this.exit(1); + } + + console.log('Certificate status: ' + data.Certificate.Status); + + if (data.Certificate.Status !== 'ISSUED') { + console.error( + 'You must validate the certificate \'' + certArn + + '\' by accessing the link from the mail sent by AWS (Subject: "Certificate approval for ' + domain + '")' + ); + this.exit(1); + } + + cb(); + }.bind(this)); + } + + function activateForCf(certArn, cb) { + console.log('Fetching CloudFront distribution \'' + cfDomain + '\' configuration'); + + getCfConfig.bind(this)(function(distConfig, eTag) { + var payload = { + DistributionConfig: distConfig, + Id: cfId, + IfMatch: eTag, + }; + + payload.DistributionConfig.DefaultCacheBehavior.ViewerProtocolPolicy = 'redirect-to-https'; + payload.DistributionConfig.ViewerCertificate.Certificate = certArn; + payload.DistributionConfig.ViewerCertificate.CertificateSource = 'acm'; + payload.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate = false; + payload.DistributionConfig.Aliases = { + Quantity: 1, + Items: [domain], + }; + + console.log('Updating CloudFront distribution \'' + cfDomain + '\' configuration'); + + cf.updateDistribution(payload, function (error) { + if (error) { + + // manage special case + if (error.code === 'CNAMEAlreadyExists') { + console.error( + 'Seems like the domain/CNAME \'' + domain + + '\' is already associated with an other CloudFront distribution!' + ); + } else { + console.error(error); + } + + this.exit(1); + } + + cb(); + }.bind(this)); + }.bind(this)); + } + + function getCfConfig(cb) { + var payload = { + Id: cfId, + }; + + cf.getDistributionConfig(payload, function (error, data) { + if (error) { + console.error(error); + this.exit(1); + } + + cb(data.DistributionConfig, data.ETag); + }.bind(this)); + } + + function _escapeRegExp(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } +}; diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 2db705b5..165a37d4 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -136,6 +136,35 @@ module.exports = { }, }, }, + 'enable-ssl': { + example: 'deepify enable-ssl path/to/web_app', + description: 'Enables SSL on a deployed web app', + opts: { + domain: { + alias: 'd', + description: 'The domain to create the certificate for (overrides the "deeploy.json" value)', + required: false, + }, + }, + args: { + path: { + description: 'The path to the web app', + required: true, + }, + }, + }, + 'disable-ssl': { + example: 'deepify disable-ssl path/to/web_app', + description: 'Disable activated SSL on a deployed web app', + opts: { + }, + args: { + path: { + description: 'The path to the web app', + required: true, + }, + }, + }, undeploy: { example: 'deepify undeploy path/to/web_app', description: 'Remove web app provisioning and uploaded data', From 21613e806799c7294b23fd7a26f1c8ccc36915e2 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 29 Jan 2016 13:15:30 +0200 Subject: [PATCH 057/133] Remove unused params --- src/bin/commands/disable-ssl.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/disable-ssl.js b/src/bin/commands/disable-ssl.js index 119e3330..fb0e3822 100644 --- a/src/bin/commands/disable-ssl.js +++ b/src/bin/commands/disable-ssl.js @@ -39,7 +39,7 @@ module.exports = function(mainPath) { } getCertArn.bind(this)(function(certArn) { - deactivateForCf.bind(this)(certArn, function() { + deactivateForCf.bind(this)(function() { console.log( 'Certificate \'' + certArn + '\' have been successfully unassigned on the \'' + cfDomain + '\' CloudFront distribution' @@ -79,7 +79,7 @@ module.exports = function(mainPath) { }.bind(this)); } - function deactivateForCf(certArn, cb) { + function deactivateForCf(cb) { console.log('Fetching CloudFront distribution \'' + cfDomain + '\' configuration'); getCfConfig.bind(this)(function(distConfig, eTag) { From 42e8738de9c022da40dc4fd7471a75bd453cde28 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 29 Jan 2016 13:24:00 +0200 Subject: [PATCH 058/133] Remove unused code --- src/bin/commands/disable-ssl.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/commands/disable-ssl.js b/src/bin/commands/disable-ssl.js index fb0e3822..69e01f2e 100644 --- a/src/bin/commands/disable-ssl.js +++ b/src/bin/commands/disable-ssl.js @@ -11,7 +11,6 @@ module.exports = function(mainPath) { var fs = require('fs'); var Property = require('deep-package-manager').Property_Instance; var ACMListing = require('deep-package-manager').Provisioning_ListingDriver_ACMDriver; - var Hash = require('deep-package-manager').Helpers_Hash; var Config = require('deep-package-manager').Property_Config; if (mainPath.indexOf(path.sep) !== 0) { From 70935f0b3335a14d97f45cd7499d3ab30f88418b Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 29 Jan 2016 15:39:28 +0200 Subject: [PATCH 059/133] Use ACM abstraction --- src/bin/commands/disable-ssl.js | 114 ++++++---------------- src/bin/commands/enable-ssl.js | 167 ++++++++------------------------ 2 files changed, 70 insertions(+), 211 deletions(-) diff --git a/src/bin/commands/disable-ssl.js b/src/bin/commands/disable-ssl.js index 69e01f2e..a529fb45 100644 --- a/src/bin/commands/disable-ssl.js +++ b/src/bin/commands/disable-ssl.js @@ -10,7 +10,8 @@ module.exports = function(mainPath) { var fse = require('fs-extra'); var fs = require('fs'); var Property = require('deep-package-manager').Property_Instance; - var ACMListing = require('deep-package-manager').Provisioning_ListingDriver_ACMDriver; + var ACMService = require('deep-package-manager').Provisioning_Service_ACMService; + var CloudFrontService = require('deep-package-manager').Provisioning_Service_CloudFrontService; var Config = require('deep-package-manager').Property_Config; if (mainPath.indexOf(path.sep) !== 0) { @@ -25,107 +26,54 @@ module.exports = function(mainPath) { } var deployConfig = fse.readJsonSync(deployConfigFile); - var cfDomain = deployConfig.provisioning.cloudfront.domain; - var cfId = deployConfig.provisioning.cloudfront.id; var property = new Property(mainPath); - var acm = property.provisioning.acm; - var cf = property.provisioning.cloudFront; + property._config = deployConfig; + property.provisioning.injectConfig(deployConfig); + var domain = property.config.domain; if (!domain) { console.error('Please add a domain to \'' + Config.DEFAULT_FILENAME + '\' config file in order to deactivate SSL!'); } - getCertArn.bind(this)(function(certArn) { - deactivateForCf.bind(this)(function() { - console.log( - 'Certificate \'' + certArn + '\' have been successfully unassigned on the \'' + - cfDomain + '\' CloudFront distribution' - ); - }.bind(this)); - }.bind(this)); - - function getCertArn(cb) { - var domainRegex = new RegExp('^' + _escapeRegExp(domain) + '$', 'i'); - - var listing = new ACMListing( - acm, - domainRegex - ); + var acmService = property.provisioning.services.find(ACMService); + var cfService = property.provisioning.services.find(CloudFrontService); - console.log('Fetching account certificates'); - - listing.list(function() { - var certificates = listing.extractResetStack; - - for (var certArn in certificates) { - if (!certificates.hasOwnProperty(certArn)) { - continue; - } - - var certData = certificates[certArn]; - - if (domain === certData.DomainName) { - console.log('Certificate \'' + certArn + '\' available for domain \'' + domain + '\''); - cb(certArn); - return; - } - } + console.log('Looking for ACM certificate available of the domain \'' + domain + '\''); + acmService.getDomainCertificateArn(domain, function(certArn) { + if (!certArn) { console.error('There is no certificate available for the domain \'' + domain + '\''); this.exit(1); - }.bind(this)); - } - - function deactivateForCf(cb) { - console.log('Fetching CloudFront distribution \'' + cfDomain + '\' configuration'); - - getCfConfig.bind(this)(function(distConfig, eTag) { - var payload = { - DistributionConfig: distConfig, - Id: cfId, - IfMatch: eTag, - }; - - payload.DistributionConfig.DefaultCacheBehavior.ViewerProtocolPolicy = 'allow-all'; - delete payload.DistributionConfig.ViewerCertificate.Certificate; - payload.DistributionConfig.ViewerCertificate.CertificateSource = 'cloudfront'; - payload.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate = true; - payload.DistributionConfig.Aliases = { + } + + var configChanges = { + DefaultCacheBehavior: { + ViewerProtocolPolicy: 'allow-all', + }, + ViewerCertificate: { + Certificate: null, + CertificateSource: 'cloudfront', + CloudFrontDefaultCertificate: true, + }, + Aliases: { Quantity: 0, - Items: [], - }; - - console.log('Updating CloudFront distribution \'' + cfDomain + '\' configuration'); - - cf.updateDistribution(payload, function (error) { - if (error) { - console.error(error); - this.exit(1); - } - - cb(); - }.bind(this)); - }.bind(this)); - } - - function getCfConfig(cb) { - var payload = { - Id: cfId, + Items: null, + }, }; - cf.getDistributionConfig(payload, function (error, data) { + console.log('Deactivating ACM certificate \'' + certArn + '\' for domain \'' + domain + '\''); + + cfService.updateDistribution(configChanges, function(error) { if (error) { console.error(error); this.exit(1); } - cb(data.DistributionConfig, data.ETag); + console.log( + 'Certificate \'' + certArn + '\' have been successfully unassigned from the CloudFront distribution' + ); }.bind(this)); - } - - function _escapeRegExp(str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); - } + }.bind(this)); }; diff --git a/src/bin/commands/enable-ssl.js b/src/bin/commands/enable-ssl.js index 3b700cfb..925382a8 100644 --- a/src/bin/commands/enable-ssl.js +++ b/src/bin/commands/enable-ssl.js @@ -10,7 +10,8 @@ module.exports = function(mainPath) { var fse = require('fs-extra'); var fs = require('fs'); var Property = require('deep-package-manager').Property_Instance; - var ACMListing = require('deep-package-manager').Provisioning_ListingDriver_ACMDriver; + var ACMService = require('deep-package-manager').Provisioning_Service_ACMService; + var CloudFrontService = require('deep-package-manager').Provisioning_Service_CloudFrontService; var Hash = require('deep-package-manager').Helpers_Hash; var Config = require('deep-package-manager').Property_Config; @@ -28,8 +29,6 @@ module.exports = function(mainPath) { } var deployConfig = fse.readJsonSync(deployConfigFile); - var cfDomain = deployConfig.provisioning.cloudfront.domain; - var cfId = deployConfig.provisioning.cloudfront.id; if (domain) { let config = null; @@ -41,159 +40,71 @@ module.exports = function(mainPath) { } var property = new Property(mainPath); - var acm = property.provisioning.acm; - var cf = property.provisioning.cloudFront; domain = property.config.domain; + property._config = deployConfig; + property.provisioning.injectConfig(deployConfig); + property.config.domain = domain; + if (!domain) { console.error('Please add a domain to \'' + Config.DEFAULT_FILENAME + '\' config file in order to activate SSL!'); console.log('You may add \'--domain\' option to add it to the config automatically.'); } - getCertArn.bind(this)(function(certArn) { - ensureActive.bind(this)(certArn, function() { - activateForCf.bind(this)(certArn, function() { - console.log( - 'Certificate \'' + certArn + '\' have been successfully assigned to the \'' + - cfDomain + '\' CloudFront distribution' - ); - }.bind(this)); - }.bind(this)); - }.bind(this)); - - function getCertArn(cb) { - var domainRegex = new RegExp('^' + _escapeRegExp(domain) + '$', 'i'); + var acmService = property.provisioning.services.find(ACMService); + var cfService = property.provisioning.services.find(CloudFrontService); - var listing = new ACMListing( - acm, - domainRegex - ); + console.log('Ensure ACM certificate available for domain \'' + domain + '\''); - console.log('Fetching account certificates'); - - listing.list(function() { - var certificates = listing.extractResetStack; - - for (var certArn in certificates) { - if (!certificates.hasOwnProperty(certArn)) { - continue; - } - - var certData = certificates[certArn]; - - if (domain === certData.DomainName) { - console.log('Certificate \'' + certArn + '\' available for domain \'' + domain + '\''); - cb(certArn); - return; - } - } - - console.log('Creating certificate for domain \'' + domain + '\''); - - createCert.bind(this)(cb); - }.bind(this)); - } - - function createCert(cb) { - var payload = { - DomainName: domain, - IdempotencyToken: Hash.md5(property.identifier + '|' + domain), - }; - - acm.requestCertificate(payload, function (error, data) { - if (error) { - console.error(error); - this.exit(1); - } - - cb(data.CertificateArn); - }.bind(this)); - } + acmService.ensureCertificate(domain, function (error, certArn) { + if (error) { + console.error(error); + this.exit(1); + } - function ensureActive(certArn, cb) { - var payload = { - CertificateArn: certArn, - }; + console.log('Ensure ACM certificate \'' + certArn + '\' for domain \'' + domain + '\' have been activated'); - acm.describeCertificate(payload, function (error, data) { + acmService.isCertificateIssued(certArn, function(error, isIssued) { if (error) { console.error(error); this.exit(1); - } - - console.log('Certificate status: ' + data.Certificate.Status); - - if (data.Certificate.Status !== 'ISSUED') { + } else if(!isIssued) { console.error( 'You must validate the certificate \'' + certArn - + '\' by accessing the link from the mail sent by AWS (Subject: "Certificate approval for ' + domain + '")' + + '\' by accessing the link from the mail sent by AWS ' + + '(Subject: "Certificate approval for ' + domain + '")' ); this.exit(1); } - cb(); - }.bind(this)); - } - - function activateForCf(certArn, cb) { - console.log('Fetching CloudFront distribution \'' + cfDomain + '\' configuration'); - - getCfConfig.bind(this)(function(distConfig, eTag) { - var payload = { - DistributionConfig: distConfig, - Id: cfId, - IfMatch: eTag, + var configChanges = { + DefaultCacheBehavior: { + ViewerProtocolPolicy: 'redirect-to-https', + }, + ViewerCertificate: { + Certificate: certArn, + CertificateSource: 'acm', + CloudFrontDefaultCertificate: false, + }, + Aliases: { + Quantity: 1, + Items: [domain], + }, }; - payload.DistributionConfig.DefaultCacheBehavior.ViewerProtocolPolicy = 'redirect-to-https'; - payload.DistributionConfig.ViewerCertificate.Certificate = certArn; - payload.DistributionConfig.ViewerCertificate.CertificateSource = 'acm'; - payload.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate = false; - payload.DistributionConfig.Aliases = { - Quantity: 1, - Items: [domain], - }; - - console.log('Updating CloudFront distribution \'' + cfDomain + '\' configuration'); + console.log('Activating ACM certificate \'' + certArn + '\' for domain \'' + domain + '\''); - cf.updateDistribution(payload, function (error) { + cfService.updateDistribution(configChanges, function(error) { if (error) { - - // manage special case - if (error.code === 'CNAMEAlreadyExists') { - console.error( - 'Seems like the domain/CNAME \'' + domain + - '\' is already associated with an other CloudFront distribution!' - ); - } else { - console.error(error); - } - + console.error(error); this.exit(1); } - cb(); + console.log( + 'The ACM certificate \'' + certArn + '\' have been successfully assigned to the CloudFront distribution' + ); }.bind(this)); }.bind(this)); - } - - function getCfConfig(cb) { - var payload = { - Id: cfId, - }; - - cf.getDistributionConfig(payload, function (error, data) { - if (error) { - console.error(error); - this.exit(1); - } - - cb(data.DistributionConfig, data.ETag); - }.bind(this)); - } - - function _escapeRegExp(str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); - } + }.bind(this)); }; From 29c1189adbf109397531b8d82523d6860dbe1505 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 29 Jan 2016 15:45:20 +0200 Subject: [PATCH 060/133] Remove unused code --- src/bin/commands/enable-ssl.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/commands/enable-ssl.js b/src/bin/commands/enable-ssl.js index 925382a8..1a179860 100644 --- a/src/bin/commands/enable-ssl.js +++ b/src/bin/commands/enable-ssl.js @@ -12,7 +12,6 @@ module.exports = function(mainPath) { var Property = require('deep-package-manager').Property_Instance; var ACMService = require('deep-package-manager').Provisioning_Service_ACMService; var CloudFrontService = require('deep-package-manager').Provisioning_Service_CloudFrontService; - var Hash = require('deep-package-manager').Helpers_Hash; var Config = require('deep-package-manager').Property_Config; var domain = this.opts.locate('domain').value || null; From 00c7ce6d738a31d791f5e960b5264abeaf120b14 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 29 Jan 2016 16:16:33 +0200 Subject: [PATCH 061/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 52db7b0a..944daf08 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.2", + "version": "1.6.3", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 92660b751d93fad3f8984b160ce65febfb951221 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 29 Jan 2016 18:46:25 +0200 Subject: [PATCH 062/133] Publish deepify --- src/lib/Server/Instance.js | 4 ++++ src/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/Server/Instance.js b/src/lib/Server/Instance.js index 0359363e..e2aad2d9 100644 --- a/src/lib/Server/Instance.js +++ b/src/lib/Server/Instance.js @@ -296,6 +296,10 @@ export class Instance { this._fs.localBackend = true; this._fs.boot(this._kernelMock, () => { + this._log(`Linking custom validation schemas`); + + Frontend.dumpValidationSchemas(this._property.config, this._fs.public._rootFolder, true); + this._log(`Creating server on port ${port}`); this._server = Http.createServer((...args) => { diff --git a/src/package.json b/src/package.json index 944daf08..a6b70f03 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.3", + "version": "1.6.4", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From e435019e6d859feeb656086360d2836fc04350b0 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 10:54:11 +0200 Subject: [PATCH 063/133] Add new unit test fir NodeJS --- src/package.json | 2 +- src/test/Lambda/Runtime.spec.js | 3 --- src/test/Lambda/Thread.spec.js | 3 --- src/test/Server/Instance.spec.js | 3 --- src/test/Terminal/Argument.spec.js | 3 --- src/test/Terminal/Arguments.spec.js | 3 --- src/test/Terminal/Help.spec.js | 3 --- src/test/Terminal/Option.spec.js | 3 --- src/test/Terminal/Options.spec.js | 3 --- src/test/Terminal/Program.spec.js | 3 --- 10 files changed, 1 insertion(+), 28 deletions(-) diff --git a/src/package.json b/src/package.json index ec061bc8..2d27fb37 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "^1.x.x", + "deep-package-manager": "file:../../../deep-package-manager/src/", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", diff --git a/src/test/Lambda/Runtime.spec.js b/src/test/Lambda/Runtime.spec.js index 0c817860..986ee225 100644 --- a/src/test/Lambda/Runtime.spec.js +++ b/src/test/Lambda/Runtime.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Runtime} from '../../lib/Lambda/Runtime'; -// @todo: Add more advanced tests suite('Lambda/Runtime', function() { test('Class Runtime exists in Lambda/Runtime', function() { chai.expect(typeof Runtime).to.equal('function'); diff --git a/src/test/Lambda/Thread.spec.js b/src/test/Lambda/Thread.spec.js index 7e4b1dbb..34bf0f5e 100644 --- a/src/test/Lambda/Thread.spec.js +++ b/src/test/Lambda/Thread.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Thread} from '../../lib/Lambda/Thread'; -// @todo: Add more advanced tests suite('Lambda/Thread', function() { test('Class Thread exists in Lambda/Thread', function() { chai.expect(typeof Thread).to.equal('function'); diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index 971993d9..2d3580b7 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Instance} from '../../lib/Server/Instance'; -// @todo: Add more advanced tests suite('Server/Instance', function() { test('Class Instance exists in Server/Instance', function() { chai.expect(typeof Instance).to.equal('function'); diff --git a/src/test/Terminal/Argument.spec.js b/src/test/Terminal/Argument.spec.js index 112764d2..1628b50d 100644 --- a/src/test/Terminal/Argument.spec.js +++ b/src/test/Terminal/Argument.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Argument} from '../../lib/Terminal/Argument'; -// @todo: Add more advanced tests suite('Terminal/Argument', function() { test('Class Argument exists in Terminal/Argument', function() { chai.expect(typeof Argument).to.equal('function'); diff --git a/src/test/Terminal/Arguments.spec.js b/src/test/Terminal/Arguments.spec.js index 67603f3b..75eb429e 100644 --- a/src/test/Terminal/Arguments.spec.js +++ b/src/test/Terminal/Arguments.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Arguments} from '../../lib/Terminal/Arguments'; -// @todo: Add more advanced tests suite('Terminal/Arguments', function() { test('Class Arguments exists in Terminal/Arguments', function() { chai.expect(typeof Arguments).to.equal('function'); diff --git a/src/test/Terminal/Help.spec.js b/src/test/Terminal/Help.spec.js index 7947b9c5..2de9336f 100644 --- a/src/test/Terminal/Help.spec.js +++ b/src/test/Terminal/Help.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Help} from '../../lib/Terminal/Help'; -// @todo: Add more advanced tests suite('Terminal/Help', function() { test('Class Help exists in Terminal/Help', function() { chai.expect(typeof Help).to.equal('function'); diff --git a/src/test/Terminal/Option.spec.js b/src/test/Terminal/Option.spec.js index 8d5e026f..4987e38d 100644 --- a/src/test/Terminal/Option.spec.js +++ b/src/test/Terminal/Option.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Option} from '../../lib/Terminal/Option'; -// @todo: Add more advanced tests suite('Terminal/Option', function() { test('Class Option exists in Terminal/Option', function() { chai.expect(typeof Option).to.equal('function'); diff --git a/src/test/Terminal/Options.spec.js b/src/test/Terminal/Options.spec.js index 4b598c1e..fc90cf21 100644 --- a/src/test/Terminal/Options.spec.js +++ b/src/test/Terminal/Options.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Options} from '../../lib/Terminal/Options'; -// @todo: Add more advanced tests suite('Terminal/Options', function() { test('Class Options exists in Terminal/Options', function() { chai.expect(typeof Options).to.equal('function'); diff --git a/src/test/Terminal/Program.spec.js b/src/test/Terminal/Program.spec.js index 1d13dd54..64bb082b 100644 --- a/src/test/Terminal/Program.spec.js +++ b/src/test/Terminal/Program.spec.js @@ -1,11 +1,8 @@ -// THIS TEST WAS GENERATED AUTOMATICALLY ON Mon Sep 14 2015 16:15:41 GMT+0300 (EEST) - 'use strict'; import chai from 'chai'; import {Program} from '../../lib/Terminal/Program'; -// @todo: Add more advanced tests suite('Terminal/Program', function() { test('Class Program exists in Terminal/Program', function() { chai.expect(typeof Program).to.equal('function'); From 0f016ee42f265b8480555a82b0bea3d7ac347d89 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 11:20:10 +0200 Subject: [PATCH 064/133] Fix package.json --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 2d27fb37..ec061bc8 100644 --- a/src/package.json +++ b/src/package.json @@ -55,7 +55,7 @@ "prepublish": "npm run obfuscate-compiled" }, "dependencies": { - "deep-package-manager": "file:../../../deep-package-manager/src/", + "deep-package-manager": "^1.x.x", "deep-log": "^1.x.x", "deep-fs": "^1.x.x", "deep-db": "^1.x.x", From 09834a6fb657769add903e6f570e73df324b3b58 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 11:21:23 +0200 Subject: [PATCH 065/133] Add new unit tests --- src/test/Helpers/Exec.spec.js | 10 ++++++ src/test/Helpers/LambdasExtractor.spec.js | 10 ++++++ src/test/Lambda/ForksManager.spec.js | 10 ++++++ src/test/Lambda/Timer.spec.js | 10 ++++++ src/test/NodeJS/Bin.spec.js | 10 ++++++ src/test/NodeJS/DepsTreeOptimizer.spec.js | 10 ++++++ src/test/NodeJS/NpmChain.spec.js | 10 ++++++ src/test/NodeJS/NpmDedupe.spec.js | 10 ++++++ src/test/NodeJS/NpmDependency.spec.js | 10 ++++++ src/test/NodeJS/NpmInstall.spec.js | 34 +++++++++++++++++++ src/test/NodeJS/NpmInstallLibs.spec.js | 10 ++++++ src/test/NodeJS/NpmLink.spec.js | 10 ++++++ src/test/NodeJS/NpmListDependencies.spec.js | 10 ++++++ src/test/NodeJS/NpmPrune.spec.js | 10 ++++++ src/test/NodeJS/NpmRun.spec.js | 10 ++++++ src/test/NodeJS/NpmShrinkwrap.spec.js | 10 ++++++ src/test/NodeJS/NpmUninstallLibs.spec.js | 10 ++++++ src/test/NodeJS/NpmUpdate.spec.js | 10 ++++++ .../NodeJS/PackageVersionResolver.spec.js | 10 ++++++ src/test/NodeJS/UndefinedDepsResolver.spec.js | 10 ++++++ src/test/Server/Hook.spec.js | 10 ++++++ src/test/Terminal/Prompt.spec.js | 10 ++++++ 22 files changed, 244 insertions(+) create mode 100644 src/test/Helpers/Exec.spec.js create mode 100644 src/test/Helpers/LambdasExtractor.spec.js create mode 100644 src/test/Lambda/ForksManager.spec.js create mode 100644 src/test/Lambda/Timer.spec.js create mode 100644 src/test/NodeJS/Bin.spec.js create mode 100644 src/test/NodeJS/DepsTreeOptimizer.spec.js create mode 100644 src/test/NodeJS/NpmChain.spec.js create mode 100644 src/test/NodeJS/NpmDedupe.spec.js create mode 100644 src/test/NodeJS/NpmDependency.spec.js create mode 100644 src/test/NodeJS/NpmInstall.spec.js create mode 100644 src/test/NodeJS/NpmInstallLibs.spec.js create mode 100644 src/test/NodeJS/NpmLink.spec.js create mode 100644 src/test/NodeJS/NpmListDependencies.spec.js create mode 100644 src/test/NodeJS/NpmPrune.spec.js create mode 100644 src/test/NodeJS/NpmRun.spec.js create mode 100644 src/test/NodeJS/NpmShrinkwrap.spec.js create mode 100644 src/test/NodeJS/NpmUninstallLibs.spec.js create mode 100644 src/test/NodeJS/NpmUpdate.spec.js create mode 100644 src/test/NodeJS/PackageVersionResolver.spec.js create mode 100644 src/test/NodeJS/UndefinedDepsResolver.spec.js create mode 100644 src/test/Server/Hook.spec.js create mode 100644 src/test/Terminal/Prompt.spec.js diff --git a/src/test/Helpers/Exec.spec.js b/src/test/Helpers/Exec.spec.js new file mode 100644 index 00000000..c57e6520 --- /dev/null +++ b/src/test/Helpers/Exec.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {Exec} from '../../lib/Helpers/Exec'; + +suite('Helpers/Exec', function() { + test('Class Exec exists in Helpers/Exec', function() { + chai.expect(typeof Exec).to.equal('function'); + }); +}); diff --git a/src/test/Helpers/LambdasExtractor.spec.js b/src/test/Helpers/LambdasExtractor.spec.js new file mode 100644 index 00000000..c8c9eefe --- /dev/null +++ b/src/test/Helpers/LambdasExtractor.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {LambdasExtractor} from '../../lib/Helpers/LambdasExtractor'; + +suite('Helpers/LambdasExtractor', function() { + test('Class LambdasExtractor exists in Helpers/LambdasExtractor', function() { + chai.expect(typeof LambdasExtractor).to.equal('function'); + }); +}); diff --git a/src/test/Lambda/ForksManager.spec.js b/src/test/Lambda/ForksManager.spec.js new file mode 100644 index 00000000..39875e8f --- /dev/null +++ b/src/test/Lambda/ForksManager.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {ForksManager} from '../../lib/Lambda/ForksManager'; + +suite('Lambda/ForksManager', function() { + test('Class ForksManager exists in Lambda/ForksManager', function() { + chai.expect(typeof ForksManager).to.equal('function'); + }); +}); diff --git a/src/test/Lambda/Timer.spec.js b/src/test/Lambda/Timer.spec.js new file mode 100644 index 00000000..7288df50 --- /dev/null +++ b/src/test/Lambda/Timer.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {Timer} from '../../lib/Lambda/Timer'; + +suite('Lambda/Timer', function() { + test('Class Timer exists in Lambda/Timer', function() { + chai.expect(typeof Timer).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/Bin.spec.js b/src/test/NodeJS/Bin.spec.js new file mode 100644 index 00000000..1e565589 --- /dev/null +++ b/src/test/NodeJS/Bin.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {Bin} from '../../lib/NodeJS/Bin'; + +suite('NodeJS/Bin', function() { + test('Class Bin exists in NodeJS/Bin', function() { + chai.expect(typeof Bin).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/DepsTreeOptimizer.spec.js b/src/test/NodeJS/DepsTreeOptimizer.spec.js new file mode 100644 index 00000000..ebfcc2a9 --- /dev/null +++ b/src/test/NodeJS/DepsTreeOptimizer.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {DepsTreeOptimizer} from '../../lib/NodeJS/DepsTreeOptimizer'; + +suite('NodeJS/DepsTreeOptimizer', function() { + test('Class DepsTreeOptimizer exists in NodeJS/DepsTreeOptimizer', function() { + chai.expect(typeof DepsTreeOptimizer).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmChain.spec.js b/src/test/NodeJS/NpmChain.spec.js new file mode 100644 index 00000000..a3f4a9ed --- /dev/null +++ b/src/test/NodeJS/NpmChain.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmChain} from '../../lib/NodeJS/NpmChain'; + +suite('NodeJS/NpmChain', function() { + test('Class NpmChain exists in NodeJS/NpmChain', function() { + chai.expect(typeof NpmChain).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmDedupe.spec.js b/src/test/NodeJS/NpmDedupe.spec.js new file mode 100644 index 00000000..00f66ec5 --- /dev/null +++ b/src/test/NodeJS/NpmDedupe.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmDedupe} from '../../lib/NodeJS/NpmDedupe'; + +suite('NodeJS/NpmDedupe', function() { + test('Class NpmDedupe exists in NodeJS/NpmDedupe', function() { + chai.expect(typeof NpmDedupe).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmDependency.spec.js b/src/test/NodeJS/NpmDependency.spec.js new file mode 100644 index 00000000..cfca2b58 --- /dev/null +++ b/src/test/NodeJS/NpmDependency.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmDependency} from '../../lib/NodeJS/NpmDependency'; + +suite('NodeJS/NpmDependency', function() { + test('Class NpmDependency exists in NodeJS/NpmDependency', function() { + chai.expect(typeof NpmDependency).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmInstall.spec.js b/src/test/NodeJS/NpmInstall.spec.js new file mode 100644 index 00000000..f0cfaf69 --- /dev/null +++ b/src/test/NodeJS/NpmInstall.spec.js @@ -0,0 +1,34 @@ +'use strict'; + +import chai from 'chai'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; + +suite('NodeJS/NpmInstall', function() { + let npmInstall = new NpmInstall(); + + test('Class NpmInstall exists in NodeJS/NpmInstall', function() { + chai.expect(typeof NpmInstall).to.equal('function'); + }); + + test('Check DEFAULT_SILENT_STATE getter returns false', function() { + chai.expect(NpmInstall.DEFAULT_SILENT_STATE).to.equal(false); + }); + + test('Check DEFAULT_CHUNK_SIZE getter returns value above than 0', function() { + chai.expect(NpmInstall.DEFAULT_CHUNK_SIZE).to.above(0); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmInstall._mainCmd).to.includes('npm install'); + }); + + test('Check constructor sets valid value for _dirs', function () { + chai.expect(npmInstall).to.be.an.instanceOf(NpmInstall); + chai.expect(npmInstall.dirs).to.be.eql([]); + }); + + test('Check constructor sets valid value for _execArgs', function () { + chai.expect(Array.isArray(npmInstall._execArgs)).to.be.equal(true); + }); + +}); diff --git a/src/test/NodeJS/NpmInstallLibs.spec.js b/src/test/NodeJS/NpmInstallLibs.spec.js new file mode 100644 index 00000000..bb20a4b8 --- /dev/null +++ b/src/test/NodeJS/NpmInstallLibs.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmInstallLibs} from '../../lib/NodeJS/NpmInstallLibs'; + +suite('NodeJS/NpmInstallLibs', function() { + test('Class NpmInstallLibs exists in NodeJS/NpmInstallLibs', function() { + chai.expect(typeof NpmInstallLibs).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmLink.spec.js b/src/test/NodeJS/NpmLink.spec.js new file mode 100644 index 00000000..99cc6da2 --- /dev/null +++ b/src/test/NodeJS/NpmLink.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmLink} from '../../lib/NodeJS/NpmLink'; + +suite('NodeJS/NpmLink', function() { + test('Class NpmLink exists in NodeJS/NpmLink', function() { + chai.expect(typeof NpmLink).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmListDependencies.spec.js b/src/test/NodeJS/NpmListDependencies.spec.js new file mode 100644 index 00000000..3e7aacfc --- /dev/null +++ b/src/test/NodeJS/NpmListDependencies.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmListDependencies} from '../../lib/NodeJS/NpmListDependencies'; + +suite('NodeJS/NpmListDependencies', function() { + test('Class NpmListDependencies exists in NodeJS/NpmListDependencies', function() { + chai.expect(typeof NpmListDependencies).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmPrune.spec.js b/src/test/NodeJS/NpmPrune.spec.js new file mode 100644 index 00000000..c5b804e0 --- /dev/null +++ b/src/test/NodeJS/NpmPrune.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmPrune} from '../../lib/NodeJS/NpmPrune'; + +suite('NodeJS/NpmPrune', function() { + test('Class NpmPrune exists in NodeJS/NpmPrune', function() { + chai.expect(typeof NpmPrune).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmRun.spec.js b/src/test/NodeJS/NpmRun.spec.js new file mode 100644 index 00000000..a3b11fe0 --- /dev/null +++ b/src/test/NodeJS/NpmRun.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmRun} from '../../lib/NodeJS/NpmRun'; + +suite('NodeJS/NpmRun', function() { + test('Class NpmRun exists in NodeJS/NpmRun', function() { + chai.expect(typeof NpmRun).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmShrinkwrap.spec.js b/src/test/NodeJS/NpmShrinkwrap.spec.js new file mode 100644 index 00000000..d075f61e --- /dev/null +++ b/src/test/NodeJS/NpmShrinkwrap.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmShrinkwrap} from '../../lib/NodeJS/NpmShrinkwrap'; + +suite('NodeJS/NpmShrinkwrap', function() { + test('Class NpmShrinkwrap exists in NodeJS/NpmShrinkwrap', function() { + chai.expect(typeof NpmShrinkwrap).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmUninstallLibs.spec.js b/src/test/NodeJS/NpmUninstallLibs.spec.js new file mode 100644 index 00000000..2575c877 --- /dev/null +++ b/src/test/NodeJS/NpmUninstallLibs.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmUninstallLibs} from '../../lib/NodeJS/NpmUninstallLibs'; + +suite('NodeJS/NpmUninstallLibs', function() { + test('Class NpmUninstallLibs exists in NodeJS/NpmUninstallLibs', function() { + chai.expect(typeof NpmUninstallLibs).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/NpmUpdate.spec.js b/src/test/NodeJS/NpmUpdate.spec.js new file mode 100644 index 00000000..7e5f4f27 --- /dev/null +++ b/src/test/NodeJS/NpmUpdate.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {NpmUpdate} from '../../lib/NodeJS/NpmUpdate'; + +suite('NodeJS/NpmUpdate', function() { + test('Class NpmUpdate exists in NodeJS/NpmUpdate', function() { + chai.expect(typeof NpmUpdate).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/PackageVersionResolver.spec.js b/src/test/NodeJS/PackageVersionResolver.spec.js new file mode 100644 index 00000000..bf5be328 --- /dev/null +++ b/src/test/NodeJS/PackageVersionResolver.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {PackageVersionResolver} from '../../lib/NodeJS/PackageVersionResolver'; + +suite('NodeJS/PackageVersionResolver', function() { + test('Class PackageVersionResolver exists in NodeJS/PackageVersionResolver', function() { + chai.expect(typeof PackageVersionResolver).to.equal('function'); + }); +}); diff --git a/src/test/NodeJS/UndefinedDepsResolver.spec.js b/src/test/NodeJS/UndefinedDepsResolver.spec.js new file mode 100644 index 00000000..77f5ec84 --- /dev/null +++ b/src/test/NodeJS/UndefinedDepsResolver.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {UndefinedDepsResolver} from '../../lib/NodeJS/UndefinedDepsResolver'; + +suite('NodeJS/UndefinedDepsResolver', function() { + test('Class UndefinedDepsResolver exists in NodeJS/UndefinedDepsResolver', function() { + chai.expect(typeof UndefinedDepsResolver).to.equal('function'); + }); +}); diff --git a/src/test/Server/Hook.spec.js b/src/test/Server/Hook.spec.js new file mode 100644 index 00000000..911c7a55 --- /dev/null +++ b/src/test/Server/Hook.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {Hook} from '../../lib/Server/Hook'; + +suite('Server/Hook', function() { + test('Class Hook exists in Server/Hook', function() { + chai.expect(typeof Hook).to.equal('function'); + }); +}); diff --git a/src/test/Terminal/Prompt.spec.js b/src/test/Terminal/Prompt.spec.js new file mode 100644 index 00000000..ede27483 --- /dev/null +++ b/src/test/Terminal/Prompt.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +import chai from 'chai'; +import {Prompt} from '../../lib/Terminal/Prompt'; + +suite('Terminal/Prompt', function() { + test('Class Prompt exists in Terminal/Prompt', function() { + chai.expect(typeof Prompt).to.equal('function'); + }); +}); From 4fda3fd573ca52abfa0cfa84528ca48eba5d9877 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 12:07:03 +0200 Subject: [PATCH 066/133] Add new unit test for npm install --- src/test/NodeJS/NpmInstall.spec.js | 52 ++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/test/NodeJS/NpmInstall.spec.js b/src/test/NodeJS/NpmInstall.spec.js index f0cfaf69..45de328e 100644 --- a/src/test/NodeJS/NpmInstall.spec.js +++ b/src/test/NodeJS/NpmInstall.spec.js @@ -22,13 +22,61 @@ suite('NodeJS/NpmInstall', function() { chai.expect(npmInstall._mainCmd).to.includes('npm install'); }); - test('Check constructor sets valid value for _dirs', function () { + test('Check constructor sets valid value for _dirs', function() { chai.expect(npmInstall).to.be.an.instanceOf(NpmInstall); chai.expect(npmInstall.dirs).to.be.eql([]); }); - test('Check constructor sets valid value for _execArgs', function () { + test('Check constructor sets valid value for _extraArgs', function() { + chai.expect(Array.isArray(npmInstall.extraArgs)).to.be.equal(true); + chai.expect(npmInstall.extraArgs).to.eql([]); + }); + + test('Check _execArgs getter', function() { chai.expect(Array.isArray(npmInstall._execArgs)).to.be.equal(true); + chai.expect(npmInstall._execArgs[0]).to.includes('npm install'); + }); + + test('Check addExtraArg()', function() { + let length = npmInstall.extraArgs.length; + let newArg = 'logLevel=debug'; + + let actualResult = npmInstall.addExtraArg(newArg); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs.length).to.equal(++length); + chai.expect(actualResult.extraArgs.pop()).to.equal(newArg); + }); + + test('Check _chunkArray() returns valid array', function() { + let toChunkArray = ['one', 'two', 'three', 'four']; + let expectedResult = [['one', 'two', 'three'], ['four']]; + let size = 3; + + let actualResult = NpmInstall._chunkArray(toChunkArray, size); + + chai.expect(actualResult).to.be.an.instanceOf(Array); + chai.expect(actualResult).to.eql(expectedResult); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmInstall._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs).to.eql([]); + chai.expect(actualResult.dirs).to.eql(args); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha']; + + let actualResult = npmInstall._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs).to.eql([]); + chai.expect(actualResult.dirs).to.eql(args); }); }); From 639bad8812d8d8a3056b2e60e10cdf47e494e2fd Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 12:43:43 +0200 Subject: [PATCH 067/133] Add unit tests for NodeJS>Bin --- src/node-bin/test.sh | 2 +- src/test/NodeJS/Bin.spec.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/node-bin/test.sh b/src/node-bin/test.sh index fee5458b..f30be637 100644 --- a/src/node-bin/test.sh +++ b/src/node-bin/test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash if [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then - babel-node `which isparta` cover --include 'lib/**/*.js' `which _mocha` -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive + babel-node `which isparta` cover --include 'lib/**/*.js' `which _mocha` -- 'test/**/*.spec.js' --reporter spec --ui tdd --recursive --timeout 20s elif [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" else diff --git a/src/test/NodeJS/Bin.spec.js b/src/test/NodeJS/Bin.spec.js index 1e565589..feeea596 100644 --- a/src/test/NodeJS/Bin.spec.js +++ b/src/test/NodeJS/Bin.spec.js @@ -7,4 +7,34 @@ suite('NodeJS/Bin', function() { test('Class Bin exists in NodeJS/Bin', function() { chai.expect(typeof Bin).to.equal('function'); }); + + test('Check npmModuleInstalled() returns true for global mocha', function() { + chai.expect(Bin.npmModuleInstalled('mocha', true)).to.equal(true); + }); + + test('Check npmModuleInstalled() returns true for local fs-extra', function() { + chai.expect(Bin.npmModuleInstalled('fs-extra', false)).to.equal(true); + }); + + test('Check npmMajorVersion returns version above than 1', function() { + chai.expect(Bin.npmMajorVersion).to.be.above(1); + }); + + test('Check nodeMajorVersion returns version above than -1', function() { + chai.expect(Bin.nodeMajorVersion).to.be.above(-1); + }); + + test('Check node returns valid string', function() { + chai.expect(Bin.node).to.contain('node'); + + //check when Bin._node already setted + chai.expect(Bin.node).to.contain('node'); + }); + + test('Check npm returns valid string', function() { + chai.expect(Bin.npm).to.contain('npm'); + + //check when Bin._node already setted + chai.expect(Bin.npm).to.contain('npm'); + }); }); From 7618655ab3857ef7cbb204926f718dcc5a818208 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 13:56:50 +0200 Subject: [PATCH 068/133] Add unit tests for UndefinedDepsResolver --- src/test/NodeJS/NpmDependency.spec.js | 41 ++++++++++++++ src/test/NodeJS/UndefinedDepsResolver.spec.js | 53 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/src/test/NodeJS/NpmDependency.spec.js b/src/test/NodeJS/NpmDependency.spec.js index cfca2b58..c966f736 100644 --- a/src/test/NodeJS/NpmDependency.spec.js +++ b/src/test/NodeJS/NpmDependency.spec.js @@ -4,7 +4,48 @@ import chai from 'chai'; import {NpmDependency} from '../../lib/NodeJS/NpmDependency'; suite('NodeJS/NpmDependency', function() { + let name = 'mocha'; + let version = '2.3.4'; + let npmDependency = new NpmDependency(name, version); + test('Class NpmDependency exists in NodeJS/NpmDependency', function() { chai.expect(typeof NpmDependency).to.equal('function'); }); + + test(`Check constructor sets _name = ${name}`, function() { + chai.expect(npmDependency).to.be.an.instanceOf(NpmDependency); + chai.expect(npmDependency.name).to.equal(name); + }); + + test(`Check constructor sets _version = ${version}`, function() { + chai.expect(npmDependency.version).to.equal(version); + }); + + test(`Check constructor sets _requestedVersion = ${version}`, function() { + chai.expect(npmDependency.requestedVersion).to.equal(version); + }); + + test('Check constructor sets _parent = null', function() { + chai.expect(npmDependency.parent).to.equal(null); + }); + + test('Check constructor sets _children = []', function() { + chai.expect(npmDependency.children).to.eql([]); + }); + + test('Check constructor sets isMain = false by default', function() { + chai.expect(npmDependency.isMain).to.eql(false); + }); + + test('Check constructor sets _defaultRootPath = ""', function() { + chai.expect(npmDependency.defaultRootPath).to.eql(''); + }); + + test(`Check fullName returns ${name}@${version}`, function() { + chai.expect(npmDependency.fullName).to.eql(`${name}@${version}`); + }); + + test('Check NODE_MODULES_DIR', function() { + chai.expect(NpmDependency.NODE_MODULES_DIR).to.equal('node_modules'); + }); }); diff --git a/src/test/NodeJS/UndefinedDepsResolver.spec.js b/src/test/NodeJS/UndefinedDepsResolver.spec.js index 77f5ec84..161eb30e 100644 --- a/src/test/NodeJS/UndefinedDepsResolver.spec.js +++ b/src/test/NodeJS/UndefinedDepsResolver.spec.js @@ -2,9 +2,62 @@ import chai from 'chai'; import {UndefinedDepsResolver} from '../../lib/NodeJS/UndefinedDepsResolver'; +import {NpmDependency} from '../../lib/NodeJS/NpmDependency'; suite('NodeJS/UndefinedDepsResolver', function() { + let name = 'mocha'; + let version = '2.3.4'; + let mainDep = new NpmDependency(name, version, true); + let undefinedDepsResolver = new UndefinedDepsResolver(mainDep); + test('Class UndefinedDepsResolver exists in NodeJS/UndefinedDepsResolver', function() { chai.expect(typeof UndefinedDepsResolver).to.equal('function'); }); + + test('Check UndefinedDepsResolver constructor throws Error for !mainDep.isMain', function() { + let error = null; + let mainDep = new NpmDependency(name, version, false); + + try { + undefinedDepsResolver = new UndefinedDepsResolver(mainDep); + } catch (e) { + error = e; + } + + chai.expect(error, 'error is an instance of Error').to.be.an.instanceOf(Error); + chai.expect(error.message).to.equal(`Npm dependency ${mainDep.fullName} is not the deps tree root`); + }); + + test('Check UndefinedDepsResolver constructor throws Error for !mainDep.isMain', + function() { + let error = null; + let mainDep = new NpmDependency(name, null, true); + + try { + undefinedDepsResolver = new UndefinedDepsResolver(mainDep); + } catch (e) { + error = e; + } + + chai.expect(error, 'error is an instance of Error').to.be.an.instanceOf(Error); + chai.expect(error.message).to.equal(`Npm main dependency version have to be defined in ${mainDep.fullName}`); + } + ); + + test('Check constructor sets _mainDep', function() { + chai.expect(undefinedDepsResolver).to.be.an.instanceOf(UndefinedDepsResolver); + chai.expect(undefinedDepsResolver.mainDep).to.equal(mainDep); + }); + + test('Check constructor sets _undefinedStack', function() { + chai.expect(undefinedDepsResolver._undefinedStack).to.eql([]); + }); + + test('Check constructor sets _cloneShadow', function() { + chai.expect(undefinedDepsResolver._cloneShadow).to.eql({}); + }); + + test('Check constructor sets _resolvedStack', function() { + chai.expect(undefinedDepsResolver._resolvedStack).to.eql({}); + }); }); From 1cfb182fd7286fc2058a17ecd8109420014e69ff Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 15:49:08 +0200 Subject: [PATCH 069/133] Add new unit tests for NpmRun --- src/test/NodeJS/NpmRun.spec.js | 30 +++++++++++++++ .../NodeJS/PackageVersionResolver.spec.js | 37 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/test/NodeJS/NpmRun.spec.js b/src/test/NodeJS/NpmRun.spec.js index a3b11fe0..fd830be1 100644 --- a/src/test/NodeJS/NpmRun.spec.js +++ b/src/test/NodeJS/NpmRun.spec.js @@ -2,9 +2,39 @@ import chai from 'chai'; import {NpmRun} from '../../lib/NodeJS/NpmRun'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmRun', function() { + let args = 'mocha -g'; + let npmRun = null; + test('Class NpmRun exists in NodeJS/NpmRun', function() { chai.expect(typeof NpmRun).to.equal('function'); }); + + test('Check constructor sets _cmd = null', function() { + npmRun = new NpmRun(args); + chai.expect(npmRun).to.be.an.instanceOf(NpmRun); + chai.expect(npmRun.cmd).to.equal(null); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmRun._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs).to.eql([]); + chai.expect(actualResult.dirs).to.eql(args); + }); + + test('Check cmd setter', function() { + npmRun.cmd = args; + + chai.expect(npmRun._mainCmd).to.includes('npm run'); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmRun._mainCmd).to.includes(`npm run ${args}`); + }); }); diff --git a/src/test/NodeJS/PackageVersionResolver.spec.js b/src/test/NodeJS/PackageVersionResolver.spec.js index bf5be328..96a711dd 100644 --- a/src/test/NodeJS/PackageVersionResolver.spec.js +++ b/src/test/NodeJS/PackageVersionResolver.spec.js @@ -4,7 +4,44 @@ import chai from 'chai'; import {PackageVersionResolver} from '../../lib/NodeJS/PackageVersionResolver'; suite('NodeJS/PackageVersionResolver', function() { + let name = 'mocha'; + let version = '2.3.4'; + let nameWithVersion = 'mocha@2.3.4'; + let packagePath = './packagePath'; + let packageVersionResolver = null; + + test('Class PackageVersionResolver exists in NodeJS/PackageVersionResolver', function() { chai.expect(typeof PackageVersionResolver).to.equal('function'); }); + + test('Check constructor for !version', function() { + packageVersionResolver = new PackageVersionResolver(packagePath, nameWithVersion, null); + + chai.expect(packageVersionResolver).to.be.an.instanceOf(PackageVersionResolver); + + chai.expect(packageVersionResolver.packagePath).to.equal(packagePath); + chai.expect(packageVersionResolver.name).to.equal(name); + chai.expect(packageVersionResolver.version).to.equal(version); + }); + + test('Check constructor for version', function() { + packageVersionResolver = new PackageVersionResolver(packagePath, name, version); + + chai.expect(packageVersionResolver).to.be.an.instanceOf(PackageVersionResolver); + + chai.expect(packageVersionResolver.packagePath).to.equal(packagePath); + chai.expect(packageVersionResolver.name).to.equal(name); + chai.expect(packageVersionResolver.version).to.equal(version); + }); + + test('Check _command() returns valid string', function() { + chai.expect(packageVersionResolver._command).to.contain( + `npm ls --loglevel silent --json ${packageVersionResolver._fullName}` + ); + }); + + test('Check _fullName() returns valid string', function() { + chai.expect(packageVersionResolver._fullName).to.equal(`${name}@'${version}'`); + }); }); From 9b9fac5457a920a94f540fa17aa1316e40db8a44 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 16:02:09 +0200 Subject: [PATCH 070/133] Add new unit tests for NpmPrune --- src/test/NodeJS/NpmPrune.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/NodeJS/NpmPrune.spec.js b/src/test/NodeJS/NpmPrune.spec.js index c5b804e0..f654adc9 100644 --- a/src/test/NodeJS/NpmPrune.spec.js +++ b/src/test/NodeJS/NpmPrune.spec.js @@ -2,9 +2,32 @@ import chai from 'chai'; import {NpmPrune} from '../../lib/NodeJS/NpmPrune'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmPrune', function() { + let args = 'mocha -g'; + let npmPrune = null; + test('Class NpmPrune exists in NodeJS/NpmPrune', function() { chai.expect(typeof NpmPrune).to.equal('function'); }); + + test('Check constructor sets _cmd = null', function() { + npmPrune = new NpmPrune(args); + chai.expect(npmPrune).to.be.an.instanceOf(NpmPrune); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmPrune._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs).to.eql([]); + chai.expect(actualResult.dirs).to.eql(args); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmPrune._mainCmd).to.includes('npm prune'); + }); }); From 337efdded0bf8c53e30312d024573036bf514e11 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 16:26:37 +0200 Subject: [PATCH 071/133] Add unit tests for NpmLink --- src/test/NodeJS/NpmLink.spec.js | 32 ++++++++++++++++++++++++++++++++ src/test/NodeJS/NpmPrune.spec.js | 4 ++-- src/test/NodeJS/NpmRun.spec.js | 10 +++++----- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/test/NodeJS/NpmLink.spec.js b/src/test/NodeJS/NpmLink.spec.js index 99cc6da2..6efd3bde 100644 --- a/src/test/NodeJS/NpmLink.spec.js +++ b/src/test/NodeJS/NpmLink.spec.js @@ -2,9 +2,41 @@ import chai from 'chai'; import {NpmLink} from '../../lib/NodeJS/NpmLink'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmLink', function() { + let libs = 'mocha isparta'; + let libsArray = ['codacy-coverage', 'istanbul']; + let npmLink = null; + test('Class NpmLink exists in NodeJS/NpmLink', function() { chai.expect(typeof NpmLink).to.equal('function'); }); + + test('Check constructor sets _libsPlain = null', function() { + npmLink = new NpmLink(); + chai.expect(npmLink).to.be.an.instanceOf(NpmLink); + chai.expect(npmLink.libsPlain).to.equal(null); + }); + + test('Check _libsPlain setter', function() { + npmLink.libs = libsArray; + chai.expect(npmLink.libsPlain).to.equal(libsArray.join(' ')); + + npmLink.libs = libs; + chai.expect(npmLink.libsPlain).to.equal(libs); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmLink._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.libsPlain).to.equal(libs); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmLink._mainCmd).to.includes(`npm link ${libs}`); + }); }); diff --git a/src/test/NodeJS/NpmPrune.spec.js b/src/test/NodeJS/NpmPrune.spec.js index f654adc9..584c8fc7 100644 --- a/src/test/NodeJS/NpmPrune.spec.js +++ b/src/test/NodeJS/NpmPrune.spec.js @@ -5,7 +5,7 @@ import {NpmPrune} from '../../lib/NodeJS/NpmPrune'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmPrune', function() { - let args = 'mocha -g'; + let args = 'dirs'; let npmPrune = null; test('Class NpmPrune exists in NodeJS/NpmPrune', function() { @@ -13,7 +13,7 @@ suite('NodeJS/NpmPrune', function() { }); test('Check constructor sets _cmd = null', function() { - npmPrune = new NpmPrune(args); + npmPrune = new NpmPrune(); chai.expect(npmPrune).to.be.an.instanceOf(NpmPrune); }); diff --git a/src/test/NodeJS/NpmRun.spec.js b/src/test/NodeJS/NpmRun.spec.js index fd830be1..cf382a9f 100644 --- a/src/test/NodeJS/NpmRun.spec.js +++ b/src/test/NodeJS/NpmRun.spec.js @@ -5,15 +5,15 @@ import {NpmRun} from '../../lib/NodeJS/NpmRun'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmRun', function() { - let args = 'mocha -g'; let npmRun = null; + let cmd = 'test'; test('Class NpmRun exists in NodeJS/NpmRun', function() { chai.expect(typeof NpmRun).to.equal('function'); }); test('Check constructor sets _cmd = null', function() { - npmRun = new NpmRun(args); + npmRun = new NpmRun(); chai.expect(npmRun).to.be.an.instanceOf(NpmRun); chai.expect(npmRun.cmd).to.equal(null); }); @@ -29,12 +29,12 @@ suite('NodeJS/NpmRun', function() { }); test('Check cmd setter', function() { - npmRun.cmd = args; + npmRun.cmd = cmd; - chai.expect(npmRun._mainCmd).to.includes('npm run'); + chai.expect(npmRun.cmd).to.equal(cmd); }); test('Check _mainCmd getter returns valid string', function() { - chai.expect(npmRun._mainCmd).to.includes(`npm run ${args}`); + chai.expect(npmRun._mainCmd).to.includes(`npm run ${cmd}`); }); }); From 2758cd206fd8d36c2e40efaa3bc0393f2e2c5266 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 1 Feb 2016 16:54:51 +0200 Subject: [PATCH 072/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index a6b70f03..8619d574 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.4", + "version": "1.6.5", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 6ac140d60585f21f50b273255658878331e453fa Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 1 Feb 2016 18:50:53 +0200 Subject: [PATCH 073/133] Fix local server lambda run --- src/bin/commands/enable-ssl.js | 2 +- src/lib/Lambda/Runtime.js | 15 +++++++++++---- src/lib/Lambda/thread_wrapper.js | 6 ++++++ src/lib/Server/Instance.js | 25 +++++++++++++++++++++---- src/package.json | 2 +- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/bin/commands/enable-ssl.js b/src/bin/commands/enable-ssl.js index 1a179860..4f2fb202 100644 --- a/src/bin/commands/enable-ssl.js +++ b/src/bin/commands/enable-ssl.js @@ -30,7 +30,7 @@ module.exports = function(mainPath) { var deployConfig = fse.readJsonSync(deployConfigFile); if (domain) { - let config = null; + var config = null; config = fse.readJsonSync(propertyConfigFile); config.domain = domain; diff --git a/src/lib/Lambda/Runtime.js b/src/lib/Lambda/Runtime.js index dabe8ef8..7fddc150 100644 --- a/src/lib/Lambda/Runtime.js +++ b/src/lib/Lambda/Runtime.js @@ -96,6 +96,13 @@ export class Runtime { return this._name; } + /** + * @returns {String} + */ + get arnName() { + return this._name.replace(/\-\d+$/i, ''); + } + /** * @param {String} name */ @@ -177,7 +184,7 @@ export class Runtime { invokeAsync: function (localPath, data, callback) { this.invoke(localPath, data, (error, result) => { if (error) { - _this._log(`Lambda ${data.lambda} async execution fail: ${error.message}`); + _this._log(`Lambda ${data.lambda} async execution fail`, error); return; } @@ -276,12 +283,12 @@ export class Runtime { /** make the context Lambda alike */ awsRequestId: '6bde10dc-a329-11e5-8f4d-55470b0a5783', invokeid: '6bde10dc-a329-11e5-8f4d-55470b0a5783', - logGroupName: `/aws/lambda/${this._name}`, + logGroupName: `/aws/lambda/${this.arnName}`, logStreamName: `${logStreamDate}/${logStreamDate}[$LATEST]e680b516b0ea402eb3ff38f10b40a264`, - functionName: this._name, + functionName: this.arnName, memoryLimitInMB: '128', functionVersion: '$LATEST', - invokedFunctionArn: `arn:aws:lambda:::function:${this._name}`, + invokedFunctionArn: `arn:aws:lambda:::function:${this.arnName}`, clientContext: { EnvironmentName: Runtime.ENVIRONMENT, diff --git a/src/lib/Lambda/thread_wrapper.js b/src/lib/Lambda/thread_wrapper.js index c2a44eca..78ab3819 100644 --- a/src/lib/Lambda/thread_wrapper.js +++ b/src/lib/Lambda/thread_wrapper.js @@ -53,6 +53,12 @@ runtime.name = rawRuntime._name; runtime.fail = (error) => { if (assureContextNotSent(error)) { + if (typeof error !== 'string') { + try { + error = JSON.parse(error); + } catch (e) {} + } + process.send({ state: 'fail', args: [error], diff --git a/src/lib/Server/Instance.js b/src/lib/Server/Instance.js index e2aad2d9..8ac25cf4 100644 --- a/src/lib/Server/Instance.js +++ b/src/lib/Server/Instance.js @@ -390,7 +390,7 @@ export class Instance { lambda.name = `${lambdaConfig.name}-${this.localId}`; - lambda.succeed = (result) => { + let successCb = (result) => { let plainResult = JSON.stringify(result); if (!asyncMode) { @@ -401,12 +401,29 @@ export class Instance { } }; + lambda.succeed = successCb; + lambda.fail = (error) => { + let errorObj = error; + + if (typeof error === 'object' && error instanceof Error) { + errorObj = { + errorType: error.name, + errorMessage: error.message, + errorStack: error.stack + }; + + if (error.validationErrors) { + errorObj.validationErrors = error.validationErrors; + } + } + if (!asyncMode) { - this._log(`Lambda ${lambdaConfig.name} execution fail: ${error.message}`); - this._send500(response, error); + this._log(`Lambda ${lambdaConfig.name} execution fail`, errorObj.errorMessage); + + successCb(errorObj); } else { - this._log(`Lambda ${lambdaConfig.name} async execution fail: ${error.message}`); + this._log(`Lambda ${lambdaConfig.name} async execution fail`, errorObj.errorMessage); } }; diff --git a/src/package.json b/src/package.json index 8619d574..f60af446 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.5", + "version": "1.6.6", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From f67a49877070a07ceee53244d45eb8bdd1b3eb03 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Mon, 1 Feb 2016 19:05:21 +0200 Subject: [PATCH 074/133] Add new unit test for NodeJS --- src/test/NodeJS/NpmChain.spec.js | 26 +++++++++++++++ src/test/NodeJS/NpmDedupe.spec.js | 22 +++++++++++++ src/test/NodeJS/NpmInstallLibs.spec.js | 42 ++++++++++++++++++++++++ src/test/NodeJS/NpmPrune.spec.js | 1 - src/test/NodeJS/NpmShrinkwrap.spec.js | 22 +++++++++++++ src/test/NodeJS/NpmUninstallLibs.spec.js | 32 ++++++++++++++++++ src/test/NodeJS/NpmUpdate.spec.js | 22 +++++++++++++ 7 files changed, 166 insertions(+), 1 deletion(-) diff --git a/src/test/NodeJS/NpmChain.spec.js b/src/test/NodeJS/NpmChain.spec.js index a3f4a9ed..5885b525 100644 --- a/src/test/NodeJS/NpmChain.spec.js +++ b/src/test/NodeJS/NpmChain.spec.js @@ -2,9 +2,35 @@ import chai from 'chai'; import {NpmChain} from '../../lib/NodeJS/NpmChain'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; +import {NpmLink} from '../../lib/NodeJS/NpmLink'; +import {NpmUpdate} from '../../lib/NodeJS/NpmUpdate'; suite('NodeJS/NpmChain', function() { + let npmLink = null; + let npmUpdate = new NpmUpdate(); + let npmChain = null; + test('Class NpmChain exists in NodeJS/NpmChain', function() { chai.expect(typeof NpmChain).to.equal('function'); }); + + test('Check constructor sets _commands', function() { + let libs = 'mocha isparta'; + npmLink = new NpmLink(); + npmLink.libs = libs; + + npmChain = new NpmChain(npmLink); + chai.expect(npmChain).to.be.an.instanceOf(NpmChain); + chai.expect(npmChain.commands[0]).to.be.an.instanceOf(NpmInstall); + chai.expect(npmChain.commands).to.be.eql([npmLink]); + }); + + //@todo - use other chai assert + test('Check add() adds command', function() { + npmChain.add(npmUpdate); + chai.expect(npmChain).to.be.an.instanceOf(NpmChain); + chai.expect(npmChain.commands[npmChain.commands.length-1]).to.be.an.instanceOf(NpmInstall); + chai.expect(npmChain.commands).to.be.eql([npmLink, npmUpdate]); + }); }); diff --git a/src/test/NodeJS/NpmDedupe.spec.js b/src/test/NodeJS/NpmDedupe.spec.js index 00f66ec5..032d7f7d 100644 --- a/src/test/NodeJS/NpmDedupe.spec.js +++ b/src/test/NodeJS/NpmDedupe.spec.js @@ -2,9 +2,31 @@ import chai from 'chai'; import {NpmDedupe} from '../../lib/NodeJS/NpmDedupe'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmDedupe', function() { + let npmDedupe = null; + test('Class NpmDedupe exists in NodeJS/NpmDedupe', function() { chai.expect(typeof NpmDedupe).to.equal('function'); }); + + test('Check constructor sets _cmd = null', function() { + npmDedupe = new NpmDedupe(); + chai.expect(npmDedupe).to.be.an.instanceOf(NpmDedupe); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmDedupe._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs).to.eql([]); + chai.expect(actualResult.dirs).to.eql(args); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmDedupe._mainCmd).to.includes('npm dedupe'); + }); }); diff --git a/src/test/NodeJS/NpmInstallLibs.spec.js b/src/test/NodeJS/NpmInstallLibs.spec.js index bb20a4b8..380eded3 100644 --- a/src/test/NodeJS/NpmInstallLibs.spec.js +++ b/src/test/NodeJS/NpmInstallLibs.spec.js @@ -2,9 +2,51 @@ import chai from 'chai'; import {NpmInstallLibs} from '../../lib/NodeJS/NpmInstallLibs'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmInstallLibs', function() { + let libs = 'mocha isparta'; + let libsArray = ['codacy-coverage', 'istanbul']; + let npmInstallLibs = null; + test('Class NpmInstallLibs exists in NodeJS/NpmInstallLibs', function() { chai.expect(typeof NpmInstallLibs).to.equal('function'); }); + + test('Check constructor sets _libsPlain = null, global = false', function() { + npmInstallLibs = new NpmInstallLibs(); + chai.expect(npmInstallLibs).to.be.an.instanceOf(NpmInstallLibs); + chai.expect(npmInstallLibs.libsPlain).to.equal(null); + chai.expect(npmInstallLibs.global).to.equal(false); + }); + + test('Check _libsPlain setter', function() { + npmInstallLibs.libs = libsArray; + chai.expect(npmInstallLibs.libsPlain).to.equal(libsArray.join(' ')); + + npmInstallLibs.libs = libs; + chai.expect(npmInstallLibs.libsPlain).to.equal(libs); + }); + + test('Check global setter', function() { + npmInstallLibs.global = false; + chai.expect(npmInstallLibs.global).to.equal(false); + + npmInstallLibs.global = true; + chai.expect(npmInstallLibs.global).to.equal(true); + chai.expect(npmInstallLibs.dirs).to.eql([process.cwd()]); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmInstallLibs._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.libsPlain).to.equal(libs); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmInstallLibs._mainCmd).to.includes(`npm install ${libs}`); + }); }); diff --git a/src/test/NodeJS/NpmPrune.spec.js b/src/test/NodeJS/NpmPrune.spec.js index 584c8fc7..72e73e41 100644 --- a/src/test/NodeJS/NpmPrune.spec.js +++ b/src/test/NodeJS/NpmPrune.spec.js @@ -5,7 +5,6 @@ import {NpmPrune} from '../../lib/NodeJS/NpmPrune'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmPrune', function() { - let args = 'dirs'; let npmPrune = null; test('Class NpmPrune exists in NodeJS/NpmPrune', function() { diff --git a/src/test/NodeJS/NpmShrinkwrap.spec.js b/src/test/NodeJS/NpmShrinkwrap.spec.js index d075f61e..8dc0515a 100644 --- a/src/test/NodeJS/NpmShrinkwrap.spec.js +++ b/src/test/NodeJS/NpmShrinkwrap.spec.js @@ -2,9 +2,31 @@ import chai from 'chai'; import {NpmShrinkwrap} from '../../lib/NodeJS/NpmShrinkwrap'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmShrinkwrap', function() { + let npmShrinkwrap = null; + test('Class NpmShrinkwrap exists in NodeJS/NpmShrinkwrap', function() { chai.expect(typeof NpmShrinkwrap).to.equal('function'); }); + + test('Check constructor sets _cmd = null', function() { + npmShrinkwrap = new NpmShrinkwrap(); + chai.expect(npmShrinkwrap).to.be.an.instanceOf(NpmShrinkwrap); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmShrinkwrap._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs).to.eql([]); + chai.expect(actualResult.dirs).to.eql(args); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmShrinkwrap._mainCmd).to.includes('npm shrinkwrap'); + }); }); diff --git a/src/test/NodeJS/NpmUninstallLibs.spec.js b/src/test/NodeJS/NpmUninstallLibs.spec.js index 2575c877..bade8d75 100644 --- a/src/test/NodeJS/NpmUninstallLibs.spec.js +++ b/src/test/NodeJS/NpmUninstallLibs.spec.js @@ -2,9 +2,41 @@ import chai from 'chai'; import {NpmUninstallLibs} from '../../lib/NodeJS/NpmUninstallLibs'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmUninstallLibs', function() { + let libs = 'mocha isparta'; + let libsArray = ['codacy-coverage', 'istanbul']; + let npmUninstallLibs = null; + test('Class NpmUninstallLibs exists in NodeJS/NpmUninstallLibs', function() { chai.expect(typeof NpmUninstallLibs).to.equal('function'); }); + + test('Check constructor sets _libsPlain = null', function() { + npmUninstallLibs = new NpmUninstallLibs(); + chai.expect(npmUninstallLibs).to.be.an.instanceOf(NpmUninstallLibs); + chai.expect(npmUninstallLibs.libsPlain).to.equal(null); + }); + + test('Check _libsPlain setter', function() { + npmUninstallLibs.libs = libsArray; + chai.expect(npmUninstallLibs.libsPlain).to.equal(libsArray.join(' ')); + + npmUninstallLibs.libs = libs; + chai.expect(npmUninstallLibs.libsPlain).to.equal(libs); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmUninstallLibs._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.libsPlain).to.equal(libs); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmUninstallLibs._mainCmd).to.includes(`npm uninstall ${libs}`); + }); }); diff --git a/src/test/NodeJS/NpmUpdate.spec.js b/src/test/NodeJS/NpmUpdate.spec.js index 7e5f4f27..74439383 100644 --- a/src/test/NodeJS/NpmUpdate.spec.js +++ b/src/test/NodeJS/NpmUpdate.spec.js @@ -2,9 +2,31 @@ import chai from 'chai'; import {NpmUpdate} from '../../lib/NodeJS/NpmUpdate'; +import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; suite('NodeJS/NpmUpdate', function() { + let npmUpdate = null; + test('Class NpmUpdate exists in NodeJS/NpmUpdate', function() { chai.expect(typeof NpmUpdate).to.equal('function'); }); + + test('Check constructor sets _cmd = null', function() { + npmUpdate = new NpmUpdate(); + chai.expect(npmUpdate).to.be.an.instanceOf(NpmUpdate); + }); + + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + let args = ['mocha', '-g', 'logLevel=debug']; + + let actualResult = npmUpdate._newInstance(args); + + chai.expect(actualResult).to.be.an.instanceOf(NpmInstall); + chai.expect(actualResult.extraArgs).to.eql([]); + chai.expect(actualResult.dirs).to.eql(args); + }); + + test('Check _mainCmd getter returns valid string', function() { + chai.expect(npmUpdate._mainCmd).to.includes('npm update'); + }); }); From 48a23ebbfb20fefc4463ff2da8a29ee50215070a Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 1 Feb 2016 19:21:27 +0200 Subject: [PATCH 075/133] Fix validationSchemas invalidation --- src/lib/Helpers/ValidationSchemasSync.js | 4 ++-- src/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/Helpers/ValidationSchemasSync.js b/src/lib/Helpers/ValidationSchemasSync.js index c7b84ade..ebece279 100644 --- a/src/lib/Helpers/ValidationSchemasSync.js +++ b/src/lib/Helpers/ValidationSchemasSync.js @@ -101,8 +101,8 @@ export class ValidationSchemasSync { lambdas.forEach((lambdaPath) => { let schemasPath = path.join(lambdaPath, Core.AWS.Lambda.Runtime.VALIDATION_SCHEMAS_DIR); - if (fs.existsSync(validationSchemas)) { - fse.removeSync(validationSchemas); + if (fs.existsSync(schemasPath)) { + fse.removeSync(schemasPath); } validationSchemas.forEach((schema) => { diff --git a/src/package.json b/src/package.json index f60af446..f59def87 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.6", + "version": "1.6.7", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From f5d892a473392c99826769170f8d0a178e306d2d Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 10:40:51 +0200 Subject: [PATCH 076/133] Adding new unit tests for NpmListDependencies --- src/test/NodeJS/NpmChain.spec.js | 7 ++--- src/test/NodeJS/NpmListDependencies.spec.js | 31 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/test/NodeJS/NpmChain.spec.js b/src/test/NodeJS/NpmChain.spec.js index 5885b525..7addcbb0 100644 --- a/src/test/NodeJS/NpmChain.spec.js +++ b/src/test/NodeJS/NpmChain.spec.js @@ -23,14 +23,13 @@ suite('NodeJS/NpmChain', function() { npmChain = new NpmChain(npmLink); chai.expect(npmChain).to.be.an.instanceOf(NpmChain); chai.expect(npmChain.commands[0]).to.be.an.instanceOf(NpmInstall); - chai.expect(npmChain.commands).to.be.eql([npmLink]); + chai.expect(npmChain.commands).to.include(npmLink); }); - //@todo - use other chai assert test('Check add() adds command', function() { npmChain.add(npmUpdate); chai.expect(npmChain).to.be.an.instanceOf(NpmChain); - chai.expect(npmChain.commands[npmChain.commands.length-1]).to.be.an.instanceOf(NpmInstall); - chai.expect(npmChain.commands).to.be.eql([npmLink, npmUpdate]); + chai.expect(npmChain.commands).to.include(npmLink); + chai.expect(npmChain.commands).to.include(npmUpdate); }); }); diff --git a/src/test/NodeJS/NpmListDependencies.spec.js b/src/test/NodeJS/NpmListDependencies.spec.js index 3e7aacfc..866f3828 100644 --- a/src/test/NodeJS/NpmListDependencies.spec.js +++ b/src/test/NodeJS/NpmListDependencies.spec.js @@ -2,9 +2,40 @@ import chai from 'chai'; import {NpmListDependencies} from '../../lib/NodeJS/NpmListDependencies'; +import {NpmDependency} from '../../lib/NodeJS/NpmDependency'; +import {NpmDepsListException} from '../../lib/NodeJS/Exception/NpmDepsListException'; suite('NodeJS/NpmListDependencies', function() { + let npmListDependencies = null + test('Class NpmListDependencies exists in NodeJS/NpmListDependencies', function() { chai.expect(typeof NpmListDependencies).to.equal('function'); }); + + test('Check constructor sets _path', function() { + let currentDirectory = __dirname; + npmListDependencies = new NpmListDependencies(currentDirectory); + chai.expect(npmListDependencies).to.be.an.instanceOf(NpmListDependencies); + chai.expect(npmListDependencies.path).to.equal(currentDirectory); + }); + + test('Check list(0)', function() { + let actualResult = npmListDependencies.list(0); + + chai.expect(actualResult).to.be.an.instanceOf(NpmDependency); + }); + + test('Check list() throws NpmDepsListException', function() { + let error = null; + + npmListDependencies = new NpmListDependencies('invalidPath'); + + try { + npmListDependencies.list(0); + } catch (e) { + error = e; + } + + chai.expect(error).to.be.an.instanceOf(NpmDepsListException); + }); }); From 937420cbae197e4d8593b31b61d01c2dd262da3e Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 12:06:54 +0200 Subject: [PATCH 077/133] Adding unit tests Timer --- src/lib/Lambda/Timer.js | 1 + src/test/Lambda/Timer.spec.js | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/lib/Lambda/Timer.js b/src/lib/Lambda/Timer.js index bfb0b28c..e47def68 100644 --- a/src/lib/Lambda/Timer.js +++ b/src/lib/Lambda/Timer.js @@ -64,6 +64,7 @@ export class Timer { get time() { if(!this.startTime) { this._startTime = this.stopTime || new Date().getTime(); + console.log('this._startTime: ', this._startTime); this.stop(); } diff --git a/src/test/Lambda/Timer.spec.js b/src/test/Lambda/Timer.spec.js index 7288df50..ae4943b2 100644 --- a/src/test/Lambda/Timer.spec.js +++ b/src/test/Lambda/Timer.spec.js @@ -4,7 +4,84 @@ import chai from 'chai'; import {Timer} from '../../lib/Lambda/Timer'; suite('Lambda/Timer', function() { + let name = 'testName'; + let timer = null; + let approxStartTime = null; + let approxStoptTime = null; + test('Class Timer exists in Lambda/Timer', function() { chai.expect(typeof Timer).to.equal('function'); }); + + test('Check constructor sets _name, _startTime, _stopTime', function() { + timer = new Timer(name); + + chai.expect(timer).to.be.an.instanceOf(Timer); + chai.expect(timer.name).to.equal(name); + chai.expect(timer.startTime).to.equal(null); + chai.expect(timer.startTimeSec).to.equal(null); + chai.expect(timer.stopTime).to.equal(null); + chai.expect(timer.stopTimeSec).to.equal(null); + }); + + test('Check start()', function() { + approxStartTime = new Date().getTime(); + + let actualResult = timer.start(); + + chai.expect(timer).to.be.an.instanceOf(Timer); + chai.expect(actualResult.startTime).to.be.at.least(approxStartTime); + chai.expect(actualResult.startTimeSec).to.be.at.least( + parseFloat((approxStartTime / 1000).toFixed(2)) + ); + }); + + test('Check stop()', function() { + let actualResult = timer.stop(); + + approxStoptTime = new Date().getTime(); + + chai.expect(timer).to.be.an.instanceOf(Timer); + chai.expect(approxStoptTime).to.be.at.least(actualResult.stopTime); + chai.expect( + parseFloat((approxStoptTime / 1000).toFixed(2)) + ).to.be.at.least(actualResult.stopTimeSec); + }); + + test('Check time getter', function() { + let expectedResult = approxStoptTime - approxStartTime; + + chai.expect(expectedResult).to.be.at.least(timer.time); + chai.expect( + parseFloat((expectedResult / 1000).toFixed(2)) + ).to.be.at.least(timer.timeSec); + }); + + test('Check toString() for sec', function() { + chai.expect(timer.toString()).to.equal( + `Timing for ${name}: ${timer.timeSec} seconds` + ); + }); + + test('Check toString() for !sec', function() { + chai.expect(timer.toString(false)).to.equal( + `Timing for ${name}: ${timer.time} miliseconds` + ); + }); + + test('Check time for !startTime', function() { + //arrange + approxStartTime = new Date().getTime(); + + timer = new Timer(name); + + //act + let actualResult = timer.time; + + approxStoptTime = new Date().getTime(); + let expectedResult = approxStoptTime - approxStartTime; + + //assert + chai.expect(expectedResult).to.be.at.least(actualResult); + }); }); From fb11a5d6c8c709499efb2fbc01bb1e3e2e2b687b Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 12:07:34 +0200 Subject: [PATCH 078/133] Adding unit tests Timer --- src/lib/Lambda/Timer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/Lambda/Timer.js b/src/lib/Lambda/Timer.js index e47def68..bfb0b28c 100644 --- a/src/lib/Lambda/Timer.js +++ b/src/lib/Lambda/Timer.js @@ -64,7 +64,6 @@ export class Timer { get time() { if(!this.startTime) { this._startTime = this.stopTime || new Date().getTime(); - console.log('this._startTime: ', this._startTime); this.stop(); } From 04f16427cd48ad4c504a38803f8017eccafdebd9 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 14:22:08 +0200 Subject: [PATCH 079/133] Add unit tests for ForksManager --- .jshint.airbnb.json | 2 +- src/test/Lambda/ForksManager.spec.js | 64 +++++++++++++++++++++++++++- src/test/PathToForked/child.js | 18 ++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/test/PathToForked/child.js diff --git a/.jshint.airbnb.json b/.jshint.airbnb.json index 60ce80a5..4ec00310 100644 --- a/.jshint.airbnb.json +++ b/.jshint.airbnb.json @@ -8,7 +8,7 @@ "eqeqeq": true, "indent": 2, "latedef": true, - "maxlen": 80, + "maxlen": 120, "newcap": true, "quotmark": "single", "strict": true, diff --git a/src/test/Lambda/ForksManager.spec.js b/src/test/Lambda/ForksManager.spec.js index 39875e8f..f74ac7ff 100644 --- a/src/test/Lambda/ForksManager.spec.js +++ b/src/test/Lambda/ForksManager.spec.js @@ -2,9 +2,69 @@ import chai from 'chai'; import {ForksManager} from '../../lib/Lambda/ForksManager'; +import ChildProcess from 'child_process'; +import path from 'path'; -suite('Lambda/ForksManager', function() { - test('Class ForksManager exists in Lambda/ForksManager', function() { +suite('Lambda/ForksManager', function () { + test('Class ForksManager exists in Lambda/ForksManager', function () { chai.expect(typeof ForksManager).to.equal('function'); }); + + test('Check STORAGE_KEY static getter', function () { + chai.expect(ForksManager.STORAGE_KEY).to.equal('_deep_fm_forks_'); + }); + + test('Check SIGKILL_KEY static getter', function () { + chai.expect(ForksManager.SIGKILL_KEY).to.equal('_deep_fm_sigkill_'); + }); + + test('Check _isManaged static getter return false', function () { + chai.expect(ForksManager._isManaged, '_isManaged returns false').to.equal(false); + }); + + test('Check _wasMainProcessKilled static getter return false', function () { + chai.expect(ForksManager._wasMainProcessKilled, '_wasMainProcessKilled returns false').to.equal(false); + }); + + test('Check _isForksStackEmpty static getter return true', function () { + chai.expect(ForksManager._isForksStackEmpty, '_isForksStackEmpty returns false').to.equal(true); + }); + + test('Check manage() for !ForksManager._isManaged', function () { + let fork = ChildProcess.fork(path.join(__dirname + './../PathToForked/child')); + + let actualResult = ForksManager.manage(fork); + + chai.expect(actualResult, 'returns undefined').to.equal(undefined); + chai.expect(ForksManager._isManaged, '_isManaged returns false').to.equal(false); + chai.expect(ForksManager._wasMainProcessKilled, '_wasMainProcessKilled returns false').to.equal(false); + chai.expect(ForksManager._isForksStackEmpty, '_isForksStackEmpty returns false').to.equal(true); + }); + + test('Check registerListener() for !ForksManager._isManaged', function () { + ForksManager.registerListener(); + + chai.expect(ForksManager._isManaged, '_isManaged returns true').to.equal(true); + chai.expect(ForksManager._isForksStackEmpty, '_isForksStackEmpty returns true').to.equal(true); + chai.expect(ForksManager._wasMainProcessKilled, '_wasMainProcessKilled returns false').to.equal(false); + }); + + test('Check manage() > _addForkToStack() ', function() { + let fork = ChildProcess.fork(path.join(__dirname + './../PathToForked/child')); + + ForksManager.manage(fork); + + chai.expect(ForksManager._isManaged, '_isManaged returns true').to.equal(true); + chai.expect(ForksManager._isForksStackEmpty, '_isForksStackEmpty returns false').to.equal(false); + chai.expect(ForksManager._wasMainProcessKilled, '_wasMainProcessKilled returns false').to.equal(false); + }); + + test('Check registerListener() for ForksManager._isManaged', function () { + let actualResult = ForksManager.registerListener(); + + chai.expect(actualResult, 'returns undefined').to.equal(undefined); + chai.expect(ForksManager._isManaged, '_isManaged returns true').to.equal(true); + chai.expect(ForksManager._isForksStackEmpty, '_isForksStackEmpty returns false').to.equal(false); + chai.expect(ForksManager._wasMainProcessKilled, '_wasMainProcessKilled returns false').to.equal(false); + }); }); diff --git a/src/test/PathToForked/child.js b/src/test/PathToForked/child.js new file mode 100644 index 00000000..6d2cd0bc --- /dev/null +++ b/src/test/PathToForked/child.js @@ -0,0 +1,18 @@ +/** + * Created by vcernomschi on 2/2/16. + */ + +import chai from 'chai'; +import ChildProcess from 'child_process'; + +let exec = ChildProcess.exec; + +exec('ls -l', { + cwd: __dirname, +}, (error, stdout) => { + if (error) { + chai.assert.fail(true, true, 'Error while running "ls -l"'); + } else { + let result = stdout ? stdout.toString().trim() : null; + } +}); \ No newline at end of file From 02b38067a965c67fd93720fa1192b9a7c53434a4 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 14:30:06 +0200 Subject: [PATCH 080/133] Remove defined but never used vars --- src/bin/commands/compile-prod.js | 1 - src/bin/commands/run-lambda.js | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index e383eea6..d8ed08c9 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -15,7 +15,6 @@ module.exports = function(mainPath) { 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; diff --git a/src/bin/commands/run-lambda.js b/src/bin/commands/run-lambda.js index 6076cdf4..f61d94af 100644 --- a/src/bin/commands/run-lambda.js +++ b/src/bin/commands/run-lambda.js @@ -14,7 +14,6 @@ module.exports = function(lambdaPath) { var os = require('os'); var Autoload = require('deep-package-manager').Microservice_Metadata_Autoload; var NpmInstallLibs = require('../../lib.compiled/NodeJS/NpmInstallLibs').NpmInstallLibs; - var NpmLink = require('../../lib.compiled/NodeJS/NpmLink').NpmLink; var Bin = require('../../lib.compiled/NodeJS/Bin').Bin; var dbServer = this.opts.locate('db-server').value || 'LocalDynamo'; @@ -60,8 +59,6 @@ module.exports = function(lambdaPath) { console.log('AWS configuration found in ' + awsConfigFile); } - var mainPath = path.dirname(lambdaPath); - console.log('Linking aws-sdk library'); if (!Bin.npmModuleInstalled('aws-sdk', true)) { From 4e9f2212b6afbed81279c18fe2bc0c72a3e8fdbd Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 2 Feb 2016 15:33:12 +0200 Subject: [PATCH 081/133] Integrate custom env functionality --- src/bin/commands/deploy.js | 137 ++++++++------------------------ src/bin/commands/disable-ssl.js | 87 ++++++++++---------- src/bin/commands/enable-ssl.js | 97 +++++++++++----------- src/bin/manifest.js | 5 ++ src/package.json | 2 +- 5 files changed, 133 insertions(+), 195 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index ff0ddabf..abd1820c 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -17,12 +17,14 @@ module.exports = function(mainPath) { var Config = require('deep-package-manager').Property_Config; var S3Service = require('deep-package-manager').Provisioning_Service_S3Service; var ProvisioningCollisionsDetectedException = require('deep-package-manager').Property_Exception_ProvisioningCollisionsDetectedException; + var DeployConfig = require('deep-package-manager').Property_DeployConfig; var installSdk = this.opts.locate('aws-sdk').exists; var localOnly = this.opts.locate('dry-run').exists; var fastDeploy = this.opts.locate('fast').exists; var dumpCodePath = this.opts.locate('dump-local').value; var cfgBucket = this.opts.locate('cfg-bucket').value; + var appEnv = this.opts.locate('env').value; var hasToPullDeps = this.opts.locate('pull-deps').exists; var microservicesToDeploy = this.opts.locate('partial').value; @@ -38,12 +40,32 @@ module.exports = function(mainPath) { var configExists = fs.existsSync(configFile); var config = null; + appEnv = appEnv ? appEnv.toLowerCase() : null; + + if (DeployConfig.AVAILABLE_ENV.indexOf(appEnv) === -1) { + console.error( + 'Invalid environment "' + appEnv + '". Available environments: ' + + DeployConfig.AVAILABLE_ENV.join(', ') + ); + this.exit(1); + } + if (!configExists) { config = Config.generate(); + if (appEnv) { + config.env = appEnv; + } + fse.outputJsonSync(configFile, config); } else { config = fse.readJsonSync(configFile); + + if (appEnv) { + config.env = appEnv; + + fse.outputJsonSync(configFile, config); + } } var propertyInstance; @@ -126,64 +148,8 @@ module.exports = function(mainPath) { }.bind(this)); } - function getConfigFromS3(propertyInstance, cb) { - console.log('Trying to retrieve .cfg.deeploy.json from S3 ' + cfgBucket); - - var s3 = propertyInstance.provisioning.s3; - - var payload = { - Bucket: cfgBucket, - Key: '.cfg.deeploy.json', - }; - - s3.getObject(payload, function(error, data) { - cb.bind(this)(error, data); - }.bind(this)); - } - - function dumpConfigToS3(propertyInstance, cb) { - if (!propertyInstance.config || !propertyInstance.config.provisioning) { - cb && cb.bind(this)(); - return; - } - - var plainConfig = JSON.stringify(propertyInstance.config); - var s3 = propertyInstance.provisioning.s3; - - var payload = { - Bucket: propertyInstance.config.provisioning.s3.buckets[S3Service.SYSTEM_BUCKET].name, - Key: '.cfg.deeploy.json', - Body: plainConfig, - }; - - s3.putObject(payload, function(error, data) { - if (error) { - console.error('Error persisting config to S3', error); - this.exit(1); - } - - cb && cb.bind(this)(); - }.bind(this)); - } - function dumpConfig(propertyInstance, cb) { - if (!propertyInstance.config) { - cb && cb.bind(this)(); - return; - } - - var deepConfigFile = path.join(mainPath, '.cfg.deeploy.json'); - var plainConfig = JSON.stringify(propertyInstance.config); - - console.log('Dumping config into ' + deepConfigFile); - - fs.writeFile(deepConfigFile, plainConfig, function(error) { - if (error) { - console.error('Error while dumping config into ' + deepConfigFile + ': ' + error); - } - - dumpConfigToS3.bind(this)(propertyInstance, cb); - }.bind(this)); + propertyInstance.configObj.completeDump(cb.bind(this)); } function prepareProduction(propertyPath, cb) { @@ -231,8 +197,6 @@ module.exports = function(mainPath) { function doDeploy() { propertyInstance.localDeploy = localOnly; - var deepConfigFile = path.join(mainPath, '.cfg.deeploy.json'); - // @todo: improve it! // Gracefully teardown... (function() { @@ -276,64 +240,27 @@ module.exports = function(mainPath) { }.bind(this)); }.bind(this))(); - var updateCfg = fs.existsSync(deepConfigFile) ? JSON.parse(fs.readFileSync(deepConfigFile)) : null; + propertyInstance.configObj.tryLoadConfig(function() { + if (propertyInstance.configObj.configExists) { + propertyInstance.update(function() { + console.log('CloudFront (CDN) domain: ' + getCfDomain(propertyInstance)); + console.log('Website address: ' + getPublicWebsite(propertyInstance)); - // @todo: rewrite this section! - if (!updateCfg) { - if (!cfgBucket) { + dumpConfig.bind(this)(propertyInstance, dumpCode); + }.bind(this), null, getMicroservicesToDeploy()); + } else { if (microservicesToDeploy) { console.warn(' Partial deploy option is useless during first deploy...'); } - console.log('Installing web app ' + config.appIdentifier); - propertyInstance.install(function() { console.log('CloudFront (CDN) domain: ' + getCfDomain(propertyInstance)); console.log('Website address: ' + getPublicWebsite(propertyInstance)); dumpConfig.bind(this)(propertyInstance, dumpCode); }.bind(this)); - } else { - getConfigFromS3.bind(this)(propertyInstance, function(error, updateCfg) { - if (error) { - console.error('Error fetching config from AWS S3 bucket ' + cfgBucket, error); - } - - if (!error) { - console.log('Updating web app ' + config.appIdentifier); - - propertyInstance.update(JSON.parse(updateCfg.Body.toString()), function() { - console.log('CloudFront (CDN) domain: ' + getCfDomain(propertyInstance)); - console.log('Website address: ' + getPublicWebsite(propertyInstance)); - - dumpConfig.bind(this)(propertyInstance, dumpCode); - }.bind(this), getMicroservicesToDeploy()); - } else { - if (microservicesToDeploy) { - console.warn(' Partial deploy option is useless during first deploy...'); - } - - console.log('Installing web app ' + config.appIdentifier); - - propertyInstance.install(function() { - console.log('CloudFront (CDN) domain: ' + getCfDomain(propertyInstance)); - console.log('Website address: ' + getPublicWebsite(propertyInstance)); - - dumpConfig.bind(this)(propertyInstance, dumpCode); - }.bind(this)); - } - }.bind(this)); } - } else { - console.log('Updating web app ' + config.appIdentifier); - - propertyInstance.update(updateCfg, function() { - console.log('CloudFront (CDN) domain: ' + getCfDomain(propertyInstance)); - console.log('Website address: ' + getPublicWebsite(propertyInstance)); - - dumpConfig.bind(this)(propertyInstance, dumpCode); - }.bind(this), getMicroservicesToDeploy()); - } + }.bind(this), cfgBucket); } function arrayUnique(a) { diff --git a/src/bin/commands/disable-ssl.js b/src/bin/commands/disable-ssl.js index a529fb45..b23bbb46 100644 --- a/src/bin/commands/disable-ssl.js +++ b/src/bin/commands/disable-ssl.js @@ -19,61 +19,64 @@ module.exports = function(mainPath) { } var propertyConfigFile = path.join(mainPath, Config.DEFAULT_FILENAME); - var deployConfigFile = path.join(mainPath, '.cfg.deeploy.json'); - if (!fs.existsSync(propertyConfigFile) || !fs.existsSync(deployConfigFile)) { - console.error('You should have the application deployed'); + if (!fs.existsSync(propertyConfigFile)) { + console.error('You should have the application configured'); + this.exit(1); } - var deployConfig = fse.readJsonSync(deployConfigFile); - var property = new Property(mainPath); - property._config = deployConfig; - property.provisioning.injectConfig(deployConfig); - var domain = property.config.domain; + property.configObj.tryLoadConfig(function() { + if (!property.configObj.configExists) { + console.error('You should have the application deployed'); + this.exit(1); + } - if (!domain) { - console.error('Please add a domain to \'' + Config.DEFAULT_FILENAME + '\' config file in order to deactivate SSL!'); - } + var domain = property.config.domain; - var acmService = property.provisioning.services.find(ACMService); - var cfService = property.provisioning.services.find(CloudFrontService); + if (!domain) { + console.error('Please add a domain to \'' + Config.DEFAULT_FILENAME + '\' config file in order to deactivate SSL!'); + } - console.log('Looking for ACM certificate available of the domain \'' + domain + '\''); + var acmService = property.provisioning.services.find(ACMService); + var cfService = property.provisioning.services.find(CloudFrontService); - acmService.getDomainCertificateArn(domain, function(certArn) { - if (!certArn) { - console.error('There is no certificate available for the domain \'' + domain + '\''); - this.exit(1); - } + console.log('Looking for ACM certificate available of the domain \'' + domain + '\''); - var configChanges = { - DefaultCacheBehavior: { - ViewerProtocolPolicy: 'allow-all', - }, - ViewerCertificate: { - Certificate: null, - CertificateSource: 'cloudfront', - CloudFrontDefaultCertificate: true, - }, - Aliases: { - Quantity: 0, - Items: null, - }, - }; - - console.log('Deactivating ACM certificate \'' + certArn + '\' for domain \'' + domain + '\''); - - cfService.updateDistribution(configChanges, function(error) { - if (error) { - console.error(error); + acmService.getDomainCertificateArn(domain, function(certArn) { + if (!certArn) { + console.error('There is no certificate available for the domain \'' + domain + '\''); this.exit(1); } - console.log( - 'Certificate \'' + certArn + '\' have been successfully unassigned from the CloudFront distribution' - ); + var configChanges = { + DefaultCacheBehavior: { + ViewerProtocolPolicy: 'allow-all', + }, + ViewerCertificate: { + Certificate: null, + CertificateSource: 'cloudfront', + CloudFrontDefaultCertificate: true, + }, + Aliases: { + Quantity: 0, + Items: null, + }, + }; + + console.log('Deactivating ACM certificate \'' + certArn + '\' for domain \'' + domain + '\''); + + cfService.updateDistribution(configChanges, function(error) { + if (error) { + console.error(error); + this.exit(1); + } + + console.log( + 'Certificate \'' + certArn + '\' have been successfully unassigned from the CloudFront distribution' + ); + }.bind(this)); }.bind(this)); }.bind(this)); }; diff --git a/src/bin/commands/enable-ssl.js b/src/bin/commands/enable-ssl.js index 4f2fb202..0ae4572e 100644 --- a/src/bin/commands/enable-ssl.js +++ b/src/bin/commands/enable-ssl.js @@ -21,14 +21,12 @@ module.exports = function(mainPath) { } var propertyConfigFile = path.join(mainPath, Config.DEFAULT_FILENAME); - var deployConfigFile = path.join(mainPath, '.cfg.deeploy.json'); - if (!fs.existsSync(propertyConfigFile) || !fs.existsSync(deployConfigFile)) { - console.error('You should have the application deployed'); + if (!fs.existsSync(propertyConfigFile)) { + console.error('You should have the application configured'); + this.exit(1); } - var deployConfig = fse.readJsonSync(deployConfigFile); - if (domain) { var config = null; @@ -42,67 +40,72 @@ module.exports = function(mainPath) { domain = property.config.domain; - property._config = deployConfig; - property.provisioning.injectConfig(deployConfig); - property.config.domain = domain; - if (!domain) { console.error('Please add a domain to \'' + Config.DEFAULT_FILENAME + '\' config file in order to activate SSL!'); console.log('You may add \'--domain\' option to add it to the config automatically.'); } - var acmService = property.provisioning.services.find(ACMService); - var cfService = property.provisioning.services.find(CloudFrontService); - - console.log('Ensure ACM certificate available for domain \'' + domain + '\''); - - acmService.ensureCertificate(domain, function (error, certArn) { - if (error) { - console.error(error); + property.configObj.tryLoadConfig(function() { + if (!property.configObj.configExists) { + console.error('You should have the application deployed'); this.exit(1); } - console.log('Ensure ACM certificate \'' + certArn + '\' for domain \'' + domain + '\' have been activated'); + property.config.domain = domain; + + var acmService = property.provisioning.services.find(ACMService); + var cfService = property.provisioning.services.find(CloudFrontService); - acmService.isCertificateIssued(certArn, function(error, isIssued) { + console.log('Ensure ACM certificate available for domain \'' + domain + '\''); + + acmService.ensureCertificate(domain, function (error, certArn) { if (error) { console.error(error); this.exit(1); - } else if(!isIssued) { - console.error( - 'You must validate the certificate \'' + certArn - + '\' by accessing the link from the mail sent by AWS ' + - '(Subject: "Certificate approval for ' + domain + '")' - ); - this.exit(1); } - var configChanges = { - DefaultCacheBehavior: { - ViewerProtocolPolicy: 'redirect-to-https', - }, - ViewerCertificate: { - Certificate: certArn, - CertificateSource: 'acm', - CloudFrontDefaultCertificate: false, - }, - Aliases: { - Quantity: 1, - Items: [domain], - }, - }; - - console.log('Activating ACM certificate \'' + certArn + '\' for domain \'' + domain + '\''); - - cfService.updateDistribution(configChanges, function(error) { + console.log('Ensure ACM certificate \'' + certArn + '\' for domain \'' + domain + '\' have been activated'); + + acmService.isCertificateIssued(certArn, function(error, isIssued) { if (error) { console.error(error); this.exit(1); + } else if(!isIssued) { + console.error( + 'You must validate the certificate \'' + certArn + + '\' by accessing the link from the mail sent by AWS ' + + '(Subject: "Certificate approval for ' + domain + '")' + ); + this.exit(1); } - console.log( - 'The ACM certificate \'' + certArn + '\' have been successfully assigned to the CloudFront distribution' - ); + var configChanges = { + DefaultCacheBehavior: { + ViewerProtocolPolicy: 'redirect-to-https', + }, + ViewerCertificate: { + Certificate: certArn, + CertificateSource: 'acm', + CloudFrontDefaultCertificate: false, + }, + Aliases: { + Quantity: 1, + Items: [domain], + }, + }; + + console.log('Activating ACM certificate \'' + certArn + '\' for domain \'' + domain + '\''); + + cfService.updateDistribution(configChanges, function(error) { + if (error) { + console.error(error); + this.exit(1); + } + + console.log( + 'The ACM certificate \'' + certArn + '\' have been successfully assigned to the CloudFront distribution' + ); + }.bind(this)); }.bind(this)); }.bind(this)); }.bind(this)); diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 165a37d4..29d9983d 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -93,6 +93,11 @@ module.exports = { example: 'deepify deploy path/to/web_app', description: 'Deploy an web app', opts: { + env: { + alias: 'e', + description: 'Web app environment to be used (default fetched from deploy config)', + required: false, + }, 'cfg-bucket': { alias: 'b', description: 'AWS S3 system bucket name where the deploy config was persisted (ex. deep.prod.system.db0c09cc)', diff --git a/src/package.json b/src/package.json index f59def87..60c81a69 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.7", + "version": "1.6.8", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From f639ab57350394783e3b73b459c3413a7be7a8a4 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 17:38:38 +0200 Subject: [PATCH 082/133] Add new unit tests for Runtime --- src/test/Lambda/ForksManager.spec.js | 6 +- src/test/Lambda/Runtime.spec.js | 219 ++++++++++++++++++ src/test/Lambda/Thread.spec.js | 27 +++ src/test/TestMaterials/Lambda/lambda.js | 9 + .../{ => TestMaterials}/PathToForked/child.js | 0 5 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 src/test/TestMaterials/Lambda/lambda.js rename src/test/{ => TestMaterials}/PathToForked/child.js (100%) diff --git a/src/test/Lambda/ForksManager.spec.js b/src/test/Lambda/ForksManager.spec.js index f74ac7ff..874d1303 100644 --- a/src/test/Lambda/ForksManager.spec.js +++ b/src/test/Lambda/ForksManager.spec.js @@ -6,6 +6,8 @@ import ChildProcess from 'child_process'; import path from 'path'; suite('Lambda/ForksManager', function () { + let forkPath = path.join(__dirname + './../TestMaterials/PathToForked/child'); + test('Class ForksManager exists in Lambda/ForksManager', function () { chai.expect(typeof ForksManager).to.equal('function'); }); @@ -31,7 +33,7 @@ suite('Lambda/ForksManager', function () { }); test('Check manage() for !ForksManager._isManaged', function () { - let fork = ChildProcess.fork(path.join(__dirname + './../PathToForked/child')); + let fork = ChildProcess.fork(forkPath); let actualResult = ForksManager.manage(fork); @@ -50,7 +52,7 @@ suite('Lambda/ForksManager', function () { }); test('Check manage() > _addForkToStack() ', function() { - let fork = ChildProcess.fork(path.join(__dirname + './../PathToForked/child')); + let fork = ChildProcess.fork(forkPath); ForksManager.manage(fork); diff --git a/src/test/Lambda/Runtime.spec.js b/src/test/Lambda/Runtime.spec.js index 986ee225..812c634a 100644 --- a/src/test/Lambda/Runtime.spec.js +++ b/src/test/Lambda/Runtime.spec.js @@ -1,10 +1,229 @@ 'use strict'; import chai from 'chai'; +import path from 'path'; import {Runtime} from '../../lib/Lambda/Runtime'; +import {Timer} from '../../lib/Lambda/Timer'; suite('Lambda/Runtime', function() { + let runtime = null; + let lambda = { + name: 'testLambda', + handler: () => {}, + }; + let lambdaPath = path.join(__dirname + './../TestMaterials/Lambda/lambda'); + test('Class Runtime exists in Lambda/Runtime', function() { chai.expect(typeof Runtime).to.equal('function'); }); + + test('Check constructor sets _lambda', function() { + runtime = new Runtime(lambda); + + chai.expect(runtime).to.be.an.instanceOf(Runtime); + chai.expect(runtime.lambda).to.eql(lambda); + }); + + test('Check constructor sets _measureTime = false', function() { + chai.expect(runtime.measureTime).to.equal(false); + }); + + test('Check constructor sets _timer = null', function() { + chai.expect(runtime._timer).to.equal(null); + }); + + test('Check constructor sets _silent = false', function() { + chai.expect(runtime.silent).to.equal(false); + }); + + test('Check constructor sets _name ', function() { + chai.expect(runtime.name).to.not.equal(''); + }); + + test('Check constructor sets _lambdaPath = null', function() { + chai.expect(runtime.lambdaPath).to.equal(null); + }); + + test('Check constructor sets _awsConfigFile = null', function() { + chai.expect(runtime._awsConfigFile).to.equal(null); + }); + + test('Check ENVIRONMENT static getter', function() { + chai.expect(Runtime.ENVIRONMENT).to.equal('local'); + }); + + test('Check SIBLING_EXEC_WRAPPER_NAME static getter', function() { + chai.expect(Runtime.SIBLING_EXEC_WRAPPER_NAME).to.equal('_deep_lambda_exec_'); + }); + + test('Check createLambda()', function() { + let actualResult = Runtime.createLambda(lambdaPath); + + chai.expect(actualResult).to.be.an.instanceOf(Runtime); + chai.expect(actualResult.awsConfigFile).to.be.equal(null); + }); + + test('Check complete setter/getter', function() { + let cb = () => { + return 'test cb'; + }; + let complete = runtime.complete; + + runtime.complete = cb; + chai.expect(runtime.complete).to.equal(cb); + + runtime.complete = null; + chai.expect(runtime.complete).to.equal(null); + + runtime.complete = complete; + chai.expect(runtime.complete).to.equal(complete); + }); + + test('Check fail setter/getter', function() { + let cb = () => { + return 'test cb fail'; + }; + let fail = runtime.fail; + + runtime.fail = cb; + chai.expect(runtime.fail).to.equal(cb); + + runtime.fail = null; + chai.expect(runtime.fail).to.equal(null); + + runtime.fail = fail; + chai.expect(runtime.fail).to.equal(fail); + }); + + test('Check succeed setter/getter', function() { + let cb = () => { + return 'test cb succeed'; + }; + let succeed = runtime.succeed; + + runtime.succeed = cb; + chai.expect(runtime.succeed).to.equal(cb); + + runtime.succeed = null; + chai.expect(runtime.succeed).to.equal(null); + + runtime.succeed = succeed; + chai.expect(runtime.succeed).to.equal(succeed); + }); + + test('Check succeed setter/getter', function() { + let measureTime = runtime.measureTime; + + runtime.measureTime = true; + chai.expect(runtime.measureTime).to.equal(true); + chai.expect(runtime._timer).to.be.an.instanceOf(Timer); + + runtime.measureTime = false; + chai.expect(runtime.measureTime).to.equal(false); + chai.expect(runtime._timer).to.be.an.instanceOf(Timer); + + runtime.succeed = measureTime; + chai.expect(runtime.measureTime).to.equal(measureTime); + }); + + test('Check name setter/getter', function() { + let name = runtime.name; + let lambdaName = 'new test name'; + + runtime.name = lambdaName; + chai.expect(runtime.name).to.equal(lambdaName); + + runtime.name = null; + chai.expect(runtime.name).to.equal(null); + + runtime.name = name; + chai.expect(runtime.name).to.equal(name); + }); + + test('Check silent setter/getter', function() { + let silent = runtime.silent; + + runtime.silent = true; + chai.expect(runtime.silent).to.equal(true); + + runtime.silent = false; + chai.expect(runtime.silent).to.equal(false); + + runtime.silent = null; + chai.expect(runtime.silent).to.equal(null); + + runtime.silent = silent; + chai.expect(runtime.silent).to.equal(silent); + }); + + test('Check context getter', function() { + let expectedContextKeys = [ + 'awsRequestId', + 'fail', + 'functionName', + 'functionVersion', + 'invokedFunctionArn', + 'invokeid', + 'logGroupName', + 'logStreamName', + 'memoryLimitInMB', + 'succeed', + ]; + let actualResult = Object.keys(runtime.context); + + expectedContextKeys.forEach((value) => { + chai.expect(actualResult).to.include(value); + }); + chai.expect(runtime.context.succeed).to.be.an('function'); + chai.expect(runtime.context.fail).to.be.an('function'); + }); + + test('Check _injectSiblingExecutionWrapper', function() { + let actualResult = runtime._injectSiblingExecutionWrapper(); + chai.expect(global[Runtime.SIBLING_EXEC_WRAPPER_NAME]).to.be.an('object'); + chai.expect(global[Runtime.SIBLING_EXEC_WRAPPER_NAME].invoke).to.be.an('function'); + chai.expect(global[Runtime.SIBLING_EXEC_WRAPPER_NAME].invokeAsync).to.be.an('function'); + }); + + test('Check run for _measureTime = undefined', function() { + let event = { + firstInputArg: 'test', + secondInputArg: 2, + thirdInputArg: false, + fourthInputArg: null, + }; + + let actualResult = runtime.run(event); + + chai.expect(actualResult.lambda).to.be.an('object'); + chai.expect(actualResult.lambda.handler).to.be.an('function'); + chai.expect(actualResult.lambda.name).to.equal(lambda.name); + }); + + test('Check run for _measureTime != undefined', function() { + let event = { + firstInputArg: 'test', + secondInputArg: 2, + thirdInputArg: false, + fourthInputArg: null, + }; + + let actualResult = runtime.run(event, true); + + chai.expect(actualResult.lambda).to.be.an('object'); + chai.expect(actualResult.measureTime).to.equal(true); + chai.expect(actualResult._timer).to.be.an.instanceOf(Timer); + chai.expect(actualResult.lambda.handler).to.be.an('function'); + chai.expect(actualResult.lambda.name).to.equal(lambda.name); + }); + + test('Check _logCallback()', function() { + runtime.silent = true; + let type = 'number'; + + let actualResult = runtime._logCallback(type); + + chai.expect(actualResult).to.be.an('function'); + chai.expect(actualResult()).to.be.equal(undefined); + }); }); diff --git a/src/test/Lambda/Thread.spec.js b/src/test/Lambda/Thread.spec.js index 34bf0f5e..d2418dbf 100644 --- a/src/test/Lambda/Thread.spec.js +++ b/src/test/Lambda/Thread.spec.js @@ -2,9 +2,36 @@ import chai from 'chai'; import {Thread} from '../../lib/Lambda/Thread'; +import {Runtime} from '../../lib/Lambda/Runtime'; suite('Lambda/Thread', function() { + let lambda = { + name: 'testLambda', + }; + let runtime = new Runtime(lambda); + let thread = null; + test('Class Thread exists in Lambda/Thread', function() { chai.expect(typeof Thread).to.equal('function'); }); + + test('Check constructor sets _lambda', function() { + thread = new Thread(runtime); + + chai.expect(thread).to.be.an.instanceOf(Thread); + chai.expect(thread.runtime).to.be.an.instanceOf(Runtime); + chai.expect(thread.process).to.equal(null); + }); + + test('Check WRAPPER static getter', function() { + chai.expect(Thread.WRAPPER).to.contains('thread_wrapper.js'); + }); + + test('Check _cleanup()', function() { + let actualResult = thread._cleanup(); + + chai.expect(actualResult).to.be.an.instanceOf(Thread); + chai.expect(thread.process).to.equal(null); + }); + }); diff --git a/src/test/TestMaterials/Lambda/lambda.js b/src/test/TestMaterials/Lambda/lambda.js new file mode 100644 index 00000000..d922af16 --- /dev/null +++ b/src/test/TestMaterials/Lambda/lambda.js @@ -0,0 +1,9 @@ +/** + * Created by vcernomschi on 2/2/16. + */ + +'use strict'; + +module.exports = function(mainPath) { + var lambda = { name: 'testLambda from file', }; +}; diff --git a/src/test/PathToForked/child.js b/src/test/TestMaterials/PathToForked/child.js similarity index 100% rename from src/test/PathToForked/child.js rename to src/test/TestMaterials/PathToForked/child.js From 0843671fcb5ce4af207166e4cf98cf313cd9795a Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 18:23:50 +0200 Subject: [PATCH 083/133] Add unit tests for Thread --- src/test/Lambda/Thread.spec.js | 42 +++++++++++++++++++++---- src/test/TestMaterials/Lambda/lambda.js | 5 +-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/test/Lambda/Thread.spec.js b/src/test/Lambda/Thread.spec.js index d2418dbf..6023b49d 100644 --- a/src/test/Lambda/Thread.spec.js +++ b/src/test/Lambda/Thread.spec.js @@ -1,21 +1,24 @@ 'use strict'; import chai from 'chai'; +import path from 'path'; import {Thread} from '../../lib/Lambda/Thread'; import {Runtime} from '../../lib/Lambda/Runtime'; -suite('Lambda/Thread', function() { +suite('Lambda/Thread', function () { let lambda = { name: 'testLambda', + handler: () => {}, }; - let runtime = new Runtime(lambda); + let lambdaPath = path.join(__dirname + './../TestMaterials/Lambda/lambda'); + let runtime = new Runtime(lambda, lambdaPath); let thread = null; - test('Class Thread exists in Lambda/Thread', function() { + test('Class Thread exists in Lambda/Thread', function () { chai.expect(typeof Thread).to.equal('function'); }); - test('Check constructor sets _lambda', function() { + test('Check constructor sets _lambda', function () { thread = new Thread(runtime); chai.expect(thread).to.be.an.instanceOf(Thread); @@ -23,15 +26,42 @@ suite('Lambda/Thread', function() { chai.expect(thread.process).to.equal(null); }); - test('Check WRAPPER static getter', function() { + test('Check WRAPPER static getter', function () { chai.expect(Thread.WRAPPER).to.contains('thread_wrapper.js'); }); - test('Check _cleanup()', function() { + test('Check _cleanup()', function () { let actualResult = thread._cleanup(); chai.expect(actualResult).to.be.an.instanceOf(Thread); chai.expect(thread.process).to.equal(null); }); + test('Check run()', function () { + runtime.silent = true; + let event = { + firstInputArg: 'test', + secondInputArg: 2, + thirdInputArg: false, + fourthInputArg: null, + }; + let expectedResultArray = [ + 'domain', '_events', '_eventsCount', '_maxListeners', + '_closesNeeded', '_closesGot', 'connected', 'signalCode', + 'exitCode', 'killed', 'spawnfile', '_handle', + 'spawnargs', 'pid', 'stdin', 'stdout', 'stderr', + 'stdio', '_channel', '_handleQueue', 'send', '_send', + 'disconnect', '_disconnect', + ]; + + let actualResult = thread.run(event, false); + let processKeys = Object.keys(thread.process); + + chai.expect(actualResult).to.be.an.instanceOf(Thread); + + expectedResultArray.forEach((value) => { + chai.expect(processKeys).to.include(value); + }); + }); + }); diff --git a/src/test/TestMaterials/Lambda/lambda.js b/src/test/TestMaterials/Lambda/lambda.js index d922af16..89615d39 100644 --- a/src/test/TestMaterials/Lambda/lambda.js +++ b/src/test/TestMaterials/Lambda/lambda.js @@ -4,6 +4,7 @@ 'use strict'; -module.exports = function(mainPath) { - var lambda = { name: 'testLambda from file', }; +module.exports = function() { + var lambda = { name: 'testLambda from file', handler: () => {},}; + return lambda; }; From c6140db4a9786ec935b0124087aeebf22def8d75 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 19:08:13 +0200 Subject: [PATCH 084/133] Add unit tests fir Lambda Extractor --- src/test/Helpers/LambdasExtractor.spec.js | 76 ++++++++++++++++++++++- src/test/Lambda/Thread.spec.js | 4 +- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/test/Helpers/LambdasExtractor.spec.js b/src/test/Helpers/LambdasExtractor.spec.js index c8c9eefe..863e4bb1 100644 --- a/src/test/Helpers/LambdasExtractor.spec.js +++ b/src/test/Helpers/LambdasExtractor.spec.js @@ -2,9 +2,81 @@ import chai from 'chai'; import {LambdasExtractor} from '../../lib/Helpers/LambdasExtractor'; +import {Property_Instance as PropertyInstance} from 'deep-package-manager'; -suite('Helpers/LambdasExtractor', function() { - test('Class LambdasExtractor exists in Helpers/LambdasExtractor', function() { +suite('Helpers/LambdasExtractor', function () { + let propertyInstance = null; + let lambdasExtractor = null; + + test('Class LambdasExtractor exists in Helpers/LambdasExtractor', function () { chai.expect(typeof LambdasExtractor).to.equal('function'); }); + + test('Check _extract()', function () { + propertyInstance = new PropertyInstance('./test/TestMaterials/Property2', 'deeploy.test.json'); + + lambdasExtractor = new LambdasExtractor(propertyInstance); + + chai.expect(propertyInstance).to.be.an.instanceOf(PropertyInstance); + chai.expect(lambdasExtractor).to.be.an.instanceOf(LambdasExtractor); + chai.expect(lambdasExtractor.property).to.equal(propertyInstance); + }); + + test('Check _extract()', function () { + let microservices = { + 'hello.world.example': { + 'isRoot': false, + 'parameters': {}, + 'resources': { + 'sample': { + 'say-hello': { + 'type': 'lambda', + 'methods': [ + 'POST' + ], + 'forceUserIdentity': true, + 'region': 'us-west-2', + 'source': { + 'api': 'https://1zf47jpvxd.execute-api.us-west-2.amazonaws.com/dev/hello-world-example/sample/say-hello', + 'original': 'arn:aws:lambda:us-west-2:389615756922:function:DeepDevSampleSayHello64232f3705a' + } + }, + 'say-bye': { + 'type': 'lambda', + 'methods': [ + 'GET' + ], + 'forceUserIdentity': true, + 'region': 'us-west-2', + 'source': { + 'api': 'https://6jh99kuklk.execute-api.us-west-2.amazonaws.com/dev/hello-world-example/sample/say-bye', + 'original': 'arn:aws:lambda:us-west-2:389615756922:function:DeepDevSampleSayBye64232f3705a' + } + }, + 'say-test': { + 'type': 'external', + 'methods': [ + 'GET' + ], + 'forceUserIdentity': true, + 'region': 'us-west-2', + 'source': { + 'api': 'https://6jh99kuklk.execute-api.us-west-2.amazonaws.com/dev/hello-world-example/sample/say-test', + 'original': 'http://petstore.swagger.io/v2/store/inventory' + } + } + } + } + }, + 'deep.ng.root': { + 'isRoot': true, + 'parameters': {}, + 'resources': {} + } + }; + + let actualResult = LambdasExtractor._extract(microservices); + + chai.expect(actualResult).to.be.eql([]); + }); }); diff --git a/src/test/Lambda/Thread.spec.js b/src/test/Lambda/Thread.spec.js index 6023b49d..085fd13a 100644 --- a/src/test/Lambda/Thread.spec.js +++ b/src/test/Lambda/Thread.spec.js @@ -45,8 +45,10 @@ suite('Lambda/Thread', function () { thirdInputArg: false, fourthInputArg: null, }; + + //'_eventsCount' not exists in node 0.12 let expectedResultArray = [ - 'domain', '_events', '_eventsCount', '_maxListeners', + 'domain', '_events', '_maxListeners', '_closesNeeded', '_closesGot', 'connected', 'signalCode', 'exitCode', 'killed', 'spawnfile', '_handle', 'spawnargs', 'pid', 'stdin', 'stdout', 'stderr', From 3417593430d827b6155d7e7d8660d2d99e883313 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 21:37:27 +0200 Subject: [PATCH 085/133] Add test materials --- .../Property2/Microservice/.parameters.json | 4 +++ .../Microservice/Backend/resources.json | 12 +++++++ .../Backend/src/TestResource/Test/Handler.es6 | 22 ++++++++++++ .../src/TestResource/Test/bootstrap.es6 | 14 ++++++++ .../src/TestResource/Test/package.json | 34 +++++++++++++++++++ .../Microservice/Data/Models/model.json | 11 ++++++ .../Property2/Microservice/deepkg.json | 21 ++++++++++++ .../TestMaterials/Property2/deeploy.test.json | 13 +++++++ 8 files changed, 131 insertions(+) create mode 100644 src/test/TestMaterials/Property2/Microservice/.parameters.json create mode 100644 src/test/TestMaterials/Property2/Microservice/Backend/resources.json create mode 100644 src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/Handler.es6 create mode 100644 src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/bootstrap.es6 create mode 100644 src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/package.json create mode 100644 src/test/TestMaterials/Property2/Microservice/Data/Models/model.json create mode 100644 src/test/TestMaterials/Property2/Microservice/deepkg.json create mode 100644 src/test/TestMaterials/Property2/deeploy.test.json diff --git a/src/test/TestMaterials/Property2/Microservice/.parameters.json b/src/test/TestMaterials/Property2/Microservice/.parameters.json new file mode 100644 index 00000000..e170716d --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice/.parameters.json @@ -0,0 +1,4 @@ +{ + "backend": {}, + "frontend": {} +} \ No newline at end of file diff --git a/src/test/TestMaterials/Property2/Microservice/Backend/resources.json b/src/test/TestMaterials/Property2/Microservice/Backend/resources.json new file mode 100644 index 00000000..f8522da5 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice/Backend/resources.json @@ -0,0 +1,12 @@ +{ + "test-resource" : { + "test": { + "description": "Just a test resource", + "type": "lambda", + "methods": [ + "POST" + ], + "source": "src/TestResource/Test" + } + } +} \ No newline at end of file diff --git a/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/Handler.es6 b/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/Handler.es6 new file mode 100644 index 00000000..70099276 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/Handler.es6 @@ -0,0 +1,22 @@ +'use strict'; + +import DeepFramework from 'deep-framework'; + +/** + * Sample lambda runtime + */ +export default class extends DeepFramework.Core.AWS.Lambda.Runtime { + /** + * @param {Array} args + */ + constructor(...args) { + super(...args); + } + + /** + * Handle lambda execution + */ + handle(request) { + this.createResponse(request).send(); + } +} diff --git a/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/bootstrap.es6 b/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/bootstrap.es6 new file mode 100644 index 00000000..9b842547 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/bootstrap.es6 @@ -0,0 +1,14 @@ +'use strict'; + +if (typeof Symbol === 'undefined') { + require('babel-core/polyfill'); +} + +import DeepFramework from 'deep-framework'; +import Handler from './Handler'; + +exports.handler = function(event, context) { + DeepFramework.Kernel.loadFromFile('_config.json', function(deepKernel) { + new Handler(deepKernel).run(event, context); + }); +}; diff --git a/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/package.json b/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/package.json new file mode 100644 index 00000000..2787d760 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice/Backend/src/TestResource/Test/package.json @@ -0,0 +1,34 @@ +{ + "name": "test-resource-test", + "version": "0.0.1", + "description": "Test resource", + "author": "Mitoc Group ", + "contributors": [ + { + "name": "Stefan Hariton", + "email": "shariton@mitocroup.com" + } + ], + "bugs": { + "url": "https://github.com/MitocGroup/deep-management/issues" + }, + "keywords": [ + "DEEP", + "Stripe", + "Digital Enterprise End-To-End Platform", + "Deep Core Libraries", + "Billing" + ], + "dependencies": { + "deep-framework": "*", + "babel-core": "5.5.*" + }, + "devDependencies": { + }, + "scripts": { + "postinstall": "BABEL_ENV=production babel -x \".es6\" ./ --out-dir ./" + }, + "preferGlobal": false, + "private": true, + "analyze": true +} diff --git a/src/test/TestMaterials/Property2/Microservice/Data/Models/model.json b/src/test/TestMaterials/Property2/Microservice/Data/Models/model.json new file mode 100644 index 00000000..e0b99814 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice/Data/Models/model.json @@ -0,0 +1,11 @@ +{ + "UserId": "string", + "AccountId": "string", + "URL": "string", + "Metadata": "map", + "Size": { + "Width": "number", + "Height": "number" + }, + "Tags": "mapSet" +} \ No newline at end of file diff --git a/src/test/TestMaterials/Property2/Microservice/deepkg.json b/src/test/TestMaterials/Property2/Microservice/deepkg.json new file mode 100644 index 00000000..2d15ad43 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice/deepkg.json @@ -0,0 +1,21 @@ +{ + "identifier": "microservice1", + "name": "microservice1", + "description": "Microservice used for testing purposes", + "version": "0.0.1", + "propertyRoot": true, + "author": { + "name": "Mitoc Group", + "email": "hello@mitocgroup.com", + "website": "http://www.mitocgroup.com" + }, + "contributors": [ + { + "name": "Vitali Cernomschi", + "email": "vcernomschi@mitocgroup.com", + "website": "http://www.mitocgroup.com" + } + ], + "dependencies": { + } +} \ No newline at end of file diff --git a/src/test/TestMaterials/Property2/deeploy.test.json b/src/test/TestMaterials/Property2/deeploy.test.json new file mode 100644 index 00000000..59402e76 --- /dev/null +++ b/src/test/TestMaterials/Property2/deeploy.test.json @@ -0,0 +1,13 @@ +{ + "aws": { + "accessKeyId": "to_pass_string_validation", + "region": "us-west-2", + "secretAccessKey": "to_pass_string_validation" + }, + "dependencies": { + "bucket": "testbucket" + }, + "env": "test", + "awsAccountId": 123456789012, + "appIdentifier": "generated" +} \ No newline at end of file From 17ca4e4d43bb44ed80321fdfa09797439d5b4eac Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Tue, 2 Feb 2016 21:51:54 +0200 Subject: [PATCH 086/133] Fix failed unit tests for node 0.12 --- src/test/Lambda/Thread.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/Lambda/Thread.spec.js b/src/test/Lambda/Thread.spec.js index 085fd13a..c740e79b 100644 --- a/src/test/Lambda/Thread.spec.js +++ b/src/test/Lambda/Thread.spec.js @@ -46,12 +46,12 @@ suite('Lambda/Thread', function () { fourthInputArg: null, }; - //'_eventsCount' not exists in node 0.12 + //'spawnargs', '_eventsCount' do not exist in node 0.12 let expectedResultArray = [ 'domain', '_events', '_maxListeners', '_closesNeeded', '_closesGot', 'connected', 'signalCode', 'exitCode', 'killed', 'spawnfile', '_handle', - 'spawnargs', 'pid', 'stdin', 'stdout', 'stderr', + 'pid', 'stdin', 'stdout', 'stderr', 'stdio', '_channel', '_handleQueue', 'send', '_send', 'disconnect', '_disconnect', ]; From eb7224981679554a4fb0147adb7e04f49af0d641 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 3 Feb 2016 09:30:33 +0200 Subject: [PATCH 087/133] Add --prod flag on deploy --- src/bin/commands/deploy.js | 61 +++++++++++++++++++++----------------- src/bin/manifest.js | 4 +++ src/package.json | 2 +- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index abd1820c..8668c57d 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -19,12 +19,13 @@ module.exports = function(mainPath) { var ProvisioningCollisionsDetectedException = require('deep-package-manager').Property_Exception_ProvisioningCollisionsDetectedException; var DeployConfig = require('deep-package-manager').Property_DeployConfig; + var isProd = this.opts.locate('prod').exists; var installSdk = this.opts.locate('aws-sdk').exists; var localOnly = this.opts.locate('dry-run').exists; var fastDeploy = this.opts.locate('fast').exists; var dumpCodePath = this.opts.locate('dump-local').value; var cfgBucket = this.opts.locate('cfg-bucket').value; - var appEnv = this.opts.locate('env').value; + var appEnv = isProd ? 'prod' : this.opts.locate('env').value; var hasToPullDeps = this.opts.locate('pull-deps').exists; var microservicesToDeploy = this.opts.locate('partial').value; @@ -42,7 +43,7 @@ module.exports = function(mainPath) { appEnv = appEnv ? appEnv.toLowerCase() : null; - if (DeployConfig.AVAILABLE_ENV.indexOf(appEnv) === -1) { + if (appEnv && DeployConfig.AVAILABLE_ENV.indexOf(appEnv) === -1) { console.error( 'Invalid environment "' + appEnv + '". Available environments: ' + DeployConfig.AVAILABLE_ENV.join(', ') @@ -152,33 +153,39 @@ module.exports = function(mainPath) { propertyInstance.configObj.completeDump(cb.bind(this)); } - function prepareProduction(propertyPath, cb) { - if (!localOnly) { - var prompt = new Prompt('Prepare for production?'); + function doCompileProd(propertyPath, cb) { + console.log('Start preparing for production'); - prompt.readConfirm(function(result) { - if (result) { - console.log('Start preparing for production'); + var cmd = new Exec( + Bin.node, + this.scriptPath, + 'compile-prod', + propertyPath + ); - var cmd = new Exec( - Bin.node, - this.scriptPath, - 'compile-prod', - propertyPath - ); + !fastDeploy && cmd.addArg('--remove-source'); + microservicesToDeploy && cmd.addArg('--partial ' + microservicesToDeploy); + installSdk && cmd.addArg('--aws-sdk'); + + cmd.run(function(result) { + if (result.failed) { + console.error('Backend production preparations failed: ' + result.error); + this.exit(1); + } - !fastDeploy && cmd.addArg('--remove-source'); - microservicesToDeploy && cmd.addArg('--partial ' + microservicesToDeploy); - installSdk && cmd.addArg('--aws-sdk'); + cb(); + }.bind(this), true); + } - cmd.run(function(result) { - if (result.failed) { - console.error('Backend production preparations failed: ' + result.error); - this.exit(1); - } + function prepareProduction(propertyPath, cb) { + if (isProd) { + doCompileProd.bind(this)(propertyPath, cb); + } else if (!localOnly) { + var prompt = new Prompt('Prepare for production?'); - cb(); - }.bind(this), true); + prompt.readConfirm(function(result) { + if (result) { + doCompileProd.bind(this)(propertyPath, cb); return; } @@ -187,11 +194,9 @@ module.exports = function(mainPath) { cb(); }.bind(this)); - - return; + } else { + cb(); } - - cb(); } function doDeploy() { diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 29d9983d..0aa0c07a 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -93,6 +93,10 @@ module.exports = { example: 'deepify deploy path/to/web_app', description: 'Deploy an web app', opts: { + prod: { + description: 'Prepare web app for production and ensure prod env is used', + required: false, + }, env: { alias: 'e', description: 'Web app environment to be used (default fetched from deploy config)', diff --git a/src/package.json b/src/package.json index 60c81a69..97b23cd5 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.8", + "version": "1.6.9", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From a5d3edcad753c97a7202f12ba971d42d5ee9301d Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 10:46:21 +0200 Subject: [PATCH 088/133] Update functions to arrow functions --- src/test/Helpers/Exec.spec.js | 6 +-- src/test/Helpers/LambdasExtractor.spec.js | 10 ++-- src/test/Lambda/Runtime.spec.js | 48 +++++++++---------- src/test/Lambda/Thread.spec.js | 14 +++--- src/test/Lambda/Timer.spec.js | 20 ++++---- src/test/NodeJS/Bin.spec.js | 18 +++---- src/test/NodeJS/DepsTreeOptimizer.spec.js | 6 +-- src/test/NodeJS/NpmChain.spec.js | 10 ++-- src/test/NodeJS/NpmDedupe.spec.js | 12 ++--- src/test/NodeJS/NpmDependency.spec.js | 24 +++++----- src/test/NodeJS/NpmInstall.spec.js | 26 +++++----- src/test/NodeJS/NpmInstallLibs.spec.js | 16 +++---- src/test/NodeJS/NpmLink.spec.js | 14 +++--- src/test/NodeJS/NpmListDependencies.spec.js | 12 ++--- src/test/NodeJS/NpmPrune.spec.js | 12 ++--- src/test/NodeJS/NpmRun.spec.js | 14 +++--- src/test/NodeJS/NpmShrinkwrap.spec.js | 12 ++--- src/test/NodeJS/NpmUninstallLibs.spec.js | 14 +++--- src/test/NodeJS/NpmUpdate.spec.js | 12 ++--- .../NodeJS/PackageVersionResolver.spec.js | 14 +++--- src/test/NodeJS/UndefinedDepsResolver.spec.js | 18 +++---- src/test/Server/Hook.spec.js | 6 +-- src/test/Server/Instance.spec.js | 6 +-- src/test/Terminal/Argument.spec.js | 6 +-- src/test/Terminal/Arguments.spec.js | 6 +-- src/test/Terminal/Help.spec.js | 6 +-- src/test/Terminal/Option.spec.js | 6 +-- src/test/Terminal/Options.spec.js | 6 +-- src/test/Terminal/Program.spec.js | 6 +-- src/test/TestMaterials/Lambda/lambda.js | 2 +- 30 files changed, 191 insertions(+), 191 deletions(-) diff --git a/src/test/Helpers/Exec.spec.js b/src/test/Helpers/Exec.spec.js index c57e6520..121bdd22 100644 --- a/src/test/Helpers/Exec.spec.js +++ b/src/test/Helpers/Exec.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Exec} from '../../lib/Helpers/Exec'; -suite('Helpers/Exec', function() { - test('Class Exec exists in Helpers/Exec', function() { - chai.expect(typeof Exec).to.equal('function'); +suite('Helpers/Exec', () => { + test('Class Exec exists in Helpers/Exec', () => { + chai.expect(Exec).to.be.an('function'); }); }); diff --git a/src/test/Helpers/LambdasExtractor.spec.js b/src/test/Helpers/LambdasExtractor.spec.js index 863e4bb1..bd0c5fe5 100644 --- a/src/test/Helpers/LambdasExtractor.spec.js +++ b/src/test/Helpers/LambdasExtractor.spec.js @@ -4,15 +4,15 @@ import chai from 'chai'; import {LambdasExtractor} from '../../lib/Helpers/LambdasExtractor'; import {Property_Instance as PropertyInstance} from 'deep-package-manager'; -suite('Helpers/LambdasExtractor', function () { +suite('Helpers/LambdasExtractor', () => { let propertyInstance = null; let lambdasExtractor = null; - test('Class LambdasExtractor exists in Helpers/LambdasExtractor', function () { - chai.expect(typeof LambdasExtractor).to.equal('function'); + test('Class LambdasExtractor exists in Helpers/LambdasExtractor', () => { + chai.expect(LambdasExtractor).to.be.an('function'); }); - test('Check _extract()', function () { + test('Check _extract()', () => { propertyInstance = new PropertyInstance('./test/TestMaterials/Property2', 'deeploy.test.json'); lambdasExtractor = new LambdasExtractor(propertyInstance); @@ -22,7 +22,7 @@ suite('Helpers/LambdasExtractor', function () { chai.expect(lambdasExtractor.property).to.equal(propertyInstance); }); - test('Check _extract()', function () { + test('Check _extract()', () => { let microservices = { 'hello.world.example': { 'isRoot': false, diff --git a/src/test/Lambda/Runtime.spec.js b/src/test/Lambda/Runtime.spec.js index 812c634a..e2c46cdd 100644 --- a/src/test/Lambda/Runtime.spec.js +++ b/src/test/Lambda/Runtime.spec.js @@ -5,7 +5,7 @@ import path from 'path'; import {Runtime} from '../../lib/Lambda/Runtime'; import {Timer} from '../../lib/Lambda/Timer'; -suite('Lambda/Runtime', function() { +suite('Lambda/Runtime', () => { let runtime = null; let lambda = { name: 'testLambda', @@ -13,57 +13,57 @@ suite('Lambda/Runtime', function() { }; let lambdaPath = path.join(__dirname + './../TestMaterials/Lambda/lambda'); - test('Class Runtime exists in Lambda/Runtime', function() { - chai.expect(typeof Runtime).to.equal('function'); + test('Class Runtime exists in Lambda/Runtime', () => { + chai.expect(Runtime).to.be.an('function'); }); - test('Check constructor sets _lambda', function() { + test('Check constructor sets _lambda', () => { runtime = new Runtime(lambda); chai.expect(runtime).to.be.an.instanceOf(Runtime); chai.expect(runtime.lambda).to.eql(lambda); }); - test('Check constructor sets _measureTime = false', function() { + test('Check constructor sets _measureTime = false', () => { chai.expect(runtime.measureTime).to.equal(false); }); - test('Check constructor sets _timer = null', function() { + test('Check constructor sets _timer = null', () => { chai.expect(runtime._timer).to.equal(null); }); - test('Check constructor sets _silent = false', function() { + test('Check constructor sets _silent = false', () => { chai.expect(runtime.silent).to.equal(false); }); - test('Check constructor sets _name ', function() { + test('Check constructor sets _name ', () => { chai.expect(runtime.name).to.not.equal(''); }); - test('Check constructor sets _lambdaPath = null', function() { + test('Check constructor sets _lambdaPath = null', () => { chai.expect(runtime.lambdaPath).to.equal(null); }); - test('Check constructor sets _awsConfigFile = null', function() { + test('Check constructor sets _awsConfigFile = null', () => { chai.expect(runtime._awsConfigFile).to.equal(null); }); - test('Check ENVIRONMENT static getter', function() { + test('Check ENVIRONMENT static getter', () => { chai.expect(Runtime.ENVIRONMENT).to.equal('local'); }); - test('Check SIBLING_EXEC_WRAPPER_NAME static getter', function() { + test('Check SIBLING_EXEC_WRAPPER_NAME static getter', () => { chai.expect(Runtime.SIBLING_EXEC_WRAPPER_NAME).to.equal('_deep_lambda_exec_'); }); - test('Check createLambda()', function() { + test('Check createLambda()', () => { let actualResult = Runtime.createLambda(lambdaPath); chai.expect(actualResult).to.be.an.instanceOf(Runtime); chai.expect(actualResult.awsConfigFile).to.be.equal(null); }); - test('Check complete setter/getter', function() { + test('Check complete setter/getter', () => { let cb = () => { return 'test cb'; }; @@ -79,7 +79,7 @@ suite('Lambda/Runtime', function() { chai.expect(runtime.complete).to.equal(complete); }); - test('Check fail setter/getter', function() { + test('Check fail setter/getter', () => { let cb = () => { return 'test cb fail'; }; @@ -95,7 +95,7 @@ suite('Lambda/Runtime', function() { chai.expect(runtime.fail).to.equal(fail); }); - test('Check succeed setter/getter', function() { + test('Check succeed setter/getter', () => { let cb = () => { return 'test cb succeed'; }; @@ -111,7 +111,7 @@ suite('Lambda/Runtime', function() { chai.expect(runtime.succeed).to.equal(succeed); }); - test('Check succeed setter/getter', function() { + test('Check succeed setter/getter', () => { let measureTime = runtime.measureTime; runtime.measureTime = true; @@ -126,7 +126,7 @@ suite('Lambda/Runtime', function() { chai.expect(runtime.measureTime).to.equal(measureTime); }); - test('Check name setter/getter', function() { + test('Check name setter/getter', () => { let name = runtime.name; let lambdaName = 'new test name'; @@ -140,7 +140,7 @@ suite('Lambda/Runtime', function() { chai.expect(runtime.name).to.equal(name); }); - test('Check silent setter/getter', function() { + test('Check silent setter/getter', () => { let silent = runtime.silent; runtime.silent = true; @@ -156,7 +156,7 @@ suite('Lambda/Runtime', function() { chai.expect(runtime.silent).to.equal(silent); }); - test('Check context getter', function() { + test('Check context getter', () => { let expectedContextKeys = [ 'awsRequestId', 'fail', @@ -178,14 +178,14 @@ suite('Lambda/Runtime', function() { chai.expect(runtime.context.fail).to.be.an('function'); }); - test('Check _injectSiblingExecutionWrapper', function() { + test('Check _injectSiblingExecutionWrapper', () => { let actualResult = runtime._injectSiblingExecutionWrapper(); chai.expect(global[Runtime.SIBLING_EXEC_WRAPPER_NAME]).to.be.an('object'); chai.expect(global[Runtime.SIBLING_EXEC_WRAPPER_NAME].invoke).to.be.an('function'); chai.expect(global[Runtime.SIBLING_EXEC_WRAPPER_NAME].invokeAsync).to.be.an('function'); }); - test('Check run for _measureTime = undefined', function() { + test('Check run for _measureTime = undefined', () => { let event = { firstInputArg: 'test', secondInputArg: 2, @@ -200,7 +200,7 @@ suite('Lambda/Runtime', function() { chai.expect(actualResult.lambda.name).to.equal(lambda.name); }); - test('Check run for _measureTime != undefined', function() { + test('Check run for _measureTime != undefined', () => { let event = { firstInputArg: 'test', secondInputArg: 2, @@ -217,7 +217,7 @@ suite('Lambda/Runtime', function() { chai.expect(actualResult.lambda.name).to.equal(lambda.name); }); - test('Check _logCallback()', function() { + test('Check _logCallback()', () => { runtime.silent = true; let type = 'number'; diff --git a/src/test/Lambda/Thread.spec.js b/src/test/Lambda/Thread.spec.js index c740e79b..e139f35a 100644 --- a/src/test/Lambda/Thread.spec.js +++ b/src/test/Lambda/Thread.spec.js @@ -5,7 +5,7 @@ import path from 'path'; import {Thread} from '../../lib/Lambda/Thread'; import {Runtime} from '../../lib/Lambda/Runtime'; -suite('Lambda/Thread', function () { +suite('Lambda/Thread', () => { let lambda = { name: 'testLambda', handler: () => {}, @@ -14,11 +14,11 @@ suite('Lambda/Thread', function () { let runtime = new Runtime(lambda, lambdaPath); let thread = null; - test('Class Thread exists in Lambda/Thread', function () { - chai.expect(typeof Thread).to.equal('function'); + test('Class Thread exists in Lambda/Thread', () => { + chai.expect(Thread).to.be.an('function'); }); - test('Check constructor sets _lambda', function () { + test('Check constructor sets _lambda', () => { thread = new Thread(runtime); chai.expect(thread).to.be.an.instanceOf(Thread); @@ -26,18 +26,18 @@ suite('Lambda/Thread', function () { chai.expect(thread.process).to.equal(null); }); - test('Check WRAPPER static getter', function () { + test('Check WRAPPER static getter', () => { chai.expect(Thread.WRAPPER).to.contains('thread_wrapper.js'); }); - test('Check _cleanup()', function () { + test('Check _cleanup()', () => { let actualResult = thread._cleanup(); chai.expect(actualResult).to.be.an.instanceOf(Thread); chai.expect(thread.process).to.equal(null); }); - test('Check run()', function () { + test('Check run()', () => { runtime.silent = true; let event = { firstInputArg: 'test', diff --git a/src/test/Lambda/Timer.spec.js b/src/test/Lambda/Timer.spec.js index ae4943b2..cee304cb 100644 --- a/src/test/Lambda/Timer.spec.js +++ b/src/test/Lambda/Timer.spec.js @@ -3,17 +3,17 @@ import chai from 'chai'; import {Timer} from '../../lib/Lambda/Timer'; -suite('Lambda/Timer', function() { +suite('Lambda/Timer', () => { let name = 'testName'; let timer = null; let approxStartTime = null; let approxStoptTime = null; - test('Class Timer exists in Lambda/Timer', function() { - chai.expect(typeof Timer).to.equal('function'); + test('Class Timer exists in Lambda/Timer', () => { + chai.expect(Timer).to.be.an('function'); }); - test('Check constructor sets _name, _startTime, _stopTime', function() { + test('Check constructor sets _name, _startTime, _stopTime', () => { timer = new Timer(name); chai.expect(timer).to.be.an.instanceOf(Timer); @@ -24,7 +24,7 @@ suite('Lambda/Timer', function() { chai.expect(timer.stopTimeSec).to.equal(null); }); - test('Check start()', function() { + test('Check start()', () => { approxStartTime = new Date().getTime(); let actualResult = timer.start(); @@ -36,7 +36,7 @@ suite('Lambda/Timer', function() { ); }); - test('Check stop()', function() { + test('Check stop()', () => { let actualResult = timer.stop(); approxStoptTime = new Date().getTime(); @@ -48,7 +48,7 @@ suite('Lambda/Timer', function() { ).to.be.at.least(actualResult.stopTimeSec); }); - test('Check time getter', function() { + test('Check time getter', () => { let expectedResult = approxStoptTime - approxStartTime; chai.expect(expectedResult).to.be.at.least(timer.time); @@ -57,19 +57,19 @@ suite('Lambda/Timer', function() { ).to.be.at.least(timer.timeSec); }); - test('Check toString() for sec', function() { + test('Check toString() for sec', () => { chai.expect(timer.toString()).to.equal( `Timing for ${name}: ${timer.timeSec} seconds` ); }); - test('Check toString() for !sec', function() { + test('Check toString() for !sec', () => { chai.expect(timer.toString(false)).to.equal( `Timing for ${name}: ${timer.time} miliseconds` ); }); - test('Check time for !startTime', function() { + test('Check time for !startTime', () => { //arrange approxStartTime = new Date().getTime(); diff --git a/src/test/NodeJS/Bin.spec.js b/src/test/NodeJS/Bin.spec.js index feeea596..c5686c4c 100644 --- a/src/test/NodeJS/Bin.spec.js +++ b/src/test/NodeJS/Bin.spec.js @@ -3,35 +3,35 @@ import chai from 'chai'; import {Bin} from '../../lib/NodeJS/Bin'; -suite('NodeJS/Bin', function() { - test('Class Bin exists in NodeJS/Bin', function() { - chai.expect(typeof Bin).to.equal('function'); +suite('NodeJS/Bin', () => { + test('Class Bin exists in NodeJS/Bin', () => { + chai.expect(Bin).to.be.an('function'); }); - test('Check npmModuleInstalled() returns true for global mocha', function() { + test('Check npmModuleInstalled() returns true for global mocha', () => { chai.expect(Bin.npmModuleInstalled('mocha', true)).to.equal(true); }); - test('Check npmModuleInstalled() returns true for local fs-extra', function() { + test('Check npmModuleInstalled() returns true for local fs-extra', () => { chai.expect(Bin.npmModuleInstalled('fs-extra', false)).to.equal(true); }); - test('Check npmMajorVersion returns version above than 1', function() { + test('Check npmMajorVersion returns version above than 1', () => { chai.expect(Bin.npmMajorVersion).to.be.above(1); }); - test('Check nodeMajorVersion returns version above than -1', function() { + test('Check nodeMajorVersion returns version above than -1', () => { chai.expect(Bin.nodeMajorVersion).to.be.above(-1); }); - test('Check node returns valid string', function() { + test('Check node returns valid string', () => { chai.expect(Bin.node).to.contain('node'); //check when Bin._node already setted chai.expect(Bin.node).to.contain('node'); }); - test('Check npm returns valid string', function() { + test('Check npm returns valid string', () => { chai.expect(Bin.npm).to.contain('npm'); //check when Bin._node already setted diff --git a/src/test/NodeJS/DepsTreeOptimizer.spec.js b/src/test/NodeJS/DepsTreeOptimizer.spec.js index ebfcc2a9..03ca5682 100644 --- a/src/test/NodeJS/DepsTreeOptimizer.spec.js +++ b/src/test/NodeJS/DepsTreeOptimizer.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {DepsTreeOptimizer} from '../../lib/NodeJS/DepsTreeOptimizer'; -suite('NodeJS/DepsTreeOptimizer', function() { - test('Class DepsTreeOptimizer exists in NodeJS/DepsTreeOptimizer', function() { - chai.expect(typeof DepsTreeOptimizer).to.equal('function'); +suite('NodeJS/DepsTreeOptimizer', () => { + test('Class DepsTreeOptimizer exists in NodeJS/DepsTreeOptimizer', () => { + chai.expect(DepsTreeOptimizer).to.be.an('function'); }); }); diff --git a/src/test/NodeJS/NpmChain.spec.js b/src/test/NodeJS/NpmChain.spec.js index 7addcbb0..b3476c23 100644 --- a/src/test/NodeJS/NpmChain.spec.js +++ b/src/test/NodeJS/NpmChain.spec.js @@ -6,16 +6,16 @@ import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; import {NpmLink} from '../../lib/NodeJS/NpmLink'; import {NpmUpdate} from '../../lib/NodeJS/NpmUpdate'; -suite('NodeJS/NpmChain', function() { +suite('NodeJS/NpmChain', () => { let npmLink = null; let npmUpdate = new NpmUpdate(); let npmChain = null; - test('Class NpmChain exists in NodeJS/NpmChain', function() { - chai.expect(typeof NpmChain).to.equal('function'); + test('Class NpmChain exists in NodeJS/NpmChain', () => { + chai.expect(NpmChain).to.be.an('function'); }); - test('Check constructor sets _commands', function() { + test('Check constructor sets _commands', () => { let libs = 'mocha isparta'; npmLink = new NpmLink(); npmLink.libs = libs; @@ -26,7 +26,7 @@ suite('NodeJS/NpmChain', function() { chai.expect(npmChain.commands).to.include(npmLink); }); - test('Check add() adds command', function() { + test('Check add() adds command', () => { npmChain.add(npmUpdate); chai.expect(npmChain).to.be.an.instanceOf(NpmChain); chai.expect(npmChain.commands).to.include(npmLink); diff --git a/src/test/NodeJS/NpmDedupe.spec.js b/src/test/NodeJS/NpmDedupe.spec.js index 032d7f7d..81cfcac6 100644 --- a/src/test/NodeJS/NpmDedupe.spec.js +++ b/src/test/NodeJS/NpmDedupe.spec.js @@ -4,19 +4,19 @@ import chai from 'chai'; import {NpmDedupe} from '../../lib/NodeJS/NpmDedupe'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmDedupe', function() { +suite('NodeJS/NpmDedupe', () => { let npmDedupe = null; - test('Class NpmDedupe exists in NodeJS/NpmDedupe', function() { - chai.expect(typeof NpmDedupe).to.equal('function'); + test('Class NpmDedupe exists in NodeJS/NpmDedupe', () => { + chai.expect(NpmDedupe).to.be.an('function'); }); - test('Check constructor sets _cmd = null', function() { + test('Check constructor sets _cmd = null', () => { npmDedupe = new NpmDedupe(); chai.expect(npmDedupe).to.be.an.instanceOf(NpmDedupe); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmDedupe._newInstance(args); @@ -26,7 +26,7 @@ suite('NodeJS/NpmDedupe', function() { chai.expect(actualResult.dirs).to.eql(args); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmDedupe._mainCmd).to.includes('npm dedupe'); }); }); diff --git a/src/test/NodeJS/NpmDependency.spec.js b/src/test/NodeJS/NpmDependency.spec.js index c966f736..7f7bf268 100644 --- a/src/test/NodeJS/NpmDependency.spec.js +++ b/src/test/NodeJS/NpmDependency.spec.js @@ -3,49 +3,49 @@ import chai from 'chai'; import {NpmDependency} from '../../lib/NodeJS/NpmDependency'; -suite('NodeJS/NpmDependency', function() { +suite('NodeJS/NpmDependency', () => { let name = 'mocha'; let version = '2.3.4'; let npmDependency = new NpmDependency(name, version); - test('Class NpmDependency exists in NodeJS/NpmDependency', function() { - chai.expect(typeof NpmDependency).to.equal('function'); + test('Class NpmDependency exists in NodeJS/NpmDependency', () => { + chai.expect(NpmDependency).to.be.an('function'); }); - test(`Check constructor sets _name = ${name}`, function() { + test(`Check constructor sets _name = ${name}`, () => { chai.expect(npmDependency).to.be.an.instanceOf(NpmDependency); chai.expect(npmDependency.name).to.equal(name); }); - test(`Check constructor sets _version = ${version}`, function() { + test(`Check constructor sets _version = ${version}`, () => { chai.expect(npmDependency.version).to.equal(version); }); - test(`Check constructor sets _requestedVersion = ${version}`, function() { + test(`Check constructor sets _requestedVersion = ${version}`, () => { chai.expect(npmDependency.requestedVersion).to.equal(version); }); - test('Check constructor sets _parent = null', function() { + test('Check constructor sets _parent = null', () => { chai.expect(npmDependency.parent).to.equal(null); }); - test('Check constructor sets _children = []', function() { + test('Check constructor sets _children = []', () => { chai.expect(npmDependency.children).to.eql([]); }); - test('Check constructor sets isMain = false by default', function() { + test('Check constructor sets isMain = false by default', () => { chai.expect(npmDependency.isMain).to.eql(false); }); - test('Check constructor sets _defaultRootPath = ""', function() { + test('Check constructor sets _defaultRootPath = ""', () => { chai.expect(npmDependency.defaultRootPath).to.eql(''); }); - test(`Check fullName returns ${name}@${version}`, function() { + test(`Check fullName returns ${name}@${version}`, () => { chai.expect(npmDependency.fullName).to.eql(`${name}@${version}`); }); - test('Check NODE_MODULES_DIR', function() { + test('Check NODE_MODULES_DIR', () => { chai.expect(NpmDependency.NODE_MODULES_DIR).to.equal('node_modules'); }); }); diff --git a/src/test/NodeJS/NpmInstall.spec.js b/src/test/NodeJS/NpmInstall.spec.js index 45de328e..413fa712 100644 --- a/src/test/NodeJS/NpmInstall.spec.js +++ b/src/test/NodeJS/NpmInstall.spec.js @@ -3,41 +3,41 @@ import chai from 'chai'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmInstall', function() { +suite('NodeJS/NpmInstall', () => { let npmInstall = new NpmInstall(); - test('Class NpmInstall exists in NodeJS/NpmInstall', function() { - chai.expect(typeof NpmInstall).to.equal('function'); + test('Class NpmInstall exists in NodeJS/NpmInstall', () => { + chai.expect(NpmInstall).to.be.an('function'); }); - test('Check DEFAULT_SILENT_STATE getter returns false', function() { + test('Check DEFAULT_SILENT_STATE getter returns false', () => { chai.expect(NpmInstall.DEFAULT_SILENT_STATE).to.equal(false); }); - test('Check DEFAULT_CHUNK_SIZE getter returns value above than 0', function() { + test('Check DEFAULT_CHUNK_SIZE getter returns value above than 0', () => { chai.expect(NpmInstall.DEFAULT_CHUNK_SIZE).to.above(0); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmInstall._mainCmd).to.includes('npm install'); }); - test('Check constructor sets valid value for _dirs', function() { + test('Check constructor sets valid value for _dirs', () => { chai.expect(npmInstall).to.be.an.instanceOf(NpmInstall); chai.expect(npmInstall.dirs).to.be.eql([]); }); - test('Check constructor sets valid value for _extraArgs', function() { + test('Check constructor sets valid value for _extraArgs', () => { chai.expect(Array.isArray(npmInstall.extraArgs)).to.be.equal(true); chai.expect(npmInstall.extraArgs).to.eql([]); }); - test('Check _execArgs getter', function() { + test('Check _execArgs getter', () => { chai.expect(Array.isArray(npmInstall._execArgs)).to.be.equal(true); chai.expect(npmInstall._execArgs[0]).to.includes('npm install'); }); - test('Check addExtraArg()', function() { + test('Check addExtraArg()', () => { let length = npmInstall.extraArgs.length; let newArg = 'logLevel=debug'; @@ -48,7 +48,7 @@ suite('NodeJS/NpmInstall', function() { chai.expect(actualResult.extraArgs.pop()).to.equal(newArg); }); - test('Check _chunkArray() returns valid array', function() { + test('Check _chunkArray() returns valid array', () => { let toChunkArray = ['one', 'two', 'three', 'four']; let expectedResult = [['one', 'two', 'three'], ['four']]; let size = 3; @@ -59,7 +59,7 @@ suite('NodeJS/NpmInstall', function() { chai.expect(actualResult).to.eql(expectedResult); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmInstall._newInstance(args); @@ -69,7 +69,7 @@ suite('NodeJS/NpmInstall', function() { chai.expect(actualResult.dirs).to.eql(args); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha']; let actualResult = npmInstall._newInstance(args); diff --git a/src/test/NodeJS/NpmInstallLibs.spec.js b/src/test/NodeJS/NpmInstallLibs.spec.js index 380eded3..de7fec73 100644 --- a/src/test/NodeJS/NpmInstallLibs.spec.js +++ b/src/test/NodeJS/NpmInstallLibs.spec.js @@ -4,23 +4,23 @@ import chai from 'chai'; import {NpmInstallLibs} from '../../lib/NodeJS/NpmInstallLibs'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmInstallLibs', function() { +suite('NodeJS/NpmInstallLibs', () => { let libs = 'mocha isparta'; let libsArray = ['codacy-coverage', 'istanbul']; let npmInstallLibs = null; - test('Class NpmInstallLibs exists in NodeJS/NpmInstallLibs', function() { - chai.expect(typeof NpmInstallLibs).to.equal('function'); + test('Class NpmInstallLibs exists in NodeJS/NpmInstallLibs', () => { + chai.expect(NpmInstallLibs).to.be.an('function'); }); - test('Check constructor sets _libsPlain = null, global = false', function() { + test('Check constructor sets _libsPlain = null, global = false', () => { npmInstallLibs = new NpmInstallLibs(); chai.expect(npmInstallLibs).to.be.an.instanceOf(NpmInstallLibs); chai.expect(npmInstallLibs.libsPlain).to.equal(null); chai.expect(npmInstallLibs.global).to.equal(false); }); - test('Check _libsPlain setter', function() { + test('Check _libsPlain setter', () => { npmInstallLibs.libs = libsArray; chai.expect(npmInstallLibs.libsPlain).to.equal(libsArray.join(' ')); @@ -28,7 +28,7 @@ suite('NodeJS/NpmInstallLibs', function() { chai.expect(npmInstallLibs.libsPlain).to.equal(libs); }); - test('Check global setter', function() { + test('Check global setter', () => { npmInstallLibs.global = false; chai.expect(npmInstallLibs.global).to.equal(false); @@ -37,7 +37,7 @@ suite('NodeJS/NpmInstallLibs', function() { chai.expect(npmInstallLibs.dirs).to.eql([process.cwd()]); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmInstallLibs._newInstance(args); @@ -46,7 +46,7 @@ suite('NodeJS/NpmInstallLibs', function() { chai.expect(actualResult.libsPlain).to.equal(libs); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmInstallLibs._mainCmd).to.includes(`npm install ${libs}`); }); }); diff --git a/src/test/NodeJS/NpmLink.spec.js b/src/test/NodeJS/NpmLink.spec.js index 6efd3bde..596e2945 100644 --- a/src/test/NodeJS/NpmLink.spec.js +++ b/src/test/NodeJS/NpmLink.spec.js @@ -4,22 +4,22 @@ import chai from 'chai'; import {NpmLink} from '../../lib/NodeJS/NpmLink'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmLink', function() { +suite('NodeJS/NpmLink', () => { let libs = 'mocha isparta'; let libsArray = ['codacy-coverage', 'istanbul']; let npmLink = null; - test('Class NpmLink exists in NodeJS/NpmLink', function() { - chai.expect(typeof NpmLink).to.equal('function'); + test('Class NpmLink exists in NodeJS/NpmLink', () => { + chai.expect(NpmLink).to.be.an('function'); }); - test('Check constructor sets _libsPlain = null', function() { + test('Check constructor sets _libsPlain = null', () => { npmLink = new NpmLink(); chai.expect(npmLink).to.be.an.instanceOf(NpmLink); chai.expect(npmLink.libsPlain).to.equal(null); }); - test('Check _libsPlain setter', function() { + test('Check _libsPlain setter', () => { npmLink.libs = libsArray; chai.expect(npmLink.libsPlain).to.equal(libsArray.join(' ')); @@ -27,7 +27,7 @@ suite('NodeJS/NpmLink', function() { chai.expect(npmLink.libsPlain).to.equal(libs); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmLink._newInstance(args); @@ -36,7 +36,7 @@ suite('NodeJS/NpmLink', function() { chai.expect(actualResult.libsPlain).to.equal(libs); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmLink._mainCmd).to.includes(`npm link ${libs}`); }); }); diff --git a/src/test/NodeJS/NpmListDependencies.spec.js b/src/test/NodeJS/NpmListDependencies.spec.js index 866f3828..b0b1415c 100644 --- a/src/test/NodeJS/NpmListDependencies.spec.js +++ b/src/test/NodeJS/NpmListDependencies.spec.js @@ -5,27 +5,27 @@ import {NpmListDependencies} from '../../lib/NodeJS/NpmListDependencies'; import {NpmDependency} from '../../lib/NodeJS/NpmDependency'; import {NpmDepsListException} from '../../lib/NodeJS/Exception/NpmDepsListException'; -suite('NodeJS/NpmListDependencies', function() { +suite('NodeJS/NpmListDependencies', () => { let npmListDependencies = null - test('Class NpmListDependencies exists in NodeJS/NpmListDependencies', function() { - chai.expect(typeof NpmListDependencies).to.equal('function'); + test('Class NpmListDependencies exists in NodeJS/NpmListDependencies', () => { + chai.expect(NpmListDependencies).to.be.an('function'); }); - test('Check constructor sets _path', function() { + test('Check constructor sets _path', () => { let currentDirectory = __dirname; npmListDependencies = new NpmListDependencies(currentDirectory); chai.expect(npmListDependencies).to.be.an.instanceOf(NpmListDependencies); chai.expect(npmListDependencies.path).to.equal(currentDirectory); }); - test('Check list(0)', function() { + test('Check list(0)', () => { let actualResult = npmListDependencies.list(0); chai.expect(actualResult).to.be.an.instanceOf(NpmDependency); }); - test('Check list() throws NpmDepsListException', function() { + test('Check list() throws NpmDepsListException', () => { let error = null; npmListDependencies = new NpmListDependencies('invalidPath'); diff --git a/src/test/NodeJS/NpmPrune.spec.js b/src/test/NodeJS/NpmPrune.spec.js index 72e73e41..d84596ce 100644 --- a/src/test/NodeJS/NpmPrune.spec.js +++ b/src/test/NodeJS/NpmPrune.spec.js @@ -4,19 +4,19 @@ import chai from 'chai'; import {NpmPrune} from '../../lib/NodeJS/NpmPrune'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmPrune', function() { +suite('NodeJS/NpmPrune', () => { let npmPrune = null; - test('Class NpmPrune exists in NodeJS/NpmPrune', function() { - chai.expect(typeof NpmPrune).to.equal('function'); + test('Class NpmPrune exists in NodeJS/NpmPrune', () => { + chai.expect(NpmPrune).to.be.an('function'); }); - test('Check constructor sets _cmd = null', function() { + test('Check constructor sets _cmd = null', () => { npmPrune = new NpmPrune(); chai.expect(npmPrune).to.be.an.instanceOf(NpmPrune); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmPrune._newInstance(args); @@ -26,7 +26,7 @@ suite('NodeJS/NpmPrune', function() { chai.expect(actualResult.dirs).to.eql(args); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmPrune._mainCmd).to.includes('npm prune'); }); }); diff --git a/src/test/NodeJS/NpmRun.spec.js b/src/test/NodeJS/NpmRun.spec.js index cf382a9f..630f460c 100644 --- a/src/test/NodeJS/NpmRun.spec.js +++ b/src/test/NodeJS/NpmRun.spec.js @@ -4,21 +4,21 @@ import chai from 'chai'; import {NpmRun} from '../../lib/NodeJS/NpmRun'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmRun', function() { +suite('NodeJS/NpmRun', () => { let npmRun = null; let cmd = 'test'; - test('Class NpmRun exists in NodeJS/NpmRun', function() { - chai.expect(typeof NpmRun).to.equal('function'); + test('Class NpmRun exists in NodeJS/NpmRun', () => { + chai.expect(NpmRun).to.be.an('function'); }); - test('Check constructor sets _cmd = null', function() { + test('Check constructor sets _cmd = null', () => { npmRun = new NpmRun(); chai.expect(npmRun).to.be.an.instanceOf(NpmRun); chai.expect(npmRun.cmd).to.equal(null); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmRun._newInstance(args); @@ -28,13 +28,13 @@ suite('NodeJS/NpmRun', function() { chai.expect(actualResult.dirs).to.eql(args); }); - test('Check cmd setter', function() { + test('Check cmd setter', () => { npmRun.cmd = cmd; chai.expect(npmRun.cmd).to.equal(cmd); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmRun._mainCmd).to.includes(`npm run ${cmd}`); }); }); diff --git a/src/test/NodeJS/NpmShrinkwrap.spec.js b/src/test/NodeJS/NpmShrinkwrap.spec.js index 8dc0515a..834763dc 100644 --- a/src/test/NodeJS/NpmShrinkwrap.spec.js +++ b/src/test/NodeJS/NpmShrinkwrap.spec.js @@ -4,19 +4,19 @@ import chai from 'chai'; import {NpmShrinkwrap} from '../../lib/NodeJS/NpmShrinkwrap'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmShrinkwrap', function() { +suite('NodeJS/NpmShrinkwrap', () => { let npmShrinkwrap = null; - test('Class NpmShrinkwrap exists in NodeJS/NpmShrinkwrap', function() { - chai.expect(typeof NpmShrinkwrap).to.equal('function'); + test('Class NpmShrinkwrap exists in NodeJS/NpmShrinkwrap', () => { + chai.expect(NpmShrinkwrap).to.be.an('function'); }); - test('Check constructor sets _cmd = null', function() { + test('Check constructor sets _cmd = null', () => { npmShrinkwrap = new NpmShrinkwrap(); chai.expect(npmShrinkwrap).to.be.an.instanceOf(NpmShrinkwrap); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmShrinkwrap._newInstance(args); @@ -26,7 +26,7 @@ suite('NodeJS/NpmShrinkwrap', function() { chai.expect(actualResult.dirs).to.eql(args); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmShrinkwrap._mainCmd).to.includes('npm shrinkwrap'); }); }); diff --git a/src/test/NodeJS/NpmUninstallLibs.spec.js b/src/test/NodeJS/NpmUninstallLibs.spec.js index bade8d75..b8c16281 100644 --- a/src/test/NodeJS/NpmUninstallLibs.spec.js +++ b/src/test/NodeJS/NpmUninstallLibs.spec.js @@ -4,22 +4,22 @@ import chai from 'chai'; import {NpmUninstallLibs} from '../../lib/NodeJS/NpmUninstallLibs'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmUninstallLibs', function() { +suite('NodeJS/NpmUninstallLibs', () => { let libs = 'mocha isparta'; let libsArray = ['codacy-coverage', 'istanbul']; let npmUninstallLibs = null; - test('Class NpmUninstallLibs exists in NodeJS/NpmUninstallLibs', function() { - chai.expect(typeof NpmUninstallLibs).to.equal('function'); + test('Class NpmUninstallLibs exists in NodeJS/NpmUninstallLibs', () => { + chai.expect(NpmUninstallLibs).to.be.an('function'); }); - test('Check constructor sets _libsPlain = null', function() { + test('Check constructor sets _libsPlain = null', () => { npmUninstallLibs = new NpmUninstallLibs(); chai.expect(npmUninstallLibs).to.be.an.instanceOf(NpmUninstallLibs); chai.expect(npmUninstallLibs.libsPlain).to.equal(null); }); - test('Check _libsPlain setter', function() { + test('Check _libsPlain setter', () => { npmUninstallLibs.libs = libsArray; chai.expect(npmUninstallLibs.libsPlain).to.equal(libsArray.join(' ')); @@ -27,7 +27,7 @@ suite('NodeJS/NpmUninstallLibs', function() { chai.expect(npmUninstallLibs.libsPlain).to.equal(libs); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmUninstallLibs._newInstance(args); @@ -36,7 +36,7 @@ suite('NodeJS/NpmUninstallLibs', function() { chai.expect(actualResult.libsPlain).to.equal(libs); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmUninstallLibs._mainCmd).to.includes(`npm uninstall ${libs}`); }); }); diff --git a/src/test/NodeJS/NpmUpdate.spec.js b/src/test/NodeJS/NpmUpdate.spec.js index 74439383..c9788272 100644 --- a/src/test/NodeJS/NpmUpdate.spec.js +++ b/src/test/NodeJS/NpmUpdate.spec.js @@ -4,19 +4,19 @@ import chai from 'chai'; import {NpmUpdate} from '../../lib/NodeJS/NpmUpdate'; import {NpmInstall} from '../../lib/NodeJS/NpmInstall'; -suite('NodeJS/NpmUpdate', function() { +suite('NodeJS/NpmUpdate', () => { let npmUpdate = null; - test('Class NpmUpdate exists in NodeJS/NpmUpdate', function() { - chai.expect(typeof NpmUpdate).to.equal('function'); + test('Class NpmUpdate exists in NodeJS/NpmUpdate', () => { + chai.expect(NpmUpdate).to.be.an('function'); }); - test('Check constructor sets _cmd = null', function() { + test('Check constructor sets _cmd = null', () => { npmUpdate = new NpmUpdate(); chai.expect(npmUpdate).to.be.an.instanceOf(NpmUpdate); }); - test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', function() { + test('Check _newInstance() returns new NpmInstall instance with dirs.length = 3', () => { let args = ['mocha', '-g', 'logLevel=debug']; let actualResult = npmUpdate._newInstance(args); @@ -26,7 +26,7 @@ suite('NodeJS/NpmUpdate', function() { chai.expect(actualResult.dirs).to.eql(args); }); - test('Check _mainCmd getter returns valid string', function() { + test('Check _mainCmd getter returns valid string', () => { chai.expect(npmUpdate._mainCmd).to.includes('npm update'); }); }); diff --git a/src/test/NodeJS/PackageVersionResolver.spec.js b/src/test/NodeJS/PackageVersionResolver.spec.js index 96a711dd..89ba8f84 100644 --- a/src/test/NodeJS/PackageVersionResolver.spec.js +++ b/src/test/NodeJS/PackageVersionResolver.spec.js @@ -3,7 +3,7 @@ import chai from 'chai'; import {PackageVersionResolver} from '../../lib/NodeJS/PackageVersionResolver'; -suite('NodeJS/PackageVersionResolver', function() { +suite('NodeJS/PackageVersionResolver', () => { let name = 'mocha'; let version = '2.3.4'; let nameWithVersion = 'mocha@2.3.4'; @@ -11,11 +11,11 @@ suite('NodeJS/PackageVersionResolver', function() { let packageVersionResolver = null; - test('Class PackageVersionResolver exists in NodeJS/PackageVersionResolver', function() { - chai.expect(typeof PackageVersionResolver).to.equal('function'); + test('Class PackageVersionResolver exists in NodeJS/PackageVersionResolver', () => { + chai.expect(PackageVersionResolver).to.be.an('function'); }); - test('Check constructor for !version', function() { + test('Check constructor for !version', () => { packageVersionResolver = new PackageVersionResolver(packagePath, nameWithVersion, null); chai.expect(packageVersionResolver).to.be.an.instanceOf(PackageVersionResolver); @@ -25,7 +25,7 @@ suite('NodeJS/PackageVersionResolver', function() { chai.expect(packageVersionResolver.version).to.equal(version); }); - test('Check constructor for version', function() { + test('Check constructor for version', () => { packageVersionResolver = new PackageVersionResolver(packagePath, name, version); chai.expect(packageVersionResolver).to.be.an.instanceOf(PackageVersionResolver); @@ -35,13 +35,13 @@ suite('NodeJS/PackageVersionResolver', function() { chai.expect(packageVersionResolver.version).to.equal(version); }); - test('Check _command() returns valid string', function() { + test('Check _command() returns valid string', () => { chai.expect(packageVersionResolver._command).to.contain( `npm ls --loglevel silent --json ${packageVersionResolver._fullName}` ); }); - test('Check _fullName() returns valid string', function() { + test('Check _fullName() returns valid string', () => { chai.expect(packageVersionResolver._fullName).to.equal(`${name}@'${version}'`); }); }); diff --git a/src/test/NodeJS/UndefinedDepsResolver.spec.js b/src/test/NodeJS/UndefinedDepsResolver.spec.js index 161eb30e..d14396e7 100644 --- a/src/test/NodeJS/UndefinedDepsResolver.spec.js +++ b/src/test/NodeJS/UndefinedDepsResolver.spec.js @@ -4,17 +4,17 @@ import chai from 'chai'; import {UndefinedDepsResolver} from '../../lib/NodeJS/UndefinedDepsResolver'; import {NpmDependency} from '../../lib/NodeJS/NpmDependency'; -suite('NodeJS/UndefinedDepsResolver', function() { +suite('NodeJS/UndefinedDepsResolver', () => { let name = 'mocha'; let version = '2.3.4'; let mainDep = new NpmDependency(name, version, true); let undefinedDepsResolver = new UndefinedDepsResolver(mainDep); - test('Class UndefinedDepsResolver exists in NodeJS/UndefinedDepsResolver', function() { - chai.expect(typeof UndefinedDepsResolver).to.equal('function'); + test('Class UndefinedDepsResolver exists in NodeJS/UndefinedDepsResolver', () => { + chai.expect(UndefinedDepsResolver).to.be.an('function'); }); - test('Check UndefinedDepsResolver constructor throws Error for !mainDep.isMain', function() { + test('Check UndefinedDepsResolver constructor throws Error for !mainDep.isMain', () => { let error = null; let mainDep = new NpmDependency(name, version, false); @@ -29,7 +29,7 @@ suite('NodeJS/UndefinedDepsResolver', function() { }); test('Check UndefinedDepsResolver constructor throws Error for !mainDep.isMain', - function() { + () => { let error = null; let mainDep = new NpmDependency(name, null, true); @@ -44,20 +44,20 @@ suite('NodeJS/UndefinedDepsResolver', function() { } ); - test('Check constructor sets _mainDep', function() { + test('Check constructor sets _mainDep', () => { chai.expect(undefinedDepsResolver).to.be.an.instanceOf(UndefinedDepsResolver); chai.expect(undefinedDepsResolver.mainDep).to.equal(mainDep); }); - test('Check constructor sets _undefinedStack', function() { + test('Check constructor sets _undefinedStack', () => { chai.expect(undefinedDepsResolver._undefinedStack).to.eql([]); }); - test('Check constructor sets _cloneShadow', function() { + test('Check constructor sets _cloneShadow', () => { chai.expect(undefinedDepsResolver._cloneShadow).to.eql({}); }); - test('Check constructor sets _resolvedStack', function() { + test('Check constructor sets _resolvedStack', () => { chai.expect(undefinedDepsResolver._resolvedStack).to.eql({}); }); }); diff --git a/src/test/Server/Hook.spec.js b/src/test/Server/Hook.spec.js index 911c7a55..4d228842 100644 --- a/src/test/Server/Hook.spec.js +++ b/src/test/Server/Hook.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Hook} from '../../lib/Server/Hook'; -suite('Server/Hook', function() { - test('Class Hook exists in Server/Hook', function() { - chai.expect(typeof Hook).to.equal('function'); +suite('Server/Hook', () => { + test('Class Hook exists in Server/Hook', () => { + chai.expect(Hook).to.be.an('function'); }); }); diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index 2d3580b7..ea09d356 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Instance} from '../../lib/Server/Instance'; -suite('Server/Instance', function() { - test('Class Instance exists in Server/Instance', function() { - chai.expect(typeof Instance).to.equal('function'); +suite('Server/Instance', () => { + test('Class Instance exists in Server/Instance', () => { + chai.expect(Instance).to.be.an('function'); }); }); diff --git a/src/test/Terminal/Argument.spec.js b/src/test/Terminal/Argument.spec.js index 1628b50d..6615a79d 100644 --- a/src/test/Terminal/Argument.spec.js +++ b/src/test/Terminal/Argument.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Argument} from '../../lib/Terminal/Argument'; -suite('Terminal/Argument', function() { - test('Class Argument exists in Terminal/Argument', function() { - chai.expect(typeof Argument).to.equal('function'); +suite('Terminal/Argument', () => { + test('Class Argument exists in Terminal/Argument', () => { + chai.expect(Argument).to.be.an('function'); }); }); diff --git a/src/test/Terminal/Arguments.spec.js b/src/test/Terminal/Arguments.spec.js index 75eb429e..9ba5b35c 100644 --- a/src/test/Terminal/Arguments.spec.js +++ b/src/test/Terminal/Arguments.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Arguments} from '../../lib/Terminal/Arguments'; -suite('Terminal/Arguments', function() { - test('Class Arguments exists in Terminal/Arguments', function() { - chai.expect(typeof Arguments).to.equal('function'); +suite('Terminal/Arguments', () => { + test('Class Arguments exists in Terminal/Arguments', () => { + chai.expect(Arguments).to.be.an('function'); }); }); diff --git a/src/test/Terminal/Help.spec.js b/src/test/Terminal/Help.spec.js index 2de9336f..9f641e14 100644 --- a/src/test/Terminal/Help.spec.js +++ b/src/test/Terminal/Help.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Help} from '../../lib/Terminal/Help'; -suite('Terminal/Help', function() { - test('Class Help exists in Terminal/Help', function() { - chai.expect(typeof Help).to.equal('function'); +suite('Terminal/Help', () => { + test('Class Help exists in Terminal/Help', () => { + chai.expect(Help).to.be.an('function'); }); }); diff --git a/src/test/Terminal/Option.spec.js b/src/test/Terminal/Option.spec.js index 4987e38d..b0cb5d45 100644 --- a/src/test/Terminal/Option.spec.js +++ b/src/test/Terminal/Option.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Option} from '../../lib/Terminal/Option'; -suite('Terminal/Option', function() { - test('Class Option exists in Terminal/Option', function() { - chai.expect(typeof Option).to.equal('function'); +suite('Terminal/Option', () => { + test('Class Option exists in Terminal/Option', () => { + chai.expect(Option).to.be.an('function'); }); }); diff --git a/src/test/Terminal/Options.spec.js b/src/test/Terminal/Options.spec.js index fc90cf21..d7adb706 100644 --- a/src/test/Terminal/Options.spec.js +++ b/src/test/Terminal/Options.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Options} from '../../lib/Terminal/Options'; -suite('Terminal/Options', function() { - test('Class Options exists in Terminal/Options', function() { - chai.expect(typeof Options).to.equal('function'); +suite('Terminal/Options', () => { + test('Class Options exists in Terminal/Options', () => { + chai.expect(Options).to.be.an('function'); }); }); diff --git a/src/test/Terminal/Program.spec.js b/src/test/Terminal/Program.spec.js index 64bb082b..bc227b39 100644 --- a/src/test/Terminal/Program.spec.js +++ b/src/test/Terminal/Program.spec.js @@ -3,8 +3,8 @@ import chai from 'chai'; import {Program} from '../../lib/Terminal/Program'; -suite('Terminal/Program', function() { - test('Class Program exists in Terminal/Program', function() { - chai.expect(typeof Program).to.equal('function'); +suite('Terminal/Program', () => { + test('Class Program exists in Terminal/Program', () => { + chai.expect(Program).to.be.an('function'); }); }); diff --git a/src/test/TestMaterials/Lambda/lambda.js b/src/test/TestMaterials/Lambda/lambda.js index 89615d39..6504231f 100644 --- a/src/test/TestMaterials/Lambda/lambda.js +++ b/src/test/TestMaterials/Lambda/lambda.js @@ -4,7 +4,7 @@ 'use strict'; -module.exports = function() { +module.exports = () => { var lambda = { name: 'testLambda from file', handler: () => {},}; return lambda; }; From dbc1266b546683fd8c3cf73fffe3ec26cb908e68 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 11:06:30 +0200 Subject: [PATCH 089/133] Update unit test generation script --- src/bin/commands/deploy.js | 61 ++++++++++++----------- src/bin/manifest.js | 4 ++ src/package.json | 2 +- src/test/Helpers/LambdasExtractor.spec.js | 59 ++++++---------------- test/bin/helper/FindClasses.js | 11 ++-- 5 files changed, 59 insertions(+), 78 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index abd1820c..8668c57d 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -19,12 +19,13 @@ module.exports = function(mainPath) { var ProvisioningCollisionsDetectedException = require('deep-package-manager').Property_Exception_ProvisioningCollisionsDetectedException; var DeployConfig = require('deep-package-manager').Property_DeployConfig; + var isProd = this.opts.locate('prod').exists; var installSdk = this.opts.locate('aws-sdk').exists; var localOnly = this.opts.locate('dry-run').exists; var fastDeploy = this.opts.locate('fast').exists; var dumpCodePath = this.opts.locate('dump-local').value; var cfgBucket = this.opts.locate('cfg-bucket').value; - var appEnv = this.opts.locate('env').value; + var appEnv = isProd ? 'prod' : this.opts.locate('env').value; var hasToPullDeps = this.opts.locate('pull-deps').exists; var microservicesToDeploy = this.opts.locate('partial').value; @@ -42,7 +43,7 @@ module.exports = function(mainPath) { appEnv = appEnv ? appEnv.toLowerCase() : null; - if (DeployConfig.AVAILABLE_ENV.indexOf(appEnv) === -1) { + if (appEnv && DeployConfig.AVAILABLE_ENV.indexOf(appEnv) === -1) { console.error( 'Invalid environment "' + appEnv + '". Available environments: ' + DeployConfig.AVAILABLE_ENV.join(', ') @@ -152,33 +153,39 @@ module.exports = function(mainPath) { propertyInstance.configObj.completeDump(cb.bind(this)); } - function prepareProduction(propertyPath, cb) { - if (!localOnly) { - var prompt = new Prompt('Prepare for production?'); + function doCompileProd(propertyPath, cb) { + console.log('Start preparing for production'); - prompt.readConfirm(function(result) { - if (result) { - console.log('Start preparing for production'); + var cmd = new Exec( + Bin.node, + this.scriptPath, + 'compile-prod', + propertyPath + ); - var cmd = new Exec( - Bin.node, - this.scriptPath, - 'compile-prod', - propertyPath - ); + !fastDeploy && cmd.addArg('--remove-source'); + microservicesToDeploy && cmd.addArg('--partial ' + microservicesToDeploy); + installSdk && cmd.addArg('--aws-sdk'); + + cmd.run(function(result) { + if (result.failed) { + console.error('Backend production preparations failed: ' + result.error); + this.exit(1); + } - !fastDeploy && cmd.addArg('--remove-source'); - microservicesToDeploy && cmd.addArg('--partial ' + microservicesToDeploy); - installSdk && cmd.addArg('--aws-sdk'); + cb(); + }.bind(this), true); + } - cmd.run(function(result) { - if (result.failed) { - console.error('Backend production preparations failed: ' + result.error); - this.exit(1); - } + function prepareProduction(propertyPath, cb) { + if (isProd) { + doCompileProd.bind(this)(propertyPath, cb); + } else if (!localOnly) { + var prompt = new Prompt('Prepare for production?'); - cb(); - }.bind(this), true); + prompt.readConfirm(function(result) { + if (result) { + doCompileProd.bind(this)(propertyPath, cb); return; } @@ -187,11 +194,9 @@ module.exports = function(mainPath) { cb(); }.bind(this)); - - return; + } else { + cb(); } - - cb(); } function doDeploy() { diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 29d9983d..0aa0c07a 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -93,6 +93,10 @@ module.exports = { example: 'deepify deploy path/to/web_app', description: 'Deploy an web app', opts: { + prod: { + description: 'Prepare web app for production and ensure prod env is used', + required: false, + }, env: { alias: 'e', description: 'Web app environment to be used (default fetched from deploy config)', diff --git a/src/package.json b/src/package.json index 60c81a69..97b23cd5 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.8", + "version": "1.6.9", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", diff --git a/src/test/Helpers/LambdasExtractor.spec.js b/src/test/Helpers/LambdasExtractor.spec.js index bd0c5fe5..d98dcfe8 100644 --- a/src/test/Helpers/LambdasExtractor.spec.js +++ b/src/test/Helpers/LambdasExtractor.spec.js @@ -25,54 +25,25 @@ suite('Helpers/LambdasExtractor', () => { test('Check _extract()', () => { let microservices = { 'hello.world.example': { - 'isRoot': false, - 'parameters': {}, - 'resources': { - 'sample': { + isRoot: false, + parameters: {}, + resources: { + sample: { 'say-hello': { - 'type': 'lambda', - 'methods': [ - 'POST' + type: 'lambda', + methods: [ + 'POST', ], - 'forceUserIdentity': true, - 'region': 'us-west-2', - 'source': { - 'api': 'https://1zf47jpvxd.execute-api.us-west-2.amazonaws.com/dev/hello-world-example/sample/say-hello', - 'original': 'arn:aws:lambda:us-west-2:389615756922:function:DeepDevSampleSayHello64232f3705a' - } + forceUserIdentity: true, + region: 'us-west-2', + source: { + api: 'https://1zf47jpvxd.execute-api.us-west-2.amazonaws.com/dev/hello-world-example/sample/say-hello', + original: 'arn:aws:lambda:us-west-2:389615756922:function:DeepDevSampleSayHello64232f3705a', + }, }, - 'say-bye': { - 'type': 'lambda', - 'methods': [ - 'GET' - ], - 'forceUserIdentity': true, - 'region': 'us-west-2', - 'source': { - 'api': 'https://6jh99kuklk.execute-api.us-west-2.amazonaws.com/dev/hello-world-example/sample/say-bye', - 'original': 'arn:aws:lambda:us-west-2:389615756922:function:DeepDevSampleSayBye64232f3705a' - } - }, - 'say-test': { - 'type': 'external', - 'methods': [ - 'GET' - ], - 'forceUserIdentity': true, - 'region': 'us-west-2', - 'source': { - 'api': 'https://6jh99kuklk.execute-api.us-west-2.amazonaws.com/dev/hello-world-example/sample/say-test', - 'original': 'http://petstore.swagger.io/v2/store/inventory' - } - } - } - } + }, + }, }, - 'deep.ng.root': { - 'isRoot': true, - 'parameters': {}, - 'resources': {} - } }; let actualResult = LambdasExtractor._extract(microservices); diff --git a/test/bin/helper/FindClasses.js b/test/bin/helper/FindClasses.js index c709a622..6ba01fe4 100644 --- a/test/bin/helper/FindClasses.js +++ b/test/bin/helper/FindClasses.js @@ -29,7 +29,8 @@ export class FindClasses { for (let filepath of classFiles) { let relativePath = filepath.substr(this._libPath.length + 1); - let testFilePath = path.join(this._testsPath, relativePath); + + let testFilePath = path.join(this._testsPath, relativePath.replace('.js', '.spec.js')); if (!fs.existsSync(testFilePath)) { let testContent = FindClasses._genTestSuite(relativePath); @@ -195,9 +196,9 @@ export class FindClasses { content.push("{import}"); content.push(""); content.push("// @todo: Add more advanced tests"); - content.push("suite(\"{fullClass}\", function() {"); - content.push(" test('Class {class} exists in {fullClass}', function() {"); - content.push(" chai.expect(typeof {class}).to.equal('function');"); + content.push("suite(\'{fullClass}\', function() {"); + content.push(" test('Class {class} exists in {fullClass}', () => {"); + content.push(" chai.expect({class}).to.be.an('function');"); content.push(" });"); content.push("});"); content.push(""); @@ -216,7 +217,7 @@ export class FindClasses { * @returns {String} */ static get REAL_LIB_DIR() { - return 'lib.compiled'; + return 'lib'; } /** From 39e0d319d250593bdb0ceae0e180c678e94a2238 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 11:22:33 +0200 Subject: [PATCH 090/133] Remove vars defined but never used --- src/bin/commands/compile-prod.js | 5 +++-- src/bin/commands/deploy.js | 3 --- src/bin/commands/disable-ssl.js | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index 32983dd8..e747c1e0 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -36,7 +36,6 @@ module.exports = function(mainPath) { var property = new Property(mainPath); property.microservicesToUpdate = getMicroservicesToDeploy(); - var microservices = property.workingMicroservices; var lambdas = { path: [], tmpPath: [], @@ -330,7 +329,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; }, []); } diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 8668c57d..19f1ca9b 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -343,9 +343,6 @@ module.exports = function(mainPath) { return; } - var lambdasVector = []; - var stack = lambdas.length; - for (var i = 0; i < lambdas.length; i++) { try { fs.unlinkSync(lambdas[i]); diff --git a/src/bin/commands/disable-ssl.js b/src/bin/commands/disable-ssl.js index b23bbb46..2306f201 100644 --- a/src/bin/commands/disable-ssl.js +++ b/src/bin/commands/disable-ssl.js @@ -7,7 +7,6 @@ module.exports = function(mainPath) { var path = require('path'); - var fse = require('fs-extra'); var fs = require('fs'); var Property = require('deep-package-manager').Property_Instance; var ACMService = require('deep-package-manager').Provisioning_Service_ACMService; From 5d182294d0f0b77f11feb2f1c11590261662a677 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 11:45:42 +0200 Subject: [PATCH 091/133] Add new unit tests --- src/test/Server/Instance.spec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index ea09d356..1e750a19 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -2,9 +2,35 @@ import chai from 'chai'; import {Instance} from '../../lib/Server/Instance'; +import {PropertyObjectRequiredException} from '../../lib/Server/Exception/PropertyObjectRequiredException'; +import {Property_Instance as PropertyInstance} from 'deep-package-manager'; suite('Server/Instance', () => { + let server = null; + let propertyInstance = null; + test('Class Instance exists in Server/Instance', () => { chai.expect(Instance).to.be.an('function'); }); + + test('Check constructor throws exception for invalid property', () => { + let error = null; + + try { + server = new Instance(); + } catch(e) { + error = e; + } + + chai.expect(error).to.be.an.instanceOf(PropertyObjectRequiredException); + }); + + test('Check constructor sets values for valid property', () => { + propertyInstance = new PropertyInstance('./test/TestMaterials/Property2', 'deeploy.test.json'); + + server = new Instance(propertyInstance); + + chai.expect(propertyInstance).to.be.an.instanceOf(PropertyInstance); + chai.expect(server).to.be.an.instanceOf(Instance); + }); }); From 461126cd898c36c614d9ed5cbad8beaba6a3755d Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 3 Feb 2016 11:47:07 +0200 Subject: [PATCH 092/133] Remove pull/push deps commands --- src/bin/commands/deploy.js | 27 +----------- src/bin/commands/pull-deps.js | 81 ----------------------------------- src/bin/commands/push-deps.js | 78 --------------------------------- src/bin/manifest.js | 41 +----------------- 4 files changed, 2 insertions(+), 225 deletions(-) delete mode 100644 src/bin/commands/pull-deps.js delete mode 100644 src/bin/commands/push-deps.js diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 8668c57d..fe4323d0 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -26,7 +26,6 @@ module.exports = function(mainPath) { var dumpCodePath = this.opts.locate('dump-local').value; var cfgBucket = this.opts.locate('cfg-bucket').value; var appEnv = isProd ? 'prod' : this.opts.locate('env').value; - var hasToPullDeps = this.opts.locate('pull-deps').exists; var microservicesToDeploy = this.opts.locate('partial').value; if (mainPath.indexOf(path.sep) !== 0) { @@ -140,11 +139,7 @@ module.exports = function(mainPath) { } propertyInstance.runInitMsHooks(function() { - var deployCb = function() { - prepareProduction.bind(this)(propertyInstance.path, doDeploy.bind(this)); - }; - - hasToPullDeps ? pullDeps.bind(this)(deployCb) : deployCb.bind(this)(); + prepareProduction.bind(this)(propertyInstance.path, doDeploy.bind(this)); }.bind(this)); }.bind(this)); } @@ -290,26 +285,6 @@ module.exports = function(mainPath) { return typeof msIdentifiers === 'string' ? [msIdentifiers] : msIdentifiers; } - function pullDeps(cb) { - console.log('Resolving dependencies in ' + tmpPropertyPath); - - new Exec( - Bin.node, - this.scriptPath, - 'pull-deps', - tmpPropertyPath - ) - .avoidBufferOverflow() - .run(function(result) { - if (result.failed) { - console.error('Error while pulling dependencies in ' + tmpPropertyPath + ': ' + result.error); - this.exit(1); - } - - cb.bind(this)(); - }.bind(this)); - } - function dumpCode() { if (!dumpCodePath) { return; diff --git a/src/bin/commands/pull-deps.js b/src/bin/commands/pull-deps.js deleted file mode 100644 index ce003367..00000000 --- a/src/bin/commands/pull-deps.js +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env node -/** - * Created by AlexanderC on 6/19/15. - */ - -'use strict'; - -module.exports = function(mainPath) { - var aws = require('aws-sdk'); - var path = require('path'); - var fs = require('fs'); - var fse = require('fs-extra'); - var Manager = require('deep-package-manager').Dependencies_Manager; - var S3Driver = require('deep-package-manager').Dependencies_Driver_S3StdDriver; - var Config = require('deep-package-manager').Property_Config; - - var dryRun = this.opts.locate('dry-run').exists; - - var microservicesStack = []; - - var semicolonIndex = mainPath.lastIndexOf(':'); - if (-1 !== semicolonIndex) { - var microservicesRaw = mainPath.substr(semicolonIndex + 1); - - microservicesRaw.split(',').forEach(function(subPath) { - microservicesStack.push(subPath.trim()); - }); - - mainPath = mainPath.substr(0, semicolonIndex); - } - - if (mainPath.indexOf(path.sep) !== 0) { - mainPath = path.join(process.cwd(), mainPath); - } - - var configFile = path.join(mainPath, Config.DEFAULT_FILENAME); - var configExists = fs.existsSync(configFile); - - if (!configExists) { - console.error('Missing ' + Config.DEFAULT_FILENAME + ' configuration file in ' + mainPath); - this.exit(1); - } - - var config = fse.readJsonSync(configFile); - - if (!config.dependencies - || typeof config.dependencies.bucket === 'undefined') { - - console.error('Missing dependencies or bucket properties'); - this.exit(1); - } - - var s3Bucket = config.dependencies.bucket; - var s3Prefix = config.dependencies.prefix || ''; - - aws.config.update(config.dependencies.aws || config.aws); - - var driver = new S3Driver(aws, s3Bucket); - driver.basePath = mainPath; - driver.prefix = s3Prefix; - - var mg = new Manager(driver); - mg.driver.dryRun = dryRun; - - console.log( - 'Resolving dependencies from ' + mainPath + - ' using \'s3://' + s3Bucket + '/' + s3Prefix + ' \' repository' - ); - - if (microservicesStack.length > 0) { - console.log('---> ', microservicesStack); - - mg.pullBatch(microservicesStack, function() { - console.log('Done!'); - }); - } else { - mg.pull(function() { - console.log('Done!'); - }); - } -}; diff --git a/src/bin/commands/push-deps.js b/src/bin/commands/push-deps.js deleted file mode 100644 index ca8ac13d..00000000 --- a/src/bin/commands/push-deps.js +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env node -/** - * Created by AlexanderC on 6/19/15. - */ - -'use strict'; - -module.exports = function(mainPath) { - var aws = require('aws-sdk'); - var path = require('path'); - var fs = require('fs'); - var fse = require('fs-extra'); - var Manager = require('deep-package-manager').Dependencies_Manager; - var S3Driver = require('deep-package-manager').Dependencies_Driver_S3StdDriver; - var Config = require('deep-package-manager').Property_Config; - - var dryRun = this.opts.locate('dry-run').exists; - - var microservicesStack = []; - - var semicolonIndex = mainPath.lastIndexOf(':'); - if (-1 !== semicolonIndex) { - var microservicesRaw = mainPath.substr(semicolonIndex + 1); - - microservicesRaw.split(',').forEach(function(subPath) { - microservicesStack.push(subPath.trim()); - }); - - mainPath = mainPath.substr(0, semicolonIndex); - } - - if (mainPath.indexOf(path.sep) !== 0) { - mainPath = path.join(process.cwd(), mainPath); - } - - var configFile = path.join(mainPath, Config.DEFAULT_FILENAME); - var configExists = fs.existsSync(configFile); - - if (!configExists) { - console.error('Missing ' + Config.DEFAULT_FILENAME + ' configuration file in ' + mainPath); - this.exit(1); - } - - var config = fse.readJsonSync(configFile); - - if (!config.dependencies - || typeof config.dependencies.bucket === 'undefined') { - - console.error('Missing dependencies or bucket properties'); - this.exit(1); - } - - var s3Bucket = config.dependencies.bucket; - var s3Prefix = config.dependencies.prefix || ''; - - aws.config.update(config.dependencies.aws || config.aws); - - var driver = new S3Driver(aws, s3Bucket); - driver.basePath = mainPath; - driver.prefix = s3Prefix; - - var mg = new Manager(driver); - mg.driver.dryRun = dryRun; - - console.log('Uploading dependencies from ' + mainPath + ' into s3://' + s3Bucket + '/' + s3Prefix); - - if (microservicesStack.length > 0) { - console.log('---> ', microservicesStack); - - mg.pushBatch(microservicesStack, function() { - console.log('Done!'); - }); - } else { - mg.push(function() { - console.log('Done!'); - }); - } -}; diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 0aa0c07a..204407d8 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -117,11 +117,6 @@ module.exports = { description: 'Dump built web app locally into the specified directory', required: false, }, - 'pull-deps': { - alias: 'p', - description: 'Pull dependencies from the remote repository', - required: false, - }, partial: { alias: 'm', description: 'Partial deploy (one or several comma separated microservices identifiers)', @@ -305,40 +300,6 @@ module.exports = { required: true, }, }, - }, - 'pull-deps': { - example: 'deepify pull-deps path/to/web_app', - description: 'Pull web app microservices\' dependencies', - opts: { - 'dry-run': { - alias: 'd', - description: 'Work locally, without pulling dependencies from the remote repository', - required: false, - }, - }, - args: { - path: { - description: 'The path to the web app', - required: true, - }, - }, - }, - 'push-deps': { - example: 'deepify push-deps path/to/web_app', - description: 'Publish microservices from within the given web app', - opts: { - 'dry-run': { - alias: 'd', - description: 'Work locally, without pushing microservices to the remote repository', - required: false, - }, - }, - args: { - path: { - description: 'The path to the web app', - required: true, - }, - }, - }, + } }, }; From 72bfb3671f7046b4f1945ac2fa3001890fb99e04 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 3 Feb 2016 12:01:23 +0200 Subject: [PATCH 093/133] Fix operator precedence --- src/lib/Server/Instance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Server/Instance.js b/src/lib/Server/Instance.js index 8ac25cf4..f1c52128 100644 --- a/src/lib/Server/Instance.js +++ b/src/lib/Server/Instance.js @@ -29,7 +29,7 @@ export class Instance { * @param {Property} property */ constructor(property) { - if (!property instanceof Property) { + if (!(property instanceof Property)) { throw new PropertyObjectRequiredException(); } From c52965201e2567a3fdc50cae732f4d28018975dd Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 12:03:45 +0200 Subject: [PATCH 094/133] Add unit tests for Server constructor --- src/test/Server/Instance.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index 1e750a19..85b20d79 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -17,7 +17,7 @@ suite('Server/Instance', () => { let error = null; try { - server = new Instance(); + server = new Instance({}); } catch(e) { error = e; } From f25e7ee8e059c15f1277a2a576dd5a998fdc49a0 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 12:43:59 +0200 Subject: [PATCH 095/133] Add new unit tests for Hook --- src/test/Server/Hook.spec.js | 30 +++++++++++++++++++++++++++++ src/test/Server/Instance.spec.js | 33 ++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/test/Server/Hook.spec.js b/src/test/Server/Hook.spec.js index 4d228842..16d047fc 100644 --- a/src/test/Server/Hook.spec.js +++ b/src/test/Server/Hook.spec.js @@ -2,9 +2,39 @@ import chai from 'chai'; import {Hook} from '../../lib/Server/Hook'; +import {Instance} from '../../lib/Server/Instance'; +import {Property_Instance as PropertyInstance} from 'deep-package-manager'; suite('Server/Hook', () => { + let hook = null; + let server = null; + let propertyInstance = null; + test('Class Hook exists in Server/Hook', () => { chai.expect(Hook).to.be.an('function'); }); + + test('Check constructor sets correctly properties for valid property', () => { + propertyInstance = new PropertyInstance('./test/TestMaterials/Property2', 'deeploy.test.json'); + + server = new Instance(propertyInstance); + + hook = new Hook(propertyInstance); + + chai.expect(hook).to.be.an.instanceOf(Instance); + chai.expect(hook.server).to.be.an.instanceOf(Instance); + chai.expect(hook.server).to.be.equal(server); + }); + + test('Check BEFORE static getter', () => { + chai.expect(Hook.BEFORE).to.be.equal('before'); + }); + + test('Check AFTER static getter', () => { + chai.expect(Hook.AFTER).to.be.equal('after'); + }); + + test('Check FILE_NAME static getter', () => { + chai.expect(Hook.FILE_NAME).to.be.equal('hook.server.js'); + }); }); diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index 85b20d79..60422ad8 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -25,12 +25,41 @@ suite('Server/Instance', () => { chai.expect(error).to.be.an.instanceOf(PropertyObjectRequiredException); }); - test('Check constructor sets values for valid property', () => { + test('Check constructor sets correctly properties for valid property', () => { propertyInstance = new PropertyInstance('./test/TestMaterials/Property2', 'deeploy.test.json'); server = new Instance(propertyInstance); - chai.expect(propertyInstance).to.be.an.instanceOf(PropertyInstance); chai.expect(server).to.be.an.instanceOf(Instance); + chai.expect(server.property).to.be.an.instanceOf(PropertyInstance); + chai.expect(server.property).to.be.equal(propertyInstance); + chai.expect(server.logger).to.be.an('function'); + chai.expect(server.nativeServer).to.be.equal(null); + chai.expect(server.fs).to.be.equal(null); + chai.expect(server.host).to.be.equal(null); + chai.expect(server._localId).to.be.equal(0); + }); + + test('Check logger getter/setter', () => { + let logger = server.logger; + let newLogger = (...args) => { + console.debug(...args); + }; + + server.logger = newLogger; + chai.expect(server.logger).to.be.equal(newLogger); + + server.logger = logger; + chai.expect(server.logger).to.be.equal(logger); + }); + + test('Check localId getter postincrements _localId', () => { + let localId = server._localId; + let expectedResult = localId + 1; + + let actualResult = server.localId; + + chai.expect(actualResult).to.be.equal(localId); + chai.expect(server._localId).to.be.equal(expectedResult); }); }); From 982fbe17c5818f414858c2b3cf4320faca1db072 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 12:44:58 +0200 Subject: [PATCH 096/133] Add autogenerated tests --- src/test/Helpers/ValidationSchemasSync.spec.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/Helpers/ValidationSchemasSync.spec.js diff --git a/src/test/Helpers/ValidationSchemasSync.spec.js b/src/test/Helpers/ValidationSchemasSync.spec.js new file mode 100644 index 00000000..300057ff --- /dev/null +++ b/src/test/Helpers/ValidationSchemasSync.spec.js @@ -0,0 +1,13 @@ +// THIS TEST WAS GENERATED AUTOMATICALLY ON Wed Feb 03 2016 11:01:21 GMT+0200 (EET) + +'use strict'; + +import chai from 'chai'; +import {ValidationSchemasSync} from '../../lib/Helpers/ValidationSchemasSync'; + +// @todo: Add more advanced tests +suite('Helpers/ValidationSchemasSync', function() { + test('Class ValidationSchemasSync exists in Helpers/ValidationSchemasSync', () => { + chai.expect(ValidationSchemasSync).to.be.an('function'); + }); +}); From 3d73ab95b1e29ee50d9b239d6f559ce9886c7c46 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 12:54:34 +0200 Subject: [PATCH 097/133] Update unit test for Server --- src/test/Server/Hook.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/Server/Hook.spec.js b/src/test/Server/Hook.spec.js index 16d047fc..83e0179f 100644 --- a/src/test/Server/Hook.spec.js +++ b/src/test/Server/Hook.spec.js @@ -14,15 +14,15 @@ suite('Server/Hook', () => { chai.expect(Hook).to.be.an('function'); }); - test('Check constructor sets correctly properties for valid property', () => { + test('Check constructor sets correctly server', () => { propertyInstance = new PropertyInstance('./test/TestMaterials/Property2', 'deeploy.test.json'); server = new Instance(propertyInstance); - hook = new Hook(propertyInstance); + hook = new Hook(server); - chai.expect(hook).to.be.an.instanceOf(Instance); - chai.expect(hook.server).to.be.an.instanceOf(Instance); + chai.expect(hook, 'is an instance of Hook').to.be.an.instanceOf(Hook); + chai.expect(hook.server, 'server is an instance of Server').to.be.an.instanceOf(Instance); chai.expect(hook.server).to.be.equal(server); }); From 220ee3225924921d0f7bcc70c9bc54281ea9c51a Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 13:43:42 +0200 Subject: [PATCH 098/133] Add unit tests for Hook --- src/test/Server/Hook.spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/Server/Hook.spec.js b/src/test/Server/Hook.spec.js index 83e0179f..969bdfda 100644 --- a/src/test/Server/Hook.spec.js +++ b/src/test/Server/Hook.spec.js @@ -37,4 +37,11 @@ suite('Server/Hook', () => { test('Check FILE_NAME static getter', () => { chai.expect(Hook.FILE_NAME).to.be.equal('hook.server.js'); }); + + test('Check _createContext', () => { + chai.expect(hook._createContext('after').isAfter()).to.be.equal(true); + chai.expect(hook._createContext('after').isBefore()).to.be.equal(false); + chai.expect(hook._createContext('before').isAfter()).to.be.equal(false); + chai.expect(hook._createContext('before').isBefore()).to.be.equal(true); + }); }); From 059b683cd0b3db29cb9067a0a085b124a360c82a Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 17:15:21 +0200 Subject: [PATCH 099/133] Add unit tests for Server > Hook --- src/test/Server/Hook.spec.js | 43 +++++++++++++++++++++++++ src/test/Server/Instance.spec.js | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/src/test/Server/Hook.spec.js b/src/test/Server/Hook.spec.js index 969bdfda..36ca8f85 100644 --- a/src/test/Server/Hook.spec.js +++ b/src/test/Server/Hook.spec.js @@ -1,10 +1,14 @@ 'use strict'; import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import {Hook} from '../../lib/Server/Hook'; import {Instance} from '../../lib/Server/Instance'; import {Property_Instance as PropertyInstance} from 'deep-package-manager'; +chai.use(sinonChai); + suite('Server/Hook', () => { let hook = null; let server = null; @@ -44,4 +48,43 @@ suite('Server/Hook', () => { chai.expect(hook._createContext('before').isAfter()).to.be.equal(false); chai.expect(hook._createContext('before').isBefore()).to.be.equal(true); }); + + test('Check _run for no hook files', () => { + //arrange + let spyCallback = sinon.spy(); + let type = 'before'; + + //act + let actualResult = hook._run(propertyInstance.microservices[0], type, spyCallback); + + //assert + chai.expect(spyCallback).to.have.been.calledWithExactly(); + chai.expect(actualResult, 'is an instance of Hook').to.be.an.instanceOf(Hook); + }); + + //@todo - need to clarify why cb is not executed + test('Check run()', () => { + let spyCallback = sinon.spy(); + let type = 'before'; + + let actualResult = hook.run(type, spyCallback); + + chai.expect(actualResult, 'is an instance of Hook').to.be.an.instanceOf(Hook); + }); + + test('Check runBefore()', () => { + let spyCallback = sinon.spy(); + + let actualResult = hook.runBefore(spyCallback); + + chai.expect(actualResult, 'is an instance of Hook').to.be.an.instanceOf(Hook); + }); + + test('Check runAfter()', () => { + let spyCallback = sinon.spy(); + + let actualResult = hook.runAfter(spyCallback); + + chai.expect(actualResult, 'is an instance of Hook').to.be.an.instanceOf(Hook); + }); }); diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index 60422ad8..d1a48171 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -1,9 +1,15 @@ 'use strict'; import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import path from 'path'; import {Instance} from '../../lib/Server/Instance'; import {PropertyObjectRequiredException} from '../../lib/Server/Exception/PropertyObjectRequiredException'; import {Property_Instance as PropertyInstance} from 'deep-package-manager'; +import {Property_Frontend as Frontend} from 'deep-package-manager'; + +chai.use(sinonChai); suite('Server/Instance', () => { let server = null; @@ -62,4 +68,52 @@ suite('Server/Instance', () => { chai.expect(actualResult).to.be.equal(localId); chai.expect(server._localId).to.be.equal(expectedResult); }); + + test('Check _setup()', () => { + server._setup(); + + chai.expect(server._rootMicroservice).to.have.all.keys('frontend', 'identifier', 'lambdas', 'path'); + chai.expect(server._defaultFrontendConfig).to.be.an('object'); + }); + + test('Check buildPath > _populateBuildConfig()', () => { + let error = null; + + try { + server.buildPath = path.join(__dirname, '../TestMaterials'); + } catch (e) { + error = e; + } + + console.log('error buildPath: ', error); + }); + + test('Check running returns false', () => { + + chai.expect(server.running).to.equal(false); + }); + + test('Check stop() when !running', () => { + let spyCallback = sinon.spy(); + + let actualResult = server.stop(spyCallback); + + chai.expect(actualResult, 'is an instance of Server').to.be.an.instanceOf(Instance); + chai.expect(spyCallback).to.have.been.calledWithExactly(); + }); + + test('Check LAMBDA_URI static getter', () => { + chai.expect(Instance.LAMBDA_URI).to.equal('/_/lambda'); + }); + + test('Check LAMBDA_ASYNC_URI static getter', () => { + chai.expect(Instance.LAMBDA_ASYNC_URI).to.equal('/_/lambda-async'); + }); + + test('Check _kernelMock getter', () => { + let actualResult = server._kernelMock; + + chai.expect(actualResult).to.be.an('object'); + chai.expect(actualResult).to.have.all.keys('config', 'microservice'); + }); }); From fd966f866f3878a58d27b6cdf3ec734e1fbf9e3e Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 17:20:23 +0200 Subject: [PATCH 100/133] Add _config.json --- src/test/TestMaterials/_www/_config.json | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/test/TestMaterials/_www/_config.json diff --git a/src/test/TestMaterials/_www/_config.json b/src/test/TestMaterials/_www/_config.json new file mode 100644 index 00000000..a71c310b --- /dev/null +++ b/src/test/TestMaterials/_www/_config.json @@ -0,0 +1,113 @@ +{ + "env": "dev", + "deployId": "5h56a8765e6159cdda87a4d11f710b46", + "awsRegion": "us-west-2", + "models": [ + { + "Todo": { + "Title": "string", + "Completed": "boolean", + "Id": "timeUUID" + } + } + ], + "identityPoolId": "us-east-1:5hgj4567-2ba5-4af8-b89d-d46e7496e9a7", + "identityProviders": { + "www.amazon.com": "amzn1.application.3b5k2jb53252352kjh5b23kj5hb" + }, + "microservices": { + "deep.ng.root": { + "isRoot": true, + "parameters": {}, + "resources": {} + }, + "deep.ng.todo": { + "isRoot": false, + "parameters": {}, + "resources": { + "todo": { + "create": { + "type": "lambda", + "methods": [ + "POST" + ], + "forceUserIdentity": true, + "region": "us-west-2", + "source": { + "api": "https://aass3gf5kd.execute-api.us-west-2.amazonaws.com/dev/deep-ng-todo/todo/create", + "original": "arn:aws:lambda:us-west-2:123456789123:function:DeepDevTodoCreate12354e1234ew" + } + }, + "retrieve": { + "type": "lambda", + "methods": [ + "GET" + ], + "forceUserIdentity": true, + "region": "us-west-2", + "source": { + "api": "https://aass3gf5kd.execute-api.us-west-2.amazonaws.com/dev/deep-ng-todo/todo/retrieve", + "original": "arn:aws:lambda:us-west-2:123456789123:function:DeepDevTodoRetrieve12354e1234ew" + } + }, + "delete": { + "type": "lambda", + "methods": [ + "DELETE" + ], + "forceUserIdentity": true, + "region": "us-west-2", + "source": { + "api": "https://aass3gf5kd.execute-api.us-west-2.amazonaws.com/dev/deep-ng-todo/todo/delete", + "original": "arn:aws:lambda:us-west-2:123456789123:function:DeepDevTodoDelete12354e1234ew" + } + }, + "deleteCompleted": { + "type": "lambda", + "methods": [ + "POST" + ], + "forceUserIdentity": true, + "region": "us-west-2", + "source": { + "api": "https://aass3gf5kd.execute-api.us-west-2.amazonaws.com/dev/deep-ng-todo/todo/deleteCompleted", + "original": "arn:aws:lambda:us-west-2:123456789123:function:DeepDevTodoDeleteCompleted12354e1234ew" + } + }, + "update": { + "type": "lambda", + "methods": [ + "PUT" + ], + "forceUserIdentity": true, + "region": "us-west-2", + "source": { + "api": "https://aass3gf5kd.execute-api.us-west-2.amazonaws.com/dev/deep-ng-todo/todo/update", + "original": "arn:aws:lambda:us-west-2:123456789123:function:DeepDevTodoUpdate12354e1234ew" + } + }, + "markAll": { + "type": "lambda", + "methods": [ + "POST" + ], + "forceUserIdentity": true, + "region": "us-west-2", + "source": { + "api": "https://aass3gf5kd.execute-api.us-west-2.amazonaws.com/dev/deep-ng-todo/todo/markAll", + "original": "arn:aws:lambda:us-west-2:123456789123:function:DeepDevTodoMarkAll12354e1234ew" + } + } + } + } + } + }, + "globals": { + "userProviderEndpoint": "@deep.auth:user:retrieve", + "security": { + "identityProviders": { + "www.amazon.com": "amzn1.application.3e4r2jb12345678kjh5b23kj5hb" + } + } + } +} \ No newline at end of file From ca90f43afb4b387a513f4ec4c3b172e267e0f219 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 3 Feb 2016 18:38:21 +0200 Subject: [PATCH 101/133] Add additional microservice to test materials --- src/test/Server/Instance.spec.js | 26 ++++++++++++++ .../Property2/Microservice2/.parameters.json | 4 +++ .../Microservice2/Backend/resources.json | 12 +++++++ .../Backend/src/TestResource/Test/Handler.es6 | 22 ++++++++++++ .../src/TestResource/Test/bootstrap.es6 | 14 ++++++++ .../src/TestResource/Test/package.json | 34 +++++++++++++++++++ .../Microservice2/Data/Models/model.json | 11 ++++++ .../Property2/Microservice2/deepkg.json | 21 ++++++++++++ 8 files changed, 144 insertions(+) create mode 100644 src/test/TestMaterials/Property2/Microservice2/.parameters.json create mode 100644 src/test/TestMaterials/Property2/Microservice2/Backend/resources.json create mode 100644 src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/Handler.es6 create mode 100644 src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/bootstrap.es6 create mode 100644 src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/package.json create mode 100644 src/test/TestMaterials/Property2/Microservice2/Data/Models/model.json create mode 100644 src/test/TestMaterials/Property2/Microservice2/deepkg.json diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index d1a48171..369115ce 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -59,6 +59,19 @@ suite('Server/Instance', () => { chai.expect(server.logger).to.be.equal(logger); }); + test('Check profiling getter/setter', () => { + let profiling = server.profiling; + + server.profiling = true; + chai.expect(server.profiling).to.be.equal(true); + + server.profiling = false; + chai.expect(server.profiling).to.be.equal(false); + + server.profiling = profiling; + chai.expect(server.profiling).to.be.equal(profiling); + }); + test('Check localId getter postincrements _localId', () => { let localId = server._localId; let expectedResult = localId + 1; @@ -116,4 +129,17 @@ suite('Server/Instance', () => { chai.expect(actualResult).to.be.an('object'); chai.expect(actualResult).to.have.all.keys('config', 'microservice'); }); + + test('Check _resolveMicroservice', () => { + let uri = 'microservice2/p/a/t/h'; + + let actualResult = server._resolveMicroservice(uri); + + chai.expect(actualResult).to.contains('Microservice2'); + }); + + //@todo - need to rework + test('Check listen()', () => { + let actualResult = server.listen(); + }); }); diff --git a/src/test/TestMaterials/Property2/Microservice2/.parameters.json b/src/test/TestMaterials/Property2/Microservice2/.parameters.json new file mode 100644 index 00000000..e170716d --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice2/.parameters.json @@ -0,0 +1,4 @@ +{ + "backend": {}, + "frontend": {} +} \ No newline at end of file diff --git a/src/test/TestMaterials/Property2/Microservice2/Backend/resources.json b/src/test/TestMaterials/Property2/Microservice2/Backend/resources.json new file mode 100644 index 00000000..f8522da5 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice2/Backend/resources.json @@ -0,0 +1,12 @@ +{ + "test-resource" : { + "test": { + "description": "Just a test resource", + "type": "lambda", + "methods": [ + "POST" + ], + "source": "src/TestResource/Test" + } + } +} \ No newline at end of file diff --git a/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/Handler.es6 b/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/Handler.es6 new file mode 100644 index 00000000..70099276 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/Handler.es6 @@ -0,0 +1,22 @@ +'use strict'; + +import DeepFramework from 'deep-framework'; + +/** + * Sample lambda runtime + */ +export default class extends DeepFramework.Core.AWS.Lambda.Runtime { + /** + * @param {Array} args + */ + constructor(...args) { + super(...args); + } + + /** + * Handle lambda execution + */ + handle(request) { + this.createResponse(request).send(); + } +} diff --git a/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/bootstrap.es6 b/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/bootstrap.es6 new file mode 100644 index 00000000..9b842547 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/bootstrap.es6 @@ -0,0 +1,14 @@ +'use strict'; + +if (typeof Symbol === 'undefined') { + require('babel-core/polyfill'); +} + +import DeepFramework from 'deep-framework'; +import Handler from './Handler'; + +exports.handler = function(event, context) { + DeepFramework.Kernel.loadFromFile('_config.json', function(deepKernel) { + new Handler(deepKernel).run(event, context); + }); +}; diff --git a/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/package.json b/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/package.json new file mode 100644 index 00000000..2787d760 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice2/Backend/src/TestResource/Test/package.json @@ -0,0 +1,34 @@ +{ + "name": "test-resource-test", + "version": "0.0.1", + "description": "Test resource", + "author": "Mitoc Group ", + "contributors": [ + { + "name": "Stefan Hariton", + "email": "shariton@mitocroup.com" + } + ], + "bugs": { + "url": "https://github.com/MitocGroup/deep-management/issues" + }, + "keywords": [ + "DEEP", + "Stripe", + "Digital Enterprise End-To-End Platform", + "Deep Core Libraries", + "Billing" + ], + "dependencies": { + "deep-framework": "*", + "babel-core": "5.5.*" + }, + "devDependencies": { + }, + "scripts": { + "postinstall": "BABEL_ENV=production babel -x \".es6\" ./ --out-dir ./" + }, + "preferGlobal": false, + "private": true, + "analyze": true +} diff --git a/src/test/TestMaterials/Property2/Microservice2/Data/Models/model.json b/src/test/TestMaterials/Property2/Microservice2/Data/Models/model.json new file mode 100644 index 00000000..e0b99814 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice2/Data/Models/model.json @@ -0,0 +1,11 @@ +{ + "UserId": "string", + "AccountId": "string", + "URL": "string", + "Metadata": "map", + "Size": { + "Width": "number", + "Height": "number" + }, + "Tags": "mapSet" +} \ No newline at end of file diff --git a/src/test/TestMaterials/Property2/Microservice2/deepkg.json b/src/test/TestMaterials/Property2/Microservice2/deepkg.json new file mode 100644 index 00000000..08a106a1 --- /dev/null +++ b/src/test/TestMaterials/Property2/Microservice2/deepkg.json @@ -0,0 +1,21 @@ +{ + "identifier": "microservice2", + "name": "microservice2", + "description": "Microservice used for testing purposes", + "version": "0.0.1", + "propertyRoot": false, + "author": { + "name": "Mitoc Group", + "email": "hello@mitocgroup.com", + "website": "http://www.mitocgroup.com" + }, + "contributors": [ + { + "name": "Vitali Cernomschi", + "email": "vcernomschi@mitocgroup.com", + "website": "http://www.mitocgroup.com" + } + ], + "dependencies": { + } +} \ No newline at end of file From 933b0b4427848f717427a2ba435c5b188cc7aa1c Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Thu, 4 Feb 2016 16:23:02 +0200 Subject: [PATCH 102/133] Add unit tests for Help constructors --- src/test/Server/Instance.spec.js | 11 ++++++++++- src/test/Terminal/Argument.spec.js | 10 ++++++++++ src/test/Terminal/Arguments.spec.js | 10 ++++++++++ src/test/Terminal/Help.spec.js | 14 ++++++++++++++ src/test/Terminal/Option.spec.js | 14 ++++++++++++++ src/test/Terminal/Program.spec.js | 14 ++++++++++++++ 6 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/test/Server/Instance.spec.js b/src/test/Server/Instance.spec.js index 369115ce..df9bc91c 100644 --- a/src/test/Server/Instance.spec.js +++ b/src/test/Server/Instance.spec.js @@ -102,7 +102,6 @@ suite('Server/Instance', () => { }); test('Check running returns false', () => { - chai.expect(server.running).to.equal(false); }); @@ -142,4 +141,14 @@ suite('Server/Instance', () => { test('Check listen()', () => { let actualResult = server.listen(); }); + + //@todo - need to rework + //test('Check _runLambda()', () => { + // let response = {}; + // let lambdaConfig = {}; + // let payload = {}; + // let asyncMode = false; + // + // let actualResult = server._runLambda(response, lambdaConfig, payload, asyncMode); + //}); }); diff --git a/src/test/Terminal/Argument.spec.js b/src/test/Terminal/Argument.spec.js index 6615a79d..42ddb5d8 100644 --- a/src/test/Terminal/Argument.spec.js +++ b/src/test/Terminal/Argument.spec.js @@ -4,7 +4,17 @@ import chai from 'chai'; import {Argument} from '../../lib/Terminal/Argument'; suite('Terminal/Argument', () => { + let name = 'server'; + let argument = null; + test('Class Argument exists in Terminal/Argument', () => { chai.expect(Argument).to.be.an('function'); }); + + test('Check constructor sets correctly values by default', () => { + argument = new Argument(name); + + chai.expect(argument, 'is an instance of Argument').to.be.an.instanceOf(Argument); + chai.expect(argument.name).to.be.equal(name); + }); }); diff --git a/src/test/Terminal/Arguments.spec.js b/src/test/Terminal/Arguments.spec.js index 9ba5b35c..a08c3d10 100644 --- a/src/test/Terminal/Arguments.spec.js +++ b/src/test/Terminal/Arguments.spec.js @@ -4,7 +4,17 @@ import chai from 'chai'; import {Arguments} from '../../lib/Terminal/Arguments'; suite('Terminal/Arguments', () => { + let argumentsInstance = null; + test('Class Arguments exists in Terminal/Arguments', () => { chai.expect(Arguments).to.be.an('function'); }); + + test('Check constructor sets correctly values by default', () => { + argumentsInstance = new Arguments(); + + chai.expect(argumentsInstance, 'is an instance of Argument').to.be.an.instanceOf(Arguments); + chai.expect(argumentsInstance.list()).to.be.eql([]); + chai.expect(argumentsInstance.listUnmanaged()).to.be.eql([]); + }); }); diff --git a/src/test/Terminal/Help.spec.js b/src/test/Terminal/Help.spec.js index 9f641e14..18ffd6eb 100644 --- a/src/test/Terminal/Help.spec.js +++ b/src/test/Terminal/Help.spec.js @@ -2,9 +2,23 @@ import chai from 'chai'; import {Help} from '../../lib/Terminal/Help'; +import {Program} from '../../lib/Terminal/Program'; suite('Terminal/Help', () => { + + let program = null; + let help = null; + test('Class Help exists in Terminal/Help', () => { chai.expect(Help).to.be.an('function'); }); + + test('Check constructor sets correctly values by default', () => { + program = new Program(); + help = new Help(program) + + chai.expect(help, 'is an instance of Help').to.be.an.instanceOf(Help); + chai.expect(help.program, 'is an instance of Program').to.be.an.instanceOf(Program); + chai.expect(help.program).to.be.eql(program); + }); }); diff --git a/src/test/Terminal/Option.spec.js b/src/test/Terminal/Option.spec.js index b0cb5d45..fe29dfae 100644 --- a/src/test/Terminal/Option.spec.js +++ b/src/test/Terminal/Option.spec.js @@ -4,7 +4,21 @@ import chai from 'chai'; import {Option} from '../../lib/Terminal/Option'; suite('Terminal/Option', () => { + let option = null; + let name = 'server' + test('Class Option exists in Terminal/Option', () => { chai.expect(Option).to.be.an('function'); }); + + test('Check constructor sets correctly values by default', () => { + option = new Option(name); + + chai.expect(option, 'is an instance of Option').to.be.an.instanceOf(Option); + chai.expect(option.name).to.be.equal(name); + chai.expect(option.description).to.be.equal(null); + chai.expect(option.alias).to.be.equal(null); + chai.expect(option.required).to.be.equal(false); + chai.expect(option.hidden).to.be.equal(false); + }); }); diff --git a/src/test/Terminal/Program.spec.js b/src/test/Terminal/Program.spec.js index bc227b39..0bf2fbe1 100644 --- a/src/test/Terminal/Program.spec.js +++ b/src/test/Terminal/Program.spec.js @@ -4,7 +4,21 @@ import chai from 'chai'; import {Program} from '../../lib/Terminal/Program'; suite('Terminal/Program', () => { + let program = null; + test('Class Program exists in Terminal/Program', () => { chai.expect(Program).to.be.an('function'); }); + + test('Check constructor sets correctly values by default', () => { + program = new Program(); + + chai.expect(program, 'is an instance of Program').to.be.an.instanceOf(Program); + chai.expect(program.name).to.be.equal(null); + chai.expect(program.version).to.be.equal(null); + chai.expect(program.description).to.be.equal(null); + chai.expect(program.example).to.be.equal(null); + chai.expect(program.commands).to.be.eql([]); + chai.expect(program.commands).to.be.eql([]); + }); }); From 90b89ef32367217f9d457d8d837519fed5a4c0b5 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Thu, 4 Feb 2016 16:32:26 +0200 Subject: [PATCH 103/133] Fix istanceof operator --- src/lib/Terminal/Arguments.js | 4 ++-- src/lib/Terminal/Exception/MissingArgumentException.js | 2 +- src/lib/Terminal/Exception/MissingOptionException.js | 2 +- src/lib/Terminal/Help.js | 2 +- src/lib/Terminal/Options.js | 4 ++-- src/lib/Terminal/Program.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/Terminal/Arguments.js b/src/lib/Terminal/Arguments.js index 95507180..37205968 100644 --- a/src/lib/Terminal/Arguments.js +++ b/src/lib/Terminal/Arguments.js @@ -39,7 +39,7 @@ export class Arguments { * @returns {Arguments} */ merge(sibling) { - if (!sibling instanceof Arguments) { + if (!(sibling instanceof Arguments)) { throw new ArgumentsObjectRequiredException(); } @@ -141,7 +141,7 @@ export class Arguments { * @returns {Arguments} */ add(argument) { - if (!argument instanceof Argument) { + if (!(argument instanceof Argument)) { throw new ArgumentObjectRequiredException(); } diff --git a/src/lib/Terminal/Exception/MissingArgumentException.js b/src/lib/Terminal/Exception/MissingArgumentException.js index 0b958e79..cef24b8a 100644 --- a/src/lib/Terminal/Exception/MissingArgumentException.js +++ b/src/lib/Terminal/Exception/MissingArgumentException.js @@ -13,7 +13,7 @@ export class MissingArgumentException extends ValidationException { * @param {Argument} argument */ constructor(argument) { - if (!argument instanceof Argument) { + if (!(argument instanceof Argument)) { throw new ArgumentObjectRequiredException(); } diff --git a/src/lib/Terminal/Exception/MissingOptionException.js b/src/lib/Terminal/Exception/MissingOptionException.js index 4c37723a..dfec3aea 100644 --- a/src/lib/Terminal/Exception/MissingOptionException.js +++ b/src/lib/Terminal/Exception/MissingOptionException.js @@ -13,7 +13,7 @@ export class MissingOptionException extends ValidationException { * @param {Option} option */ constructor(option) { - if (!option instanceof Option) { + if (!(option instanceof Option)) { throw new OptionObjectRequiredException(); } diff --git a/src/lib/Terminal/Help.js b/src/lib/Terminal/Help.js index e35491c5..3b91ee82 100644 --- a/src/lib/Terminal/Help.js +++ b/src/lib/Terminal/Help.js @@ -15,7 +15,7 @@ export class Help { constructor(program) { this._program = program; - if (!program instanceof Program) { + if (!(program instanceof Program)) { throw new ProgramInstanceRequiredException(); } } diff --git a/src/lib/Terminal/Options.js b/src/lib/Terminal/Options.js index bffc142f..93851fd4 100644 --- a/src/lib/Terminal/Options.js +++ b/src/lib/Terminal/Options.js @@ -38,7 +38,7 @@ export class Options { * @returns {Options} */ merge(sibling) { - if (!sibling instanceof Options) { + if (!(sibling instanceof Options)) { throw new OptionsObjectRequiredException(); } @@ -119,7 +119,7 @@ export class Options { * @returns {Options} */ add(option) { - if (!option instanceof Option) { + if (!(option instanceof Option)) { throw new OptionObjectRequiredException(); } diff --git a/src/lib/Terminal/Program.js b/src/lib/Terminal/Program.js index 41092e59..f702ccd9 100644 --- a/src/lib/Terminal/Program.js +++ b/src/lib/Terminal/Program.js @@ -299,7 +299,7 @@ export class Program { * @returns {Program} */ addCommand(subProgram) { - if (!subProgram instanceof Program) { + if (!(subProgram instanceof Program)) { throw new ProgramInstanceRequiredException(); } From f39b4334e2381817c69b567ddbf619d69758fed5 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Thu, 4 Feb 2016 18:07:22 +0200 Subject: [PATCH 104/133] Add unit tests for Argument and Arguments --- src/lib/Terminal/Arguments.js | 4 +- .../Exception/MissingArgumentException.js | 2 +- .../Exception/MissingOptionException.js | 2 +- src/lib/Terminal/Help.js | 2 +- src/lib/Terminal/Options.js | 4 +- src/lib/Terminal/Program.js | 2 +- src/test/Terminal/Argument.spec.js | 50 +++++++++++++++++++ src/test/Terminal/Arguments.spec.js | 30 +++++++++++ src/test/Terminal/Prompt.spec.js | 10 ++++ 9 files changed, 98 insertions(+), 8 deletions(-) diff --git a/src/lib/Terminal/Arguments.js b/src/lib/Terminal/Arguments.js index 95507180..37205968 100644 --- a/src/lib/Terminal/Arguments.js +++ b/src/lib/Terminal/Arguments.js @@ -39,7 +39,7 @@ export class Arguments { * @returns {Arguments} */ merge(sibling) { - if (!sibling instanceof Arguments) { + if (!(sibling instanceof Arguments)) { throw new ArgumentsObjectRequiredException(); } @@ -141,7 +141,7 @@ export class Arguments { * @returns {Arguments} */ add(argument) { - if (!argument instanceof Argument) { + if (!(argument instanceof Argument)) { throw new ArgumentObjectRequiredException(); } diff --git a/src/lib/Terminal/Exception/MissingArgumentException.js b/src/lib/Terminal/Exception/MissingArgumentException.js index 0b958e79..cef24b8a 100644 --- a/src/lib/Terminal/Exception/MissingArgumentException.js +++ b/src/lib/Terminal/Exception/MissingArgumentException.js @@ -13,7 +13,7 @@ export class MissingArgumentException extends ValidationException { * @param {Argument} argument */ constructor(argument) { - if (!argument instanceof Argument) { + if (!(argument instanceof Argument)) { throw new ArgumentObjectRequiredException(); } diff --git a/src/lib/Terminal/Exception/MissingOptionException.js b/src/lib/Terminal/Exception/MissingOptionException.js index 4c37723a..dfec3aea 100644 --- a/src/lib/Terminal/Exception/MissingOptionException.js +++ b/src/lib/Terminal/Exception/MissingOptionException.js @@ -13,7 +13,7 @@ export class MissingOptionException extends ValidationException { * @param {Option} option */ constructor(option) { - if (!option instanceof Option) { + if (!(option instanceof Option)) { throw new OptionObjectRequiredException(); } diff --git a/src/lib/Terminal/Help.js b/src/lib/Terminal/Help.js index e35491c5..3b91ee82 100644 --- a/src/lib/Terminal/Help.js +++ b/src/lib/Terminal/Help.js @@ -15,7 +15,7 @@ export class Help { constructor(program) { this._program = program; - if (!program instanceof Program) { + if (!(program instanceof Program)) { throw new ProgramInstanceRequiredException(); } } diff --git a/src/lib/Terminal/Options.js b/src/lib/Terminal/Options.js index bffc142f..93851fd4 100644 --- a/src/lib/Terminal/Options.js +++ b/src/lib/Terminal/Options.js @@ -38,7 +38,7 @@ export class Options { * @returns {Options} */ merge(sibling) { - if (!sibling instanceof Options) { + if (!(sibling instanceof Options)) { throw new OptionsObjectRequiredException(); } @@ -119,7 +119,7 @@ export class Options { * @returns {Options} */ add(option) { - if (!option instanceof Option) { + if (!(option instanceof Option)) { throw new OptionObjectRequiredException(); } diff --git a/src/lib/Terminal/Program.js b/src/lib/Terminal/Program.js index 41092e59..f702ccd9 100644 --- a/src/lib/Terminal/Program.js +++ b/src/lib/Terminal/Program.js @@ -299,7 +299,7 @@ export class Program { * @returns {Program} */ addCommand(subProgram) { - if (!subProgram instanceof Program) { + if (!(subProgram instanceof Program)) { throw new ProgramInstanceRequiredException(); } diff --git a/src/test/Terminal/Argument.spec.js b/src/test/Terminal/Argument.spec.js index 42ddb5d8..1675b2ff 100644 --- a/src/test/Terminal/Argument.spec.js +++ b/src/test/Terminal/Argument.spec.js @@ -16,5 +16,55 @@ suite('Terminal/Argument', () => { chai.expect(argument, 'is an instance of Argument').to.be.an.instanceOf(Argument); chai.expect(argument.name).to.be.equal(name); + chai.expect(argument.description).to.be.equal(null); + chai.expect(argument.required).to.be.equal(false); + chai.expect(argument.hidden).to.be.equal(false); + chai.expect(argument.exists).to.be.equal(false); + chai.expect(argument.value).to.be.equal(undefined); + }); + + test('Check _matchNonOption() returns false', () => { + let actualResult = Argument._matchNonOption('-testArgument'); + + chai.expect(actualResult).to.be.equal(false); + }); + + test('Check _matchNonOption() returns true', () => { + let actualResult = Argument._matchNonOption('testArgument'); + + chai.expect(actualResult).to.be.equal(true); + }); + + test('Check collect()', () => { + let actualResult = argument.collect(['argumentHere']); + + chai.expect(actualResult).to.be.an.instanceOf(Argument); + chai.expect(actualResult.value).to.be.equal('argumentHere'); + }); + + test('Check hidden setter/getter', () => { + let hidden = argument.hidden; + + argument.hidden = true; + chai.expect(argument.hidden).to.be.equal(true); + + argument.hidden = false; + chai.expect(argument.hidden).to.be.equal(false); + + argument.hidden = hidden; + chai.expect(argument.hidden).to.be.equal(hidden); + }); + + test('Check required setter/getter', () => { + let required = argument.required; + + argument.required = true; + chai.expect(argument.required).to.be.equal(true); + + argument.required = false; + chai.expect(argument.required).to.be.equal(false); + + argument.required = required; + chai.expect(argument.required).to.be.equal(required); }); }); diff --git a/src/test/Terminal/Arguments.spec.js b/src/test/Terminal/Arguments.spec.js index a08c3d10..02c5c514 100644 --- a/src/test/Terminal/Arguments.spec.js +++ b/src/test/Terminal/Arguments.spec.js @@ -2,9 +2,13 @@ import chai from 'chai'; import {Arguments} from '../../lib/Terminal/Arguments'; +import {Argument} from '../../lib/Terminal/Argument'; +import {ArgumentObjectRequiredException} from '../../lib/Terminal/Exception/ArgumentObjectRequiredException'; suite('Terminal/Arguments', () => { + let name = 'server'; let argumentsInstance = null; + let argument = new Argument(name); test('Class Arguments exists in Terminal/Arguments', () => { chai.expect(Arguments).to.be.an('function'); @@ -17,4 +21,30 @@ suite('Terminal/Arguments', () => { chai.expect(argumentsInstance.list()).to.be.eql([]); chai.expect(argumentsInstance.listUnmanaged()).to.be.eql([]); }); + + test('Check add() throws ArgumentObjectRequiredException', () => { + let error = null; + + try { + argumentsInstance.add({}); + } catch(e) { + error = e; + } + + chai.expect( + error, 'is an instance of ArgumentObjectRequiredException' + ).to.be.an.instanceOf(ArgumentObjectRequiredException); + chai.expect(argumentsInstance.list()).to.be.eql([]); + }); + + test('Check add()', () => { + let actualResult = argumentsInstance.add(argument); + + chai.expect(actualResult).to.be.an.instanceOf(Arguments); + chai.expect(argumentsInstance.list()[0]).to.be.an.instanceOf(Argument); + }); + + test('Check hasUnmanaged() returns false', () => { + chai.expect(argumentsInstance.hasUnmanaged).to.be.equal(false); + }); }); diff --git a/src/test/Terminal/Prompt.spec.js b/src/test/Terminal/Prompt.spec.js index ede27483..b3c6e3ae 100644 --- a/src/test/Terminal/Prompt.spec.js +++ b/src/test/Terminal/Prompt.spec.js @@ -2,9 +2,19 @@ import chai from 'chai'; import {Prompt} from '../../lib/Terminal/Prompt'; +import {Helpers_Terminal_Prompt as MainPrompt} from 'deep-package-manager'; suite('Terminal/Prompt', function() { + let prompt = new Prompt(); + test('Class Prompt exists in Terminal/Prompt', function() { chai.expect(typeof Prompt).to.equal('function'); }); + + test('Check constructor sets correctly values by default', () => { + prompt = new Prompt(); + + chai.expect(prompt, 'is an instance of Prompt').to.be.an.instanceOf(Prompt); + chai.expect(prompt, 'is an instance of MainPrompt').to.be.an.instanceOf(MainPrompt); + }); }); From d8a08bda480fd89b7cc075ab7d0a832b96f51047 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Thu, 4 Feb 2016 19:12:52 +0200 Subject: [PATCH 105/133] Add unit test for listValues --- src/test/Terminal/Arguments.spec.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/Terminal/Arguments.spec.js b/src/test/Terminal/Arguments.spec.js index 02c5c514..6b6d3531 100644 --- a/src/test/Terminal/Arguments.spec.js +++ b/src/test/Terminal/Arguments.spec.js @@ -39,11 +39,18 @@ suite('Terminal/Arguments', () => { test('Check add()', () => { let actualResult = argumentsInstance.add(argument); - chai.expect(actualResult).to.be.an.instanceOf(Arguments); chai.expect(argumentsInstance.list()[0]).to.be.an.instanceOf(Argument); }); + test('Check listValues() for !includeUnmanaged', () => { + argument.collect(['logLevel=debug']); + + let actualResult = argumentsInstance.listValues(false); + + chai.expect(actualResult[0]).to.be.equal(argument.value); + }); + test('Check hasUnmanaged() returns false', () => { chai.expect(argumentsInstance.hasUnmanaged).to.be.equal(false); }); From 9917c7a7983b60f8e64ab917aff5efa728e7a6e0 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 5 Feb 2016 10:13:29 +0200 Subject: [PATCH 106/133] Add unit tests for Help --- src/test/Terminal/Arguments.spec.js | 124 +++++++++++++++++++++++++++- src/test/Terminal/Help.spec.js | 74 ++++++++++++++++- src/test/Terminal/Program.spec.js | 30 +++++++ 3 files changed, 225 insertions(+), 3 deletions(-) diff --git a/src/test/Terminal/Arguments.spec.js b/src/test/Terminal/Arguments.spec.js index 6b6d3531..c8d0627c 100644 --- a/src/test/Terminal/Arguments.spec.js +++ b/src/test/Terminal/Arguments.spec.js @@ -4,6 +4,8 @@ import chai from 'chai'; import {Arguments} from '../../lib/Terminal/Arguments'; import {Argument} from '../../lib/Terminal/Argument'; import {ArgumentObjectRequiredException} from '../../lib/Terminal/Exception/ArgumentObjectRequiredException'; +import {ArgumentsObjectRequiredException} from '../../lib/Terminal/Exception/ArgumentsObjectRequiredException'; +import {MissingArgumentException} from '../../lib/Terminal/Exception/MissingArgumentException'; suite('Terminal/Arguments', () => { let name = 'server'; @@ -27,7 +29,7 @@ suite('Terminal/Arguments', () => { try { argumentsInstance.add({}); - } catch(e) { + } catch (e) { error = e; } @@ -39,8 +41,23 @@ suite('Terminal/Arguments', () => { test('Check add()', () => { let actualResult = argumentsInstance.add(argument); + chai.expect(actualResult).to.be.an.instanceOf(Arguments); chai.expect(argumentsInstance.list()[0]).to.be.an.instanceOf(Argument); + chai.expect(argumentsInstance.list()[0].name).to.be.equal(name); + }); + + test('Check locate() returns argument by name', () => { + let actualResult = argumentsInstance.locate(name); + + chai.expect(actualResult).to.be.an.instanceOf(Argument); + chai.expect(actualResult).to.be.equal(argument); + }); + + test('Check locate() returns null', () => { + let actualResult = argumentsInstance.locate('non-existing name'); + + chai.expect(actualResult).to.be.equal(null); }); test('Check listValues() for !includeUnmanaged', () => { @@ -54,4 +71,109 @@ suite('Terminal/Arguments', () => { test('Check hasUnmanaged() returns false', () => { chai.expect(argumentsInstance.hasUnmanaged).to.be.equal(false); }); + + test('Check remove()', () => { + argumentsInstance.remove(name); + + chai.expect(argumentsInstance.list()).to.be.eql([]); + }); + + test('Check create()', () => { + name = 'deploy'; + let actualResult = argumentsInstance.create(name); + + chai.expect(actualResult).to.be.an.instanceOf(Arguments); + chai.expect(argumentsInstance.list()[0]).to.be.an.instanceOf(Argument); + chai.expect(argumentsInstance.list()[0].name).to.be.equal(name); + }); + + test('Check merge()', () => { + let toMergeName = 'install'; + let sibling = new Arguments(toMergeName); + sibling.create(toMergeName); + + let actualResult = argumentsInstance.merge(sibling); + + chai.expect(actualResult).to.be.an.instanceOf(Arguments); + chai.expect(argumentsInstance.list()[0]).to.be.an.instanceOf(Argument); + chai.expect(argumentsInstance.list()[0].name).to.be.equal(name); + chai.expect(argumentsInstance.list()[1]).to.be.an.instanceOf(Argument); + chai.expect(argumentsInstance.list()[1].name).to.be.eql(toMergeName); + }); + + test('Check merge() throws ArgumentObjectRequiredException', () => { + let error = null; + let expectedResult = argumentsInstance.list(); + + try { + argumentsInstance.merge({}); + } catch (e) { + error = e; + } + + chai.expect( + error, 'is an instance of ArgumentsObjectRequiredException' + ).to.be.an.instanceOf(ArgumentsObjectRequiredException); + chai.expect(argumentsInstance.list()).to.be.eql(expectedResult); + }); + + test('Check populate()', () => { + let argumentItem = 'logLevel=warn'; + let args = [argumentItem]; + + let actualResult = argumentsInstance.populate(args); + + chai.expect(actualResult).to.be.an.instanceOf(Arguments); + + chai.expect(argumentsInstance.list()[0].value).to.be.equal(argumentItem); + chai.expect(argumentsInstance.list()[0].exists).to.be.equal(true); + + }); + + //@todo - clarify with Alex C if Argument[] or String[] + test('Check populateUnmanaged()', () => { + let args = ['logLevel=info', 'testArg=value']; + + let actualResult = argumentsInstance.populateUnmanaged(args); + + chai.expect(actualResult).to.be.an.instanceOf(Arguments); + chai.expect(actualResult.listUnmanaged()).to.be.eql(args); + }); + + test('Check hasUnmanaged() returns true', () => { + chai.expect(argumentsInstance.hasUnmanaged).to.be.equal(true); + }); + + test('Check validate()', () => { + let actualResult = argumentsInstance.validate(); + + chai.expect( + actualResult, 'is an instance of Arguments' + ).to.be.an.instanceOf(Arguments); + }); + + test('Check validate() throws MissingArgumentException', () => { + let error = null; + + argumentsInstance.list()[0].required = true; + argumentsInstance.list()[0]._exists = false; + + try { + argumentsInstance.validate(); + } catch (e) { + error = e; + } + + chai.expect( + error, 'is an instance of MissingArgumentException' + ).to.be.an.instanceOf(MissingArgumentException); + }); + + test('Check listvalidate() for includeUnmanaged', () => { + let expectedResult = ['logLevel=info', 'testArg=value']; + + let actualResult = argumentsInstance.listValues(true); + + chai.expect(actualResult).to.eql(expectedResult); + }); }); diff --git a/src/test/Terminal/Help.spec.js b/src/test/Terminal/Help.spec.js index 18ffd6eb..0acca4b4 100644 --- a/src/test/Terminal/Help.spec.js +++ b/src/test/Terminal/Help.spec.js @@ -3,9 +3,13 @@ import chai from 'chai'; import {Help} from '../../lib/Terminal/Help'; import {Program} from '../../lib/Terminal/Program'; +import {ProgramInstanceRequiredException} from '../../lib/Terminal/Exception/ProgramInstanceRequiredException'; suite('Terminal/Help', () => { - + let programName = 'testProgramName'; + let programVersion = 'testProgramVersion'; + let programDescription = 'testProgramDescription'; + let programExample = 'testProgramExample'; let program = null; let help = null; @@ -14,11 +18,77 @@ suite('Terminal/Help', () => { }); test('Check constructor sets correctly values by default', () => { - program = new Program(); + program = new Program(programName, programVersion, programDescription, programExample); help = new Help(program) chai.expect(help, 'is an instance of Help').to.be.an.instanceOf(Help); chai.expect(help.program, 'is an instance of Program').to.be.an.instanceOf(Program); chai.expect(help.program).to.be.eql(program); }); + + test('Check constructor throws ProgramInstanceRequiredException', () => { + let error = null; + + try { + help = new Help({}); + } catch (e) { + error = e; + } + + chai.expect(error, 'is an instance of Help').to.be.an.instanceOf(ProgramInstanceRequiredException); + }); + + test('Check _stringify() returns "unknown"', () => { + let actualResult = Help._stringify(); + + chai.expect(actualResult).to.equal('unknown'); + + actualResult = Help._stringify(null); + + chai.expect(actualResult).to.equal('unknown'); + }); + + test('Check _stringify() returns "true"', () => { + let actualResult = Help._stringify(true); + + chai.expect(actualResult).to.equal('true'); + }); + + test('Check _stringify() returns "false"', () => { + let actualResult = Help._stringify(false); + + chai.expect(actualResult).to.equal('false'); + }); + + test('Check _stringify() returns "one,two"', () => { + let actualResult = Help._stringify(['one', 'two']); + + chai.expect(actualResult).to.equal('one,two'); + }); + + //@todo - need to deeply investigate how to check console.log + test('Check _printHead', () => { + let actualResult = help._printHead(); + + chai.expect(actualResult, 'is an instance of Help').to.be.an.instanceOf(Help); + }); + + test('Check _printExample', () => { + let actualResult = help._printExample(); + + chai.expect(actualResult, 'is an instance of Help').to.be.an.instanceOf(Help); + }); + + test('Check print', () => { + let actualResult = help.print(); + + chai.expect(actualResult, 'is an instance of Help').to.be.an.instanceOf(Help); + }); + + test('Check _scoreSimilarWord returns 0', () => { + + let actualResult = Help._scoreSimilarWord('testString', 'testWord'); + + chai.expect(actualResult).to.be.equal(0); + }); }); diff --git a/src/test/Terminal/Program.spec.js b/src/test/Terminal/Program.spec.js index 0bf2fbe1..3e38fa01 100644 --- a/src/test/Terminal/Program.spec.js +++ b/src/test/Terminal/Program.spec.js @@ -2,8 +2,14 @@ import chai from 'chai'; import {Program} from '../../lib/Terminal/Program'; +import {Options} from '../../lib/Terminal/Options'; +import {Arguments} from '../../lib/Terminal/Arguments'; suite('Terminal/Program', () => { + let programName = 'testProgramName'; + let programVersion = 'testProgramVersion'; + let programDescription = 'testProgramDescription'; + let programExample = 'testProgramExample'; let program = null; test('Class Program exists in Terminal/Program', () => { @@ -19,6 +25,30 @@ suite('Terminal/Program', () => { chai.expect(program.description).to.be.equal(null); chai.expect(program.example).to.be.equal(null); chai.expect(program.commands).to.be.eql([]); + chai.expect(program.inputParsed).to.be.equal(false); + chai.expect(program.unmanagedArgs).to.be.eql([]); + chai.expect(program.action).to.be.an('function'); + chai.expect(program.opts).to.be.an.instanceOf(Options); + chai.expect(program.args).to.be.an.instanceOf(Arguments); + chai.expect(program.nodeBinary).to.equal(Program.NODE_BINARY); + chai.expect(program.scriptPath).to.equal(null); + }); + + test('Check constructor sets name', () => { + program = new Program(programName, programVersion, programDescription, programExample); + + chai.expect(program, 'is an instance of Program').to.be.an.instanceOf(Program); + chai.expect(program.name).to.be.equal(programName); + chai.expect(program.version).to.be.equal(programVersion); + chai.expect(program.description).to.be.equal(programDescription); + chai.expect(program.example).to.be.equal(programExample); chai.expect(program.commands).to.be.eql([]); + chai.expect(program.inputParsed).to.be.equal(false); + chai.expect(program.unmanagedArgs).to.be.eql([]); + chai.expect(program.action).to.be.an('function'); + chai.expect(program.opts).to.be.an.instanceOf(Options); + chai.expect(program.args).to.be.an.instanceOf(Arguments); + chai.expect(program.nodeBinary).to.equal(Program.NODE_BINARY); + chai.expect(program.scriptPath).to.equal(null); }); }); From 7172843a532baa774c20577e51aadb1c5cfe0bd8 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 5 Feb 2016 17:27:04 +0200 Subject: [PATCH 107/133] Fix deploy config dump without -f flag --- src/bin/commands/deploy.js | 40 +++++++++++++------------------------- src/package.json | 2 +- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 19f1ca9b..7f060dfc 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -26,7 +26,6 @@ module.exports = function(mainPath) { var dumpCodePath = this.opts.locate('dump-local').value; var cfgBucket = this.opts.locate('cfg-bucket').value; var appEnv = isProd ? 'prod' : this.opts.locate('env').value; - var hasToPullDeps = this.opts.locate('pull-deps').exists; var microservicesToDeploy = this.opts.locate('partial').value; if (mainPath.indexOf(path.sep) !== 0) { @@ -140,17 +139,21 @@ module.exports = function(mainPath) { } propertyInstance.runInitMsHooks(function() { - var deployCb = function() { - prepareProduction.bind(this)(propertyInstance.path, doDeploy.bind(this)); - }; - - hasToPullDeps ? pullDeps.bind(this)(deployCb) : deployCb.bind(this)(); + prepareProduction.bind(this)(propertyInstance.path, doDeploy.bind(this)); }.bind(this)); }.bind(this)); } function dumpConfig(propertyInstance, cb) { - propertyInstance.configObj.completeDump(cb.bind(this)); + propertyInstance.configObj.completeDump(function() { + if (!fastDeploy) { + let configFile = propertyInstance.configObj.configFile; + + fse.copySync(configFile, path.join(mainPath, path.basename(configFile))); + } + + cb.bind(this)(); + }.bind(this)); } function doCompileProd(propertyPath, cb) { @@ -290,26 +293,6 @@ module.exports = function(mainPath) { return typeof msIdentifiers === 'string' ? [msIdentifiers] : msIdentifiers; } - function pullDeps(cb) { - console.log('Resolving dependencies in ' + tmpPropertyPath); - - new Exec( - Bin.node, - this.scriptPath, - 'pull-deps', - tmpPropertyPath - ) - .avoidBufferOverflow() - .run(function(result) { - if (result.failed) { - console.error('Error while pulling dependencies in ' + tmpPropertyPath + ': ' + result.error); - this.exit(1); - } - - cb.bind(this)(); - }.bind(this)); - } - function dumpCode() { if (!dumpCodePath) { return; @@ -343,6 +326,9 @@ module.exports = function(mainPath) { return; } + var lambdasVector = []; + var stack = lambdas.length; + for (var i = 0; i < lambdas.length; i++) { try { fs.unlinkSync(lambdas[i]); diff --git a/src/package.json b/src/package.json index 97b23cd5..5333e547 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.9", + "version": "1.6.10", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From af5083ff06dd89fff79251a6f174f163791ed4fe Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 10 Feb 2016 12:27:22 +0200 Subject: [PATCH 108/133] Fix typo --- src/bin/commands/deploy.js | 2 +- src/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 7f060dfc..8d0953fc 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -147,7 +147,7 @@ module.exports = function(mainPath) { function dumpConfig(propertyInstance, cb) { propertyInstance.configObj.completeDump(function() { if (!fastDeploy) { - let configFile = propertyInstance.configObj.configFile; + var configFile = propertyInstance.configObj.configFile; fse.copySync(configFile, path.join(mainPath, path.basename(configFile))); } diff --git a/src/package.json b/src/package.json index 5333e547..5ea809bd 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.10", + "version": "1.6.11", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From c42c291e5ea7c720f9e1f48ee627e45792437a36 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 10 Feb 2016 15:42:35 +0200 Subject: [PATCH 109/133] Implement generate-migration --- src/bin/commands/assets/migration_tpl.txt | 20 ++++++++++++++ src/bin/commands/migration-create.js | 32 +++++++++++++++++++++++ src/bin/manifest.js | 12 +++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/bin/commands/assets/migration_tpl.txt create mode 100644 src/bin/commands/migration-create.js diff --git a/src/bin/commands/assets/migration_tpl.txt b/src/bin/commands/assets/migration_tpl.txt new file mode 100644 index 00000000..73ecfea6 --- /dev/null +++ b/src/bin/commands/assets/migration_tpl.txt @@ -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(); + }, +}; diff --git a/src/bin/commands/migration-create.js b/src/bin/commands/migration-create.js new file mode 100644 index 00000000..123f33d4 --- /dev/null +++ b/src/bin/commands/migration-create.js @@ -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()) + ); +}; diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 0aa0c07a..54ff5270 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -257,6 +257,18 @@ module.exports = { }, }, }, + 'migration-create': { + example: 'deepify migration-create path/to/microservice', + description: 'Create migration for a certain microservice', + opts: { + }, + args: { + path: { + description: 'The path to the microservice', + required: true, + }, + }, + }, 'init-backend': { example: 'deepify init-backend path/to/web_app', description: 'Initialize backend', From 28a9139cf7e53d57838331883ac19b42668655e4 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 10 Feb 2016 17:31:21 +0200 Subject: [PATCH 110/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 5ea809bd..e801e764 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.11", + "version": "1.6.12", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 2f60b0d3b466ed5ff100923022ecd2cb32de48f7 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 10 Feb 2016 18:12:07 +0200 Subject: [PATCH 111/133] Publish deepify --- src/bin/manifest.js | 2 +- src/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 2feb34b7..9dfcdad6 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -254,7 +254,7 @@ module.exports = { }, 'migration-create': { example: 'deepify migration-create path/to/microservice', - description: 'Create migration for a certain microservice', + description: 'Create empty migration for a certain microservice', opts: { }, args: { diff --git a/src/package.json b/src/package.json index e801e764..6bcfa2d3 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.12", + "version": "1.6.13", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 83806a00864da2c81004893e335b9242539ea594 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 10 Feb 2016 18:27:46 +0200 Subject: [PATCH 112/133] Rename migration create command --- ...igration-create.js => create-migration.js} | 0 src/bin/manifest.js | 56 +++++++++---------- src/package.json | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) rename src/bin/commands/{migration-create.js => create-migration.js} (100%) diff --git a/src/bin/commands/migration-create.js b/src/bin/commands/create-migration.js similarity index 100% rename from src/bin/commands/migration-create.js rename to src/bin/commands/create-migration.js diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 9dfcdad6..bbd2a01a 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -140,13 +140,23 @@ module.exports = { }, }, }, - 'enable-ssl': { - example: 'deepify enable-ssl path/to/web_app', - description: 'Enables SSL on a deployed web app', + undeploy: { + example: 'deepify undeploy path/to/web_app', + description: 'Remove web app provisioning and uploaded data', opts: { - domain: { + 'cfg-bucket': { + alias: 'b', + description: 'AWS S3 system bucket name where the deploy config was persisted (ex. deep.prod.system.db0c09cc)', + required: false, + }, + 'resource': { + alias: 'r', + description: 'An generated AWS resource name from given deploy (ex. deep.prod.system.db0c09cc)', + required: false, + }, + dirty: { alias: 'd', - description: 'The domain to create the certificate for (overrides the "deeploy.json" value)', + description: 'Force cleaning up all resources if .cfg.deeploy.json file missing', required: false, }, }, @@ -157,10 +167,15 @@ module.exports = { }, }, }, - 'disable-ssl': { - example: 'deepify disable-ssl path/to/web_app', - description: 'Disable activated SSL on a deployed web app', + 'enable-ssl': { + example: 'deepify enable-ssl path/to/web_app', + description: 'Enables SSL on a deployed web app', opts: { + domain: { + alias: 'd', + description: 'The domain to create the certificate for (overrides the "deeploy.json" value)', + required: false, + }, }, args: { path: { @@ -169,25 +184,10 @@ module.exports = { }, }, }, - undeploy: { - example: 'deepify undeploy path/to/web_app', - description: 'Remove web app provisioning and uploaded data', + 'disable-ssl': { + example: 'deepify disable-ssl path/to/web_app', + description: 'Disable activated SSL on a deployed web app', opts: { - 'cfg-bucket': { - alias: 'b', - description: 'AWS S3 system bucket name where the deploy config was persisted (ex. deep.prod.system.db0c09cc)', - required: false, - }, - 'resource': { - alias: 'r', - description: 'An generated AWS resource name from given deploy (ex. deep.prod.system.db0c09cc)', - required: false, - }, - dirty: { - alias: 'd', - description: 'Force cleaning up all resources if .cfg.deeploy.json file missing', - required: false, - }, }, args: { path: { @@ -252,8 +252,8 @@ module.exports = { }, }, }, - 'migration-create': { - example: 'deepify migration-create path/to/microservice', + 'create-migration': { + example: 'deepify create-migration path/to/microservice', description: 'Create empty migration for a certain microservice', opts: { }, diff --git a/src/package.json b/src/package.json index 6bcfa2d3..55b0567a 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.13", + "version": "1.6.14", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From e72574b888ada926384b1c831dfc45a45c5fbbd3 Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Wed, 10 Feb 2016 19:05:33 +0200 Subject: [PATCH 113/133] Fix deploy config --- src/test/TestMaterials/Property2/deeploy.test.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/TestMaterials/Property2/deeploy.test.json b/src/test/TestMaterials/Property2/deeploy.test.json index 59402e76..60fdf0d1 100644 --- a/src/test/TestMaterials/Property2/deeploy.test.json +++ b/src/test/TestMaterials/Property2/deeploy.test.json @@ -4,9 +4,6 @@ "region": "us-west-2", "secretAccessKey": "to_pass_string_validation" }, - "dependencies": { - "bucket": "testbucket" - }, "env": "test", "awsAccountId": 123456789012, "appIdentifier": "generated" From c175d48f5dbc89dafbdf277c235727e5fda7c672 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 19 Feb 2016 17:05:07 +0200 Subject: [PATCH 114/133] Integrate registry abstraction --- src/bin/commands/install.js | 249 +++++++--------- src/bin/manifest.js | 26 +- src/lib/Registry/GitHub/Dependency.js | 281 ++++++++++++++++++ .../Exception/InvalidTagMetadataException.js | 16 + .../ExtractStrategy/AbstractStrategy.js | 25 ++ .../ExtractStrategy/StandardStrategy.js | 53 ++++ src/lib/Registry/GitHub/Tag.js | 78 +++++ src/lib/Registry/GitHub/TagMetadata.js | 52 ++++ src/lib/Registry/GitHub/tag.schema.js | 21 ++ src/package.json | 6 +- 10 files changed, 661 insertions(+), 146 deletions(-) create mode 100644 src/lib/Registry/GitHub/Dependency.js create mode 100644 src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js create mode 100644 src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js create mode 100644 src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js create mode 100644 src/lib/Registry/GitHub/Tag.js create mode 100644 src/lib/Registry/GitHub/TagMetadata.js create mode 100644 src/lib/Registry/GitHub/tag.schema.js diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index f37afb57..a1336c5e 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -5,31 +5,97 @@ 'use strict'; -module.exports = function(microserviceRepo, dumpPath) { - var fs = require('fs'); - var tmp = require('tmp'); - var path = require('path'); - var fse = require('fs-extra'); - var Exec = require('../../lib.compiled/Helpers/Exec').Exec; +module.exports = function(dependency) { + + // @todo: move it in config? + var DEFAULT_REGISTRY_BASE_HOST = 'https://deep.mg'; + + var GitHubDependency = require('../../lib.compiled/Registry/GitHub/Dependency').Dependency; + var Property = require('deep-package-manager').Property_Instance; + var PropertyConfig = require('deep-package-manager').Property_Config; + var Registry = require('deep-package-manager').Registry_Registry; var Bin = require('../../lib.compiled/NodeJS/Bin').Bin; - var Prompt = require('../../lib.compiled/Terminal/Prompt').Prompt; + var Exec = require('../../lib.compiled/Helpers/Exec').Exec; + var path = require('path'); + + var workingDirectory = process.cwd(); + var registryBaseHost = this.opts.locate('registry').value || DEFAULT_REGISTRY_BASE_HOST; + var initApp = this.opts.locate('init').exists; + var depParts = parseDep(); + var depName = depParts[0]; + var depVersion = depParts[1]; + + if (depName) { + var fetcher = GitHubDependency.isGitHubDependency(depName) ? fetchGitHub : fetchRepository; + + fetcher.bind(this)(function(error) { + if (error) { + console.error(error); + this.exit(1); + } + + console.log(`The microservice '${depName}' has been successfully installed`); - if (dumpPath.indexOf(path.sep) !== 0) { - dumpPath = path.join(process.cwd(), dumpPath); + initBackend.bind(this)(); + }.bind(this)); + } else { + createRegistry.bind(this)(function(registry) { + console.log('Installing web app dependencies'); + + registry.install(createProperty(), function(error) { + if (error) { + console.error(error); + this.exit(1); + } + + console.log('Wep app dependencies have been successfully installed'); + + initBackend.bind(this)(); + }.bind(this)); + }.bind(this)); } - gitFetch(microserviceRepo, function(error) { - if (error) { - this.exit(1); + function createProperty() { + return Property.create(workingDirectory, PropertyConfig.DEFAULT_FILENAME); + } + + function createRegistry(cb) { + console.log('Initializing remote registry'); + + Registry.createApiRegistry(registryBaseHost, function(error, registry) { + if (error) { + console.error(error); + this.exit(1); + } + + cb(registry); + }.bind(this)); + } + + function parseDep() { + var parts = (dependency || '').split('@'); + + if (parts.length <= 1) { + return [parts[0], '*']; + } + + return [parts[0], parts[1]]; + } + + function initBackend() { + if (!initApp) { return; } + console.log('Start initializing backend'); + npmInstall('"babel@^5.x.x"', function(error) { if (error) { console.error('Error while installing babel: ' + error); + this.exit(1); } - //@todo - temporary workarround for FATAL ERROR- JS Allocation failed – process out of memory + //@todo - temporary workaround for FATAL ERROR- JS Allocation failed – process out of memory if(/^win/.test(process.platform)) { console.warn('The web application was successfully installed on Windows!\n'); console.info('To initialize backend use "deepify init-backend path/to" command'); @@ -37,34 +103,48 @@ module.exports = function(microserviceRepo, dumpPath) { return; } - var prompt = new Prompt('Initialize backend?'); + var cmd = new Exec( + Bin.node, + this.scriptPath, + 'init-backend', + workingDirectory + ); - prompt.readConfirm(function(result) { - if (result) { - console.log('Start initializing backend...'); + cmd.run(function(result) { + if (result.failed) { + console.error(result.error); + this.exit(1); + } - var cmd = new Exec( - Bin.node, - this.scriptPath, - 'init-backend', - dumpPath - ); + console.log('Wep app dependencies have been successfully initialized'); + }.bind(this), true); + }.bind(this)); + } - cmd.run(function(result) { - if (result.failed) { - console.error(result.error); - } + function fetchGitHub(cb) { + console.log('Fetching microservice from GitHub'); - console.log('The web application was successfully installed.'); - }, true); + var depObj = new GitHubDependency(depName, depVersion); - return; - } + depObj.extract( + path.join(workingDirectory, depObj.shortDependencyName), + cb.bind(this) + ); + } - console.log('The web application was successfully installed.'); - }.bind(this)); + function fetchRepository(cb) { + createRegistry.bind(this)(function(registry) { + console.log('Fetching microservice from DEEP repository'); + + registry.installModule( + depName, + depVersion, + path.join(workingDirectory, depName), + cb.bind(this), + createProperty.bind(this)() + ); }.bind(this)); - }.bind(this)); + } function npmInstall(repo, cb) { console.log('Installing ' + repo + ' via NPM globally'); @@ -82,105 +162,4 @@ module.exports = function(microserviceRepo, dumpPath) { cb(null); }.bind(this)); } - - function gitFetch(repo, cb, copyFiles) { - copyFiles = copyFiles || {}; - - var tmpFolder = tmp.dirSync().name; - - console.log('Cloning the ' + repo + ' into ' + tmpFolder); - - var cmd = new Exec('git', 'clone', '--depth=1', repo, '.'); - cmd.cwd = tmpFolder; - - cmd - .avoidBufferOverflow() - .run(function(result) { - if (result.failed) { - console.error('Error cloning ' + repo + ' repository into ' + tmpFolder + ': ' + result.error); - - fse.removeSync(tmpFolder); - cb(result.error); - return; - } - - var srcDir = path.join(tmpFolder, 'src'); - - if (!fs.existsSync(srcDir)) { - var error = 'Missing "src" directory in ' + tmpFolder; - - fse.removeSync(tmpFolder); - cb(new Error(error)); - return; - } - - cleanupDir(srcDir); - - try { - var subdir = getSubdirName(srcDir); - } catch (e) { - fse.removeSync(srcDir); - cb(e); - return; - } - - var sourcePath = path.join(srcDir, subdir); - var targetPath = path.join(dumpPath, subdir); - - fse.copySync(sourcePath, targetPath, {clobber: true}); - - var copyFilesKeys = Object.keys(copyFiles); - - for (var i in copyFilesKeys) { - if (!copyFilesKeys.hasOwnProperty(i)) { - continue; - } - - var fSrc = copyFilesKeys[i]; - var fDes = copyFiles[fSrc]; - - fse.copySync(path.join(tmpFolder, fSrc), fDes, {clobber: true}); - } - - fse.removeSync(tmpFolder); - - cb(null); - }.bind(this)); - } - - /** - * @param {String} dir - */ - function cleanupDir(dir) { - new Exec('find', dir, '-type d -name ".git" -print0 | xargs -0 rm -rf') - .avoidBufferOverflow() - .runSync(); - } - - /** - * @param {String} dir - * @returns {String} - */ - function getSubdirName(dir) { - var dirFiles = fs.readdirSync(dir); - - if (dirFiles.length <= 0) { - throw new Error('No sub directories in ' + dir); - } - - for (var i in dirFiles) { - if (!dirFiles.hasOwnProperty(i)) { - continue; - } - - var file = dirFiles[i]; - var filePath = path.join(dir, file); - - if (fs.lstatSync(filePath).isDirectory()) { - return file; - } - } - - throw new Error('There is no directory in ' + dir); - } }; diff --git a/src/bin/manifest.js b/src/bin/manifest.js index bbd2a01a..00a7d18b 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -26,19 +26,25 @@ module.exports = { }, }, }, - 'install': { - example: 'deepify install https://github.com/MitocGroup/deep-microservices-todo-app.git path/to/web_app', - description: 'Install an microservice from remote git repository', + install: { + example: 'deepify install github://MitocGroup/deep-microservices-todo-app', + description: 'Install the web app or a single microservice from the registry or GitHub', opts: { + init: { + alias: 'i', + description: 'Initialize deep web app', + required: false, + }, + registry: { + alias: 'r', + description: 'Custom registry url (ex. https://deep.mg)', + required: false, + }, }, args: { - repository: { - description: 'The remote microservice git repository', - required: true, - }, - path: { - description: 'The path to dump microservice into', - required: true, + dependency: { + description: 'The dependency you want to fetch (ex. "deep.ng.todo@^0.0.x")', + required: false, }, }, }, diff --git a/src/lib/Registry/GitHub/Dependency.js b/src/lib/Registry/GitHub/Dependency.js new file mode 100644 index 00000000..a51a33c1 --- /dev/null +++ b/src/lib/Registry/GitHub/Dependency.js @@ -0,0 +1,281 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import request from 'fetchy-request'; +import {Tag} from './Tag'; +import {Registry_Resolver_Strategy_SemVerStrategy as SemVerStrategy} from 'deep-package-manager'; +import tar from 'tar-stream'; +import gunzip from 'gunzip-maybe'; +import {Helpers_WaitFor as WaitFor} from 'deep-package-manager'; +import {StandardStrategy} from './ExtractStrategy/StandardStrategy'; + +export class Dependency { + /** + * @param {String} dependencyName + * @param {String} dependencyVersion + */ + constructor(dependencyName, dependencyVersion) { + this._dependencyName = dependencyName; + this._dependencyVersion = dependencyVersion; + + this._repository = Dependency.parseDependencyRepository(dependencyName); + + if (!this._repository) { + throw new Error(`Unable to parse GitHub repository ${this.shortDependencyName}`); + } + + Dependency.__cache__ = []; + } + + /** + * @param {String} dumpPath + * @param {Function} cb + * @param {AbstractStrategy|StandardStrategy|*} extractStrategy + */ + extract(dumpPath, cb, extractStrategy = null) { + console.log(`Searching for suitable '${this.shortDependencyName}' dependency version`); + + this.findSuitableTag((error, tag) => { + if (error) { + cb(error); + return; + } + + console.log(`Fetching suitable '${this.shortDependencyName}' dependency version from '${tag.sourceUrl}'`); + + request(Dependency._createRequestPayload(Dependency._normalizeSourceUrl(tag.sourceUrl))) + .then((response) => { + if (!response.ok) { + cb(response._error || new Error(response.statusText)); + return; + } + + console.log(`Dumping '${this.shortDependencyName}' dependency into '${dumpPath}'`); + + extractStrategy = extractStrategy || new StandardStrategy(dumpPath); + + let unTarStream = tar.extract(); + + let wait = new WaitFor(); + let filesToExtract = 0; + + wait.push(() => { + return filesToExtract <= 0; + }); + + unTarStream.on('entry', (header, stream, next) => { + if (header.type === 'directory') { + next(); + return; + } + + filesToExtract++; + + let filePath = header.name.replace(/^([^\/]+\/)/, ''); + + extractStrategy.extract(filePath, stream, () => { + filesToExtract--; + + next(); + }); + }); + + unTarStream.on('finish', () => { + wait.ready(cb); + }); + + response.body + .pipe(gunzip()) + .pipe(unTarStream); + + }).catch(cb); + }); + } + + /** + * @param {Function} cb + */ + findSuitableTag(cb) { + if (Dependency.__cache__.hasOwnProperty(this._repository)) { + console.log(`Using GitHub repository '${this._repository}' tags from cache`); + + cb(...this._findSuitable(Dependency.__cache__[this._repository])); + return; + } + + console.log(`Fetching GitHub repository '${this._repository}' tags`); + + this.getAvailableTags((error, tags) => { + if (error) { + cb(error, null); + return; + } + + Dependency.__cache__[this._repository] = tags; + + cb(...this._findSuitable(tags)); + }); + } + + /** + * @param {Tag[]} tags + * @returns {Array} + * @private + */ + _findSuitable(tags) { + let semverStrategy = new SemVerStrategy(); + let versions = tags.map((tag) => tag.name); + + let matchedVersion = semverStrategy.resolve({ + getVersions: () => versions, + }, this._dependencyVersion); + + if (!matchedVersion) { + return [ + new Error( + `No suitable version found for '${this.shortDependencyName}@${this._dependencyVersion}' (${versions.join(', ')})` + ), + null + ]; + } + + for (let i in tags) { + if (!tags.hasOwnProperty(i)) { + continue; + } + + let tag = tags[i]; + + if (SemVerStrategy.CLEAN_FUNC(tag.name) === matchedVersion) { + return [null, tag]; + } + } + } + + /** + * @param {Function} cb + */ + getAvailableTags(cb) { + request(Dependency._createRequestPayload(Dependency.TAGS_URI_TPL.replace(/\{repository\}/i, this._repository))) + .then((response) => { + if (!response.ok) { + cb(response._error || new Error(response.statusText), null); + return; + } + + response + .text() + .then((plainData) => { + try { + cb(null, Tag.createFromMetadataVector(this._repository, JSON.parse(plainData))); + } catch (error) { + cb(error, null); + } + }) + .catch((error) => { + cb(error, null); + }); + }).catch((error) => { + cb(error, null); + }); + } + + /** + * @returns {String} + */ + get shortDependencyName() { + return this._repository.split('/')[1]; + } + + /** + * @returns {String} + */ + get dependencyName() { + return this._dependencyName; + } + + /** + * @returns {String} + */ + get dependencyVersion() { + return this._dependencyVersion; + } + + /** + * @returns {String|*} + */ + get repository() { + return this._repository; + } + + + /** + * @param {String} sourceUrl + * @returns {String} + * @private + * + * @example https://codeload.github.com/MitocGroup/deep-microservices-todo-app/legacy.tar.gz/v0.0.1 + * ----> + * https://api.github.com/repos/MitocGroup/deep-microservices-todo-app/tarball/v0.0.1 + */ + static _normalizeSourceUrl(sourceUrl) { + let matches = sourceUrl.match(/https?:\/\/api\.github\.com\/repos\/([^\/]+\/[^\/]+)\/tarball\/([^\/]+)$/i); + + if (!matches || matches.length < 3) { + return sourceUrl; + } + + let repo = matches[1]; + let version = matches[2]; + + return `https://codeload.github.com/${repo}/legacy.tar.gz/${version}`; + } + + /** + * @param {String} uri + * @returns {Object} + */ + static _createRequestPayload(uri) { + return { + uri: uri, + method: 'GET', + retry: 3, + headers: { + 'User-Agent': 'User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.56 (KHTML, like Gecko) Version/9.0 Safari/601.1.56', + Accept: '*/*', + }, + }; + } + + /** + * @param {String} dependencyName + * @returns {Boolean} + */ + static isGitHubDependency(dependencyName) { + return !!Dependency.parseDependencyRepository(dependencyName); + } + + /** + * @param {String} dependencyName + * @returns {String|null} + */ + static parseDependencyRepository(dependencyName) { + let repo = dependencyName.match(/^github:\/\/([^\/]+\/[^\/]+)$/i); + + if (repo && repo.length === 2) { + return repo[1].toString(); + } + + return null; + } + + /** + * @returns {String} + */ + static get TAGS_URI_TPL() { + return 'https://api.github.com/repos/{repository}/tags'; + } +} diff --git a/src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js b/src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js new file mode 100644 index 00000000..978f4d67 --- /dev/null +++ b/src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js @@ -0,0 +1,16 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import {Exception} from '../../../Exception/Exception'; + +export class InvalidTagMetadataException extends Exception { + /** + * @param {String|Error|*} error + */ + constructor(error) { + super(`Invalid tag metadata: ${error}`); + } +} diff --git a/src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js b/src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js new file mode 100644 index 00000000..14de6c87 --- /dev/null +++ b/src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js @@ -0,0 +1,25 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import Core from 'deep-core'; + +export class AbstractStrategy extends Core.OOP.Interface { + /** + * @param {String} dumpPath + */ + constructor(dumpPath) { + super(['extract']); + + this._dumpPath = dumpPath; + } + + /** + * @returns {String} + */ + get dumpPath() { + return this._dumpPath; + } +} diff --git a/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js b/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js new file mode 100644 index 00000000..f04785a1 --- /dev/null +++ b/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js @@ -0,0 +1,53 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import {AbstractStrategy} from './AbstractStrategy'; +import path from 'path'; +import fse from 'fs-extra'; + +export class StandardStrategy extends AbstractStrategy { + /** + * @param {*} args + */ + constructor(...args) { + super(...args); + } + + /** + * @param {String} filePath + * @param {Stream|Writable|Readable|stream.Readable|stream.Writable|*} stream + * @param {Function} cb + */ + extract(filePath, stream, cb) { + if (!StandardStrategy._haveToDump(filePath)) { + cb(); + return; + } + + let file = path.join(this.dumpPath, StandardStrategy._normalizeFilePath(filePath)); + + stream.pipe(fse.createOutputStream(file)); + stream.on('end', cb); + } + + /** + * @param {String} filePath + * @returns {String} + * @private + */ + static _normalizeFilePath(filePath) { + return filePath.replace(/^(\/?src\/[^\/]+\/)/i, ''); + } + + /** + * @param {String} filePath + * @returns {Boolean} + * @private + */ + static _haveToDump(filePath) { + return /^\/?src\/[A-Z][^\/]+\//.test(filePath); + } +} diff --git a/src/lib/Registry/GitHub/Tag.js b/src/lib/Registry/GitHub/Tag.js new file mode 100644 index 00000000..d53eae43 --- /dev/null +++ b/src/lib/Registry/GitHub/Tag.js @@ -0,0 +1,78 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import {TagMetadata} from './TagMetadata'; + +export class Tag { + /** + * @param {String} repository + * @param {String} name + * @param {String} sourceUrl + */ + constructor(repository, name, sourceUrl) { + this._repository = repository; + this._name = name; + this._sourceUrl = sourceUrl; + } + + /** + * @param {String} repository + * @param {Object[]} tagMetadataVector + * @param {Boolean} failSilently + * @returns {Array} + */ + static createFromMetadataVector(repository, tagMetadataVector, failSilently = true) { + let tags = []; + + for (let tagMetadata in tagMetadataVector) { + if (!tagMetadataVector.hasOwnProperty(tagMetadata)) { + continue; + } + + try { + tags.push(Tag.createFromRawMetadata(repository, tagMetadataVector[tagMetadata])); + } catch (error) { + if (!failSilently) { + throw error; + } + } + } + + return tags; + } + + /** + * @param {String} repository + * @param {Object} rawTagMetadata + * @returns {Tag} + */ + static createFromRawMetadata(repository, rawTagMetadata) { + let metadata = (new TagMetadata(rawTagMetadata)).extract(); + + return new Tag(repository, metadata.name, metadata.tarball_url); + } + + /** + * @returns {String} + */ + get repository() { + return this._repository; + } + + /** + * @returns {String} + */ + get name() { + return this._name; + } + + /** + * @returns {String} + */ + get sourceUrl() { + return this._sourceUrl; + } +} diff --git a/src/lib/Registry/GitHub/TagMetadata.js b/src/lib/Registry/GitHub/TagMetadata.js new file mode 100644 index 00000000..ac06ff05 --- /dev/null +++ b/src/lib/Registry/GitHub/TagMetadata.js @@ -0,0 +1,52 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import tagSchema from './tag.schema'; +import {InvalidTagMetadataException} from './Exception/InvalidTagMetadataException'; +import Joi from 'joi'; + +export class TagMetadata { + /** + * @param {Object} tagMetadata + */ + constructor(tagMetadata) { + this._tagMetadata = tagMetadata; + + this._parsedTagMetadata = Joi.validate(tagMetadata, tagSchema); + } + + /** + * @returns {Object} + */ + get rawMetadata() { + return this._tagMetadata; + } + + /** + * @returns {Boolean} + */ + get valid() { + return !this.error; + } + + /** + * @returns {String} + */ + get error() { + return this._parsedTagMetadata.error; + } + + /** + * @returns {Object} + */ + extract() { + if (!this.valid) { + throw new InvalidTagMetadataException(this.error); + } + + return this._parsedTagMetadata.value; + } +} diff --git a/src/lib/Registry/GitHub/tag.schema.js b/src/lib/Registry/GitHub/tag.schema.js new file mode 100644 index 00000000..4b3c6425 --- /dev/null +++ b/src/lib/Registry/GitHub/tag.schema.js @@ -0,0 +1,21 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +/** + * Created by AlexanderC on 5/25/15. + */ + +'use strict'; + +import Joi from 'joi'; + +export default Joi.object().keys({ + name: Joi.string().required(), + zipball_url: Joi.string().uri().required(), + tarball_url: Joi.string().uri().required(), + commit: Joi.object().keys({ + sha: Joi.string().regex(/^[a-z0-9]+$/i).required(), + url: Joi.string().uri().required(), + }), +}); diff --git a/src/package.json b/src/package.json index 55b0567a..214f311a 100644 --- a/src/package.json +++ b/src/package.json @@ -68,7 +68,11 @@ "aws-api-gw-client": "^0.1.x", "mime": "^1.3.x", "gather-dependencies": "^1.0.x", - "aws-sdk": "^2.2.x" + "aws-sdk": "^2.2.x", + "fetchy-request": "^0.8.x", + "joi": "^6.4.x", + "tar-stream": "^1.3.x", + "gunzip-maybe": "^1.3.1" }, "devDependencies": { "chai": "^3.2.x", From aa5950981e20d6e844645269a3c7ee3552859840 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 19 Feb 2016 18:44:03 +0200 Subject: [PATCH 115/133] Add auth token registry integration --- src/bin/commands/install.js | 36 ++++++++- src/lib/Registry/AuthToken.js | 78 +++++++++++++++++++ src/lib/Registry/Config.js | 42 ++++++++++ .../ExtractStrategy/StandardStrategy.js | 6 +- 4 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 src/lib/Registry/AuthToken.js create mode 100644 src/lib/Registry/Config.js diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index a1336c5e..0ce551c4 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -11,11 +11,14 @@ module.exports = function(dependency) { var DEFAULT_REGISTRY_BASE_HOST = 'https://deep.mg'; var GitHubDependency = require('../../lib.compiled/Registry/GitHub/Dependency').Dependency; + var AuthToken = require('../../lib.compiled/Registry/AuthToken').AuthToken; var Property = require('deep-package-manager').Property_Instance; var PropertyConfig = require('deep-package-manager').Property_Config; var Registry = require('deep-package-manager').Registry_Registry; + var RegistryAuthorizer = require('deep-package-manager').Registry_Storage_Driver_Helpers_Api_Auth_Authorizer; var Bin = require('../../lib.compiled/NodeJS/Bin').Bin; var Exec = require('../../lib.compiled/Helpers/Exec').Exec; + var Microservice = require('deep-package-manager').Microservice_Instance; var path = require('path'); var workingDirectory = process.cwd(); @@ -59,6 +62,10 @@ module.exports = function(dependency) { return Property.create(workingDirectory, PropertyConfig.DEFAULT_FILENAME); } + function getRegistryToken() { + return (new AuthToken()).refresh().toString(); + } + function createRegistry(cb) { console.log('Initializing remote registry'); @@ -68,6 +75,8 @@ module.exports = function(dependency) { this.exit(1); } + registry.storage.driver.authorizer = RegistryAuthorizer.createHeaderToken(getRegistryToken()); + cb(registry); }.bind(this)); } @@ -125,10 +134,31 @@ module.exports = function(dependency) { console.log('Fetching microservice from GitHub'); var depObj = new GitHubDependency(depName, depVersion); + var dumpPath = path.join(workingDirectory, depObj.shortDependencyName); depObj.extract( - path.join(workingDirectory, depObj.shortDependencyName), - cb.bind(this) + dumpPath, + function(error) { + if (error) { + console.error(error); + this.exit(1); + } + + var microservice = Microservice.create(dumpPath); + + createRegistry.bind(this)(function(registry) { + console.log(`Installing '${depObj.shortDependencyName}' dependencies`); + + registry.install(createProperty(), function(error) { + if (error) { + console.error(error); + this.exit(1); + } + + cb.bind(this)(); + }.bind(this), [microservice.identifier]); + }.bind(this)); + }.bind(this) ); } @@ -139,7 +169,7 @@ module.exports = function(dependency) { registry.installModule( depName, depVersion, - path.join(workingDirectory, depName), + workingDirectory, cb.bind(this), createProperty.bind(this)() ); diff --git a/src/lib/Registry/AuthToken.js b/src/lib/Registry/AuthToken.js new file mode 100644 index 00000000..047b8c26 --- /dev/null +++ b/src/lib/Registry/AuthToken.js @@ -0,0 +1,78 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import {Config} from './Config'; + +export class AuthToken { + /** + * @param {String|null} token + */ + constructor(token = null) { + this._token = token; + } + + /** + * @returns {String|null|*} + */ + get token() { + return this._token; + } + + /** + * @returns {AuthToken} + */ + refresh() { + this._token = AuthToken._fromGlobal || + AuthToken._fromEnvVar || + AuthToken._fromConfigFile || + 'ANON'; + + return this; + } + + /** + * @returns {String|null} + * @private + */ + static get _fromEnvVar() { + return process.env[AuthToken.TOKEN_VAR_NAME]; + } + + /** + * @returns {String|null} + * @private + */ + static get _fromGlobal() { + return global[AuthToken.TOKEN_VAR_NAME]; + } + + /** + * @returns {String|null} + * @private + */ + static get _fromConfigFile() { + try { + let config = Config.create(); + + return config[AuthToken.TOKEN_VAR_NAME]; + } catch (error) { + } + } + + /** + * @returns {String} + */ + static get TOKEN_VAR_NAME() { + return 'DEEP_REGISTRY_AUTH_TOKEN'; + } + + /** + * @returns {String} + */ + toString() { + return this._token.toString(); + } +} diff --git a/src/lib/Registry/Config.js b/src/lib/Registry/Config.js new file mode 100644 index 00000000..5c82cf9a --- /dev/null +++ b/src/lib/Registry/Config.js @@ -0,0 +1,42 @@ +/** + * Created by AlexanderC on 2/19/16. + */ + +'use strict'; + +import os from 'os'; +import path from 'path'; +import fse from 'fs-extra'; +import {Registry_Storage_Driver_Helpers_Api_RegistryAutoDiscovery as RegistryAutoDiscovery} from 'deep-package-manager'; + +export class Config { + /** + * @param {Object|null} config + */ + constructor(config = null) { + this._config = config; + } + + /** + * @returns {Config} + */ + static create() { + return new Config(fse.readJsonSync(Config.CONFIG_FILE)); + } + + /** + * @returns {String} + */ + static get CONFIG_FILE() { + let dir = path.dirname(RegistryAutoDiscovery.DEFAULT_CACHE_FILE); + + return path.join(dir, Config.CONFIG_FILE_NAME); + } + + /** + * @returns {String} + */ + static get CONFIG_FILE_NAME() { + return 'deepify.config.json'; + } +} diff --git a/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js b/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js index f04785a1..d1e37a4b 100644 --- a/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js +++ b/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js @@ -28,9 +28,11 @@ export class StandardStrategy extends AbstractStrategy { } let file = path.join(this.dumpPath, StandardStrategy._normalizeFilePath(filePath)); + let output = fse.createOutputStream(file); - stream.pipe(fse.createOutputStream(file)); - stream.on('end', cb); + output.on('finish', cb); + + stream.pipe(output); } /** From a36ae74928b6f779bab7abd81ffde796869135b2 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 19 Feb 2016 19:53:15 +0200 Subject: [PATCH 116/133] Tweak helloworld to work with registry --- src/bin/commands/helloworld.js | 21 +- src/bin/commands/install.js | 12 +- src/bin/manifest.js | 5 + src/lib/Registry/GitHub/Dependency.js | 281 ------------------ .../Exception/InvalidTagMetadataException.js | 16 - .../ExtractStrategy/AbstractStrategy.js | 25 -- .../ExtractStrategy/StandardStrategy.js | 55 ---- src/lib/Registry/GitHub/Tag.js | 78 ----- src/lib/Registry/GitHub/TagMetadata.js | 52 ---- src/lib/Registry/GitHub/tag.schema.js | 21 -- src/package.json | 6 +- 11 files changed, 29 insertions(+), 543 deletions(-) delete mode 100644 src/lib/Registry/GitHub/Dependency.js delete mode 100644 src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js delete mode 100644 src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js delete mode 100644 src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js delete mode 100644 src/lib/Registry/GitHub/Tag.js delete mode 100644 src/lib/Registry/GitHub/TagMetadata.js delete mode 100644 src/lib/Registry/GitHub/tag.schema.js diff --git a/src/bin/commands/helloworld.js b/src/bin/commands/helloworld.js index 5def3214..bb16d748 100644 --- a/src/bin/commands/helloworld.js +++ b/src/bin/commands/helloworld.js @@ -6,25 +6,32 @@ 'use strict'; module.exports = function(dumpPath) { - - // @todo: put it anywhere in a config - var helloWorldRepoUrl = 'https://github.com/MitocGroup/deep-microservices-helloworld.git'; - + var path = require('path'); + var fse = require('fs-extra'); var Exec = require('../../lib.compiled/Helpers/Exec').Exec; var Bin = require('../../lib.compiled/NodeJS/Bin').Bin; + if (dumpPath.indexOf(path.sep) !== 0) { + dumpPath = path.join(process.cwd(), dumpPath); + } + var cmd = new Exec( Bin.node, this.scriptPath, 'install', - helloWorldRepoUrl, - dumpPath + 'github://MitocGroup/deep-microservices-helloworld', + '--init', + '--skip-github-deps' ); + fse.ensureDirSync(dumpPath); + + cmd.cwd = dumpPath; + cmd.run(function(result) { if (result.failed) { console.error(result.error); this.exit(1); } - }, true); + }.bind(this), true); }; diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index 0ce551c4..2f3031cb 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -10,7 +10,7 @@ module.exports = function(dependency) { // @todo: move it in config? var DEFAULT_REGISTRY_BASE_HOST = 'https://deep.mg'; - var GitHubDependency = require('../../lib.compiled/Registry/GitHub/Dependency').Dependency; + var GitHubDependency = require('deep-package-manager').Registry_GitHub_Dependency; var AuthToken = require('../../lib.compiled/Registry/AuthToken').AuthToken; var Property = require('deep-package-manager').Property_Instance; var PropertyConfig = require('deep-package-manager').Property_Config; @@ -23,6 +23,7 @@ module.exports = function(dependency) { var workingDirectory = process.cwd(); var registryBaseHost = this.opts.locate('registry').value || DEFAULT_REGISTRY_BASE_HOST; + var skipGitHubDeps = this.opts.locate('skip-github-deps').exists; var initApp = this.opts.locate('init').exists; var depParts = parseDep(); var depName = depParts[0]; @@ -37,7 +38,7 @@ module.exports = function(dependency) { this.exit(1); } - console.log(`The microservice '${depName}' has been successfully installed`); + console.log('The microservice \'' + depName + '\' has been successfully installed'); initBackend.bind(this)(); }.bind(this)); @@ -144,10 +145,15 @@ module.exports = function(dependency) { this.exit(1); } + if (skipGitHubDeps) { + cb.bind(this)(); + return; + } + var microservice = Microservice.create(dumpPath); createRegistry.bind(this)(function(registry) { - console.log(`Installing '${depObj.shortDependencyName}' dependencies`); + console.log('Installing \'' + depObj.shortDependencyName + '\' dependencies'); registry.install(createProperty(), function(error) { if (error) { diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 00a7d18b..9cfc2d0f 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -40,6 +40,11 @@ module.exports = { description: 'Custom registry url (ex. https://deep.mg)', required: false, }, + 'skip-github-deps': { + alias: 's', + description: 'Skip fetching dependencies when working with a GitHub hosted microservice', + required: false, + }, }, args: { dependency: { diff --git a/src/lib/Registry/GitHub/Dependency.js b/src/lib/Registry/GitHub/Dependency.js deleted file mode 100644 index a51a33c1..00000000 --- a/src/lib/Registry/GitHub/Dependency.js +++ /dev/null @@ -1,281 +0,0 @@ -/** - * Created by AlexanderC on 2/19/16. - */ - -'use strict'; - -import request from 'fetchy-request'; -import {Tag} from './Tag'; -import {Registry_Resolver_Strategy_SemVerStrategy as SemVerStrategy} from 'deep-package-manager'; -import tar from 'tar-stream'; -import gunzip from 'gunzip-maybe'; -import {Helpers_WaitFor as WaitFor} from 'deep-package-manager'; -import {StandardStrategy} from './ExtractStrategy/StandardStrategy'; - -export class Dependency { - /** - * @param {String} dependencyName - * @param {String} dependencyVersion - */ - constructor(dependencyName, dependencyVersion) { - this._dependencyName = dependencyName; - this._dependencyVersion = dependencyVersion; - - this._repository = Dependency.parseDependencyRepository(dependencyName); - - if (!this._repository) { - throw new Error(`Unable to parse GitHub repository ${this.shortDependencyName}`); - } - - Dependency.__cache__ = []; - } - - /** - * @param {String} dumpPath - * @param {Function} cb - * @param {AbstractStrategy|StandardStrategy|*} extractStrategy - */ - extract(dumpPath, cb, extractStrategy = null) { - console.log(`Searching for suitable '${this.shortDependencyName}' dependency version`); - - this.findSuitableTag((error, tag) => { - if (error) { - cb(error); - return; - } - - console.log(`Fetching suitable '${this.shortDependencyName}' dependency version from '${tag.sourceUrl}'`); - - request(Dependency._createRequestPayload(Dependency._normalizeSourceUrl(tag.sourceUrl))) - .then((response) => { - if (!response.ok) { - cb(response._error || new Error(response.statusText)); - return; - } - - console.log(`Dumping '${this.shortDependencyName}' dependency into '${dumpPath}'`); - - extractStrategy = extractStrategy || new StandardStrategy(dumpPath); - - let unTarStream = tar.extract(); - - let wait = new WaitFor(); - let filesToExtract = 0; - - wait.push(() => { - return filesToExtract <= 0; - }); - - unTarStream.on('entry', (header, stream, next) => { - if (header.type === 'directory') { - next(); - return; - } - - filesToExtract++; - - let filePath = header.name.replace(/^([^\/]+\/)/, ''); - - extractStrategy.extract(filePath, stream, () => { - filesToExtract--; - - next(); - }); - }); - - unTarStream.on('finish', () => { - wait.ready(cb); - }); - - response.body - .pipe(gunzip()) - .pipe(unTarStream); - - }).catch(cb); - }); - } - - /** - * @param {Function} cb - */ - findSuitableTag(cb) { - if (Dependency.__cache__.hasOwnProperty(this._repository)) { - console.log(`Using GitHub repository '${this._repository}' tags from cache`); - - cb(...this._findSuitable(Dependency.__cache__[this._repository])); - return; - } - - console.log(`Fetching GitHub repository '${this._repository}' tags`); - - this.getAvailableTags((error, tags) => { - if (error) { - cb(error, null); - return; - } - - Dependency.__cache__[this._repository] = tags; - - cb(...this._findSuitable(tags)); - }); - } - - /** - * @param {Tag[]} tags - * @returns {Array} - * @private - */ - _findSuitable(tags) { - let semverStrategy = new SemVerStrategy(); - let versions = tags.map((tag) => tag.name); - - let matchedVersion = semverStrategy.resolve({ - getVersions: () => versions, - }, this._dependencyVersion); - - if (!matchedVersion) { - return [ - new Error( - `No suitable version found for '${this.shortDependencyName}@${this._dependencyVersion}' (${versions.join(', ')})` - ), - null - ]; - } - - for (let i in tags) { - if (!tags.hasOwnProperty(i)) { - continue; - } - - let tag = tags[i]; - - if (SemVerStrategy.CLEAN_FUNC(tag.name) === matchedVersion) { - return [null, tag]; - } - } - } - - /** - * @param {Function} cb - */ - getAvailableTags(cb) { - request(Dependency._createRequestPayload(Dependency.TAGS_URI_TPL.replace(/\{repository\}/i, this._repository))) - .then((response) => { - if (!response.ok) { - cb(response._error || new Error(response.statusText), null); - return; - } - - response - .text() - .then((plainData) => { - try { - cb(null, Tag.createFromMetadataVector(this._repository, JSON.parse(plainData))); - } catch (error) { - cb(error, null); - } - }) - .catch((error) => { - cb(error, null); - }); - }).catch((error) => { - cb(error, null); - }); - } - - /** - * @returns {String} - */ - get shortDependencyName() { - return this._repository.split('/')[1]; - } - - /** - * @returns {String} - */ - get dependencyName() { - return this._dependencyName; - } - - /** - * @returns {String} - */ - get dependencyVersion() { - return this._dependencyVersion; - } - - /** - * @returns {String|*} - */ - get repository() { - return this._repository; - } - - - /** - * @param {String} sourceUrl - * @returns {String} - * @private - * - * @example https://codeload.github.com/MitocGroup/deep-microservices-todo-app/legacy.tar.gz/v0.0.1 - * ----> - * https://api.github.com/repos/MitocGroup/deep-microservices-todo-app/tarball/v0.0.1 - */ - static _normalizeSourceUrl(sourceUrl) { - let matches = sourceUrl.match(/https?:\/\/api\.github\.com\/repos\/([^\/]+\/[^\/]+)\/tarball\/([^\/]+)$/i); - - if (!matches || matches.length < 3) { - return sourceUrl; - } - - let repo = matches[1]; - let version = matches[2]; - - return `https://codeload.github.com/${repo}/legacy.tar.gz/${version}`; - } - - /** - * @param {String} uri - * @returns {Object} - */ - static _createRequestPayload(uri) { - return { - uri: uri, - method: 'GET', - retry: 3, - headers: { - 'User-Agent': 'User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.56 (KHTML, like Gecko) Version/9.0 Safari/601.1.56', - Accept: '*/*', - }, - }; - } - - /** - * @param {String} dependencyName - * @returns {Boolean} - */ - static isGitHubDependency(dependencyName) { - return !!Dependency.parseDependencyRepository(dependencyName); - } - - /** - * @param {String} dependencyName - * @returns {String|null} - */ - static parseDependencyRepository(dependencyName) { - let repo = dependencyName.match(/^github:\/\/([^\/]+\/[^\/]+)$/i); - - if (repo && repo.length === 2) { - return repo[1].toString(); - } - - return null; - } - - /** - * @returns {String} - */ - static get TAGS_URI_TPL() { - return 'https://api.github.com/repos/{repository}/tags'; - } -} diff --git a/src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js b/src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js deleted file mode 100644 index 978f4d67..00000000 --- a/src/lib/Registry/GitHub/Exception/InvalidTagMetadataException.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Created by AlexanderC on 2/19/16. - */ - -'use strict'; - -import {Exception} from '../../../Exception/Exception'; - -export class InvalidTagMetadataException extends Exception { - /** - * @param {String|Error|*} error - */ - constructor(error) { - super(`Invalid tag metadata: ${error}`); - } -} diff --git a/src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js b/src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js deleted file mode 100644 index 14de6c87..00000000 --- a/src/lib/Registry/GitHub/ExtractStrategy/AbstractStrategy.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Created by AlexanderC on 2/19/16. - */ - -'use strict'; - -import Core from 'deep-core'; - -export class AbstractStrategy extends Core.OOP.Interface { - /** - * @param {String} dumpPath - */ - constructor(dumpPath) { - super(['extract']); - - this._dumpPath = dumpPath; - } - - /** - * @returns {String} - */ - get dumpPath() { - return this._dumpPath; - } -} diff --git a/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js b/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js deleted file mode 100644 index d1e37a4b..00000000 --- a/src/lib/Registry/GitHub/ExtractStrategy/StandardStrategy.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Created by AlexanderC on 2/19/16. - */ - -'use strict'; - -import {AbstractStrategy} from './AbstractStrategy'; -import path from 'path'; -import fse from 'fs-extra'; - -export class StandardStrategy extends AbstractStrategy { - /** - * @param {*} args - */ - constructor(...args) { - super(...args); - } - - /** - * @param {String} filePath - * @param {Stream|Writable|Readable|stream.Readable|stream.Writable|*} stream - * @param {Function} cb - */ - extract(filePath, stream, cb) { - if (!StandardStrategy._haveToDump(filePath)) { - cb(); - return; - } - - let file = path.join(this.dumpPath, StandardStrategy._normalizeFilePath(filePath)); - let output = fse.createOutputStream(file); - - output.on('finish', cb); - - stream.pipe(output); - } - - /** - * @param {String} filePath - * @returns {String} - * @private - */ - static _normalizeFilePath(filePath) { - return filePath.replace(/^(\/?src\/[^\/]+\/)/i, ''); - } - - /** - * @param {String} filePath - * @returns {Boolean} - * @private - */ - static _haveToDump(filePath) { - return /^\/?src\/[A-Z][^\/]+\//.test(filePath); - } -} diff --git a/src/lib/Registry/GitHub/Tag.js b/src/lib/Registry/GitHub/Tag.js deleted file mode 100644 index d53eae43..00000000 --- a/src/lib/Registry/GitHub/Tag.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Created by AlexanderC on 2/19/16. - */ - -'use strict'; - -import {TagMetadata} from './TagMetadata'; - -export class Tag { - /** - * @param {String} repository - * @param {String} name - * @param {String} sourceUrl - */ - constructor(repository, name, sourceUrl) { - this._repository = repository; - this._name = name; - this._sourceUrl = sourceUrl; - } - - /** - * @param {String} repository - * @param {Object[]} tagMetadataVector - * @param {Boolean} failSilently - * @returns {Array} - */ - static createFromMetadataVector(repository, tagMetadataVector, failSilently = true) { - let tags = []; - - for (let tagMetadata in tagMetadataVector) { - if (!tagMetadataVector.hasOwnProperty(tagMetadata)) { - continue; - } - - try { - tags.push(Tag.createFromRawMetadata(repository, tagMetadataVector[tagMetadata])); - } catch (error) { - if (!failSilently) { - throw error; - } - } - } - - return tags; - } - - /** - * @param {String} repository - * @param {Object} rawTagMetadata - * @returns {Tag} - */ - static createFromRawMetadata(repository, rawTagMetadata) { - let metadata = (new TagMetadata(rawTagMetadata)).extract(); - - return new Tag(repository, metadata.name, metadata.tarball_url); - } - - /** - * @returns {String} - */ - get repository() { - return this._repository; - } - - /** - * @returns {String} - */ - get name() { - return this._name; - } - - /** - * @returns {String} - */ - get sourceUrl() { - return this._sourceUrl; - } -} diff --git a/src/lib/Registry/GitHub/TagMetadata.js b/src/lib/Registry/GitHub/TagMetadata.js deleted file mode 100644 index ac06ff05..00000000 --- a/src/lib/Registry/GitHub/TagMetadata.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Created by AlexanderC on 2/19/16. - */ - -'use strict'; - -import tagSchema from './tag.schema'; -import {InvalidTagMetadataException} from './Exception/InvalidTagMetadataException'; -import Joi from 'joi'; - -export class TagMetadata { - /** - * @param {Object} tagMetadata - */ - constructor(tagMetadata) { - this._tagMetadata = tagMetadata; - - this._parsedTagMetadata = Joi.validate(tagMetadata, tagSchema); - } - - /** - * @returns {Object} - */ - get rawMetadata() { - return this._tagMetadata; - } - - /** - * @returns {Boolean} - */ - get valid() { - return !this.error; - } - - /** - * @returns {String} - */ - get error() { - return this._parsedTagMetadata.error; - } - - /** - * @returns {Object} - */ - extract() { - if (!this.valid) { - throw new InvalidTagMetadataException(this.error); - } - - return this._parsedTagMetadata.value; - } -} diff --git a/src/lib/Registry/GitHub/tag.schema.js b/src/lib/Registry/GitHub/tag.schema.js deleted file mode 100644 index 4b3c6425..00000000 --- a/src/lib/Registry/GitHub/tag.schema.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Created by AlexanderC on 2/19/16. - */ - -/** - * Created by AlexanderC on 5/25/15. - */ - -'use strict'; - -import Joi from 'joi'; - -export default Joi.object().keys({ - name: Joi.string().required(), - zipball_url: Joi.string().uri().required(), - tarball_url: Joi.string().uri().required(), - commit: Joi.object().keys({ - sha: Joi.string().regex(/^[a-z0-9]+$/i).required(), - url: Joi.string().uri().required(), - }), -}); diff --git a/src/package.json b/src/package.json index 214f311a..55b0567a 100644 --- a/src/package.json +++ b/src/package.json @@ -68,11 +68,7 @@ "aws-api-gw-client": "^0.1.x", "mime": "^1.3.x", "gather-dependencies": "^1.0.x", - "aws-sdk": "^2.2.x", - "fetchy-request": "^0.8.x", - "joi": "^6.4.x", - "tar-stream": "^1.3.x", - "gunzip-maybe": "^1.3.1" + "aws-sdk": "^2.2.x" }, "devDependencies": { "chai": "^3.2.x", From 4429b25b391293a887b63100c7af95cb8585f0e4 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 22 Feb 2016 13:55:18 +0200 Subject: [PATCH 117/133] Add registry configuration --- src/bin/commands/install.js | 10 +- src/bin/commands/registry-cfg.js | 39 ++++++++ src/bin/manifest.js | 22 +++++ src/lib/Registry/AuthToken.js | 37 +------- src/lib/Registry/Config.js | 157 +++++++++++++++++++++++++++++-- src/lib/Registry/ConfigVars.js | 54 +++++++++++ 6 files changed, 276 insertions(+), 43 deletions(-) create mode 100644 src/bin/commands/registry-cfg.js create mode 100644 src/lib/Registry/ConfigVars.js diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index 2f3031cb..2485a181 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -7,11 +7,12 @@ module.exports = function(dependency) { - // @todo: move it in config? + // @todo: move it in some json config? var DEFAULT_REGISTRY_BASE_HOST = 'https://deep.mg'; var GitHubDependency = require('deep-package-manager').Registry_GitHub_Dependency; var AuthToken = require('../../lib.compiled/Registry/AuthToken').AuthToken; + var RegistryConfig = require('../../lib.compiled/Registry/Config').Config; var Property = require('deep-package-manager').Property_Instance; var PropertyConfig = require('deep-package-manager').Property_Config; var Registry = require('deep-package-manager').Registry_Registry; @@ -21,8 +22,11 @@ module.exports = function(dependency) { var Microservice = require('deep-package-manager').Microservice_Instance; var path = require('path'); + var registryBaseHost = this.opts.locate('registry').value || + RegistryConfig.create().refresh('registry').read('registry') || + DEFAULT_REGISTRY_BASE_HOST; + var workingDirectory = process.cwd(); - var registryBaseHost = this.opts.locate('registry').value || DEFAULT_REGISTRY_BASE_HOST; var skipGitHubDeps = this.opts.locate('skip-github-deps').exists; var initApp = this.opts.locate('init').exists; var depParts = parseDep(); @@ -79,7 +83,7 @@ module.exports = function(dependency) { registry.storage.driver.authorizer = RegistryAuthorizer.createHeaderToken(getRegistryToken()); cb(registry); - }.bind(this)); + }.bind(this), true); } function parseDep() { diff --git a/src/bin/commands/registry-cfg.js b/src/bin/commands/registry-cfg.js new file mode 100644 index 00000000..2c904857 --- /dev/null +++ b/src/bin/commands/registry-cfg.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node +/** + * Created by AlexanderC on 8/4/15. + */ + +'use strict'; + +module.exports = function(parameter) { + var RegistryConfig = require('../../lib.compiled/Registry/Config').Config; + + this.constructor._logDriver.overrideJsConsole(false); + + parameter = parameter || 'unknown'; + var newValue = this.opts.locate('set').value; + var printAvailable = this.opts.locate('print').exists; + var config = RegistryConfig.create().refresh(parameter); + + if (printAvailable) { + console.log(Object.keys((new RegistryConfig()).varsMapper.MAPPING).join(', ')); + } else if (newValue) { + console.log('Setting new value of parameter "' + parameter + '"'); + + config.add(parameter, newValue); + + try { + config.persist(); + } catch (error) { + console.error('Failed to set new value of parameter "' + parameter + '": ' + error); + this.exit(1); + } + } else { + if (!config.has(parameter)) { + console.error('Missing parameter "' + parameter + '" in config'); + this.exit(1); + } + + console.log(config.read(parameter)); + } +}; diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 9cfc2d0f..b08a8787 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -178,6 +178,28 @@ module.exports = { }, }, }, + 'registry-cfg': { + example: 'deepify registry-cfg token --set "some_custom_auth_token"', + description: 'Read/Set the registry configuration value (read unless called with --set)', + opts: { + set: { + alias: 's', + description: 'Set the registry parameter to the value given', + required: false, + }, + print: { + alias: 'p', + description: 'Print available registry parameters', + required: false, + }, + }, + args: { + parameter: { + description: 'Registry configuration parameter name', + required: false, + }, + }, + }, 'enable-ssl': { example: 'deepify enable-ssl path/to/web_app', description: 'Enables SSL on a deployed web app', diff --git a/src/lib/Registry/AuthToken.js b/src/lib/Registry/AuthToken.js index 047b8c26..924b2082 100644 --- a/src/lib/Registry/AuthToken.js +++ b/src/lib/Registry/AuthToken.js @@ -25,43 +25,14 @@ export class AuthToken { * @returns {AuthToken} */ refresh() { - this._token = AuthToken._fromGlobal || - AuthToken._fromEnvVar || - AuthToken._fromConfigFile || - 'ANON'; + this._token = Config + .create() + .refresh(AuthToken.TOKEN_VAR_NAME) + .read(AuthToken.TOKEN_VAR_NAME) || 'ANON'; return this; } - /** - * @returns {String|null} - * @private - */ - static get _fromEnvVar() { - return process.env[AuthToken.TOKEN_VAR_NAME]; - } - - /** - * @returns {String|null} - * @private - */ - static get _fromGlobal() { - return global[AuthToken.TOKEN_VAR_NAME]; - } - - /** - * @returns {String|null} - * @private - */ - static get _fromConfigFile() { - try { - let config = Config.create(); - - return config[AuthToken.TOKEN_VAR_NAME]; - } catch (error) { - } - } - /** * @returns {String} */ diff --git a/src/lib/Registry/Config.js b/src/lib/Registry/Config.js index 5c82cf9a..f069cdce 100644 --- a/src/lib/Registry/Config.js +++ b/src/lib/Registry/Config.js @@ -7,30 +7,173 @@ import os from 'os'; import path from 'path'; import fse from 'fs-extra'; +import fs from 'fs'; +import {ConfigVars} from './ConfigVars'; +import {_extend as extend} from 'util'; import {Registry_Storage_Driver_Helpers_Api_RegistryAutoDiscovery as RegistryAutoDiscovery} from 'deep-package-manager'; export class Config { /** - * @param {Object|null} config + * @param {Object} config */ - constructor(config = null) { + constructor(config = {}) { this._config = config; + this._varsMapper = ConfigVars; } /** + * @param {String[]|String|*} readFromGlobalsNames * @returns {Config} */ - static create() { - return new Config(fse.readJsonSync(Config.CONFIG_FILE)); + refresh(...readFromGlobalsNames) { + let envConfig = this._config; + let fileConfig = {}; + + readFromGlobalsNames.forEach((name) => { + let value = this._readVarFromEnvVar(name) || + this._readVarFromGlobal(name); + + if (value) { + envConfig[this._varsMapper.map(name)] = value; + } + }); + + let configFile = Config.CONFIG_FILE; + + if (fs.existsSync(configFile)) { + fileConfig = fse.readJsonSync(configFile); + } + + this._config = extend(this._config, envConfig, fileConfig); + + return this; + } + + /** + * @returns {Config} + */ + persist() { + fse.outputJsonSync(Config.CONFIG_FILE, this._config); + + return this; + } + + /** + * @param {String} name + * @param {*} value + * @returns {Config} + */ + add(name, value) { + this._config[this._varsMapper.map(name)] = value; + + return this; + } + + /** + * @param {String} name + * @returns {Boolean} + */ + has(name) { + return this._config.hasOwnProperty(this._varsMapper.map(name)); + } + + /** + * @returns {*} + */ + read(name) { + return this._config[this._varsMapper.map(name)]; + } + + /** + * @param {String} name + * @returns {Config} + */ + unset(name) { + delete this._config[this._varsMapper.map(name)]; + + return this; + } + + /** + * @param {String} name + * @returns {*} + * @private + */ + _readVarFromEnvVar(name) { + return process.env[this._varsMapper.unMap(name)]; + } + + /** + * @param {String} name + * @returns {*} + * @private + */ + _readVarFromGlobal(name) { + return global[this._varsMapper.unMap(name)]; + } + + /** + * @returns {ConfigVars|Object} + */ + get varsMapper() { + return this._varsMapper; + } + + /** + * @param {ConfigVars|Object} mapper + */ + set varsMapper(mapper) { + this._varsMapper = mapper; + } + + /** + * @returns {Object} + */ + get rawConfig() { + return this._config; + } + + /** + * @returns {Object} + */ + get config() { + let conf = {}; + + for (let name in this._config) { + if (!this._config.hasOwnProperty(name)) { + continue; + } + + conf[this._varsMapper.unMap(name)] = this._config[name]; + } + + return conf; + } + + /** + * @param {Boolean} createIfMissing + * @returns {Config} + */ + static create(createIfMissing = true) { + let configFile = Config.CONFIG_FILE; + let config = {}; + + if (!fs.existsSync(configFile)) { + if (createIfMissing) { + fse.outputJsonSync(configFile, config); + } + } else { + config = fse.readJsonSync(configFile); + } + + return new Config(config); } /** * @returns {String} */ static get CONFIG_FILE() { - let dir = path.dirname(RegistryAutoDiscovery.DEFAULT_CACHE_FILE); - - return path.join(dir, Config.CONFIG_FILE_NAME); + return path.join(RegistryAutoDiscovery.DEFAULT_CONFIG_DIR, Config.CONFIG_FILE_NAME); } /** diff --git a/src/lib/Registry/ConfigVars.js b/src/lib/Registry/ConfigVars.js new file mode 100644 index 00000000..cd10c82a --- /dev/null +++ b/src/lib/Registry/ConfigVars.js @@ -0,0 +1,54 @@ +/** + * Created by AlexanderC on 2/22/16. + */ + +'use strict'; + +import {AuthToken} from './AuthToken'; + +export class ConfigVars { + + /** + * @param {String} name + * @returns {String} + */ + static map(name) { + return ConfigVars.REVERSED_MAPPING[name] || name; + } + + /** + * @param {String} name + * @returns {String} + */ + static unMap(name) { + return ConfigVars.MAPPING[name] || name; + } + + /** + * @returns {Object} + */ + static get REVERSED_MAPPING() { + let mapping = ConfigVars.MAPPING; + let obj = {}; + + for (let name in mapping) { + if (!mapping.hasOwnProperty(name)) { + continue; + } + + obj[mapping[name]] = name; + } + + return obj; + } + + /** + * @returns {Object} + */ + static get MAPPING() { + return { + token: AuthToken.TOKEN_VAR_NAME, // DEEP_REGISTRY_AUTH_TOKEN + registry: 'DEEP_REGISTRY_BASE_HOST', + }; + } +} From 58003afead5980465691ff39276b67c8ce8b09f0 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 22 Feb 2016 14:04:28 +0200 Subject: [PATCH 118/133] Small changes --- src/bin/commands/registry-cfg.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/commands/registry-cfg.js b/src/bin/commands/registry-cfg.js index 2c904857..2e3bf309 100644 --- a/src/bin/commands/registry-cfg.js +++ b/src/bin/commands/registry-cfg.js @@ -8,14 +8,13 @@ module.exports = function(parameter) { var RegistryConfig = require('../../lib.compiled/Registry/Config').Config; - this.constructor._logDriver.overrideJsConsole(false); - parameter = parameter || 'unknown'; var newValue = this.opts.locate('set').value; var printAvailable = this.opts.locate('print').exists; var config = RegistryConfig.create().refresh(parameter); if (printAvailable) { + resetDeepLog.bind(this)(); console.log(Object.keys((new RegistryConfig()).varsMapper.MAPPING).join(', ')); } else if (newValue) { console.log('Setting new value of parameter "' + parameter + '"'); @@ -34,6 +33,11 @@ module.exports = function(parameter) { this.exit(1); } + resetDeepLog.bind(this)(); console.log(config.read(parameter)); } + + function resetDeepLog() { + this.constructor._logDriver.overrideJsConsole(false); + } }; From 073e9d6b9892845d7126cce6301715c400525da9 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 22 Feb 2016 14:39:45 +0200 Subject: [PATCH 119/133] Add github auth --- src/bin/commands/install.js | 15 +++++++++++++++ src/bin/manifest.js | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index 2485a181..5e3fc30f 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -28,6 +28,7 @@ module.exports = function(dependency) { var workingDirectory = process.cwd(); var skipGitHubDeps = this.opts.locate('skip-github-deps').exists; + var gitHubAuthPair = this.opts.locate('github-auth').value; var initApp = this.opts.locate('init').exists; var depParts = parseDep(); var depName = depParts[0]; @@ -139,6 +140,20 @@ module.exports = function(dependency) { console.log('Fetching microservice from GitHub'); var depObj = new GitHubDependency(depName, depVersion); + + // @todo: move logic into GitHubDependency? + if (gitHubAuthPair) { + var gitHubCred = gitHubAuthPair.split(':'); + + if (gitHubCred.length === 1) { + + // @todo: read git user followed by this fallback? + gitHubCred.unshift(depObj.shortDependencyName); + } + + depObj.auth(gitHubCred[0], gitHubCred[1]); + } + var dumpPath = path.join(workingDirectory, depObj.shortDependencyName); depObj.extract( diff --git a/src/bin/manifest.js b/src/bin/manifest.js index b08a8787..2319e3b2 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -40,6 +40,11 @@ module.exports = { description: 'Custom registry url (ex. https://deep.mg)', required: false, }, + 'github-auth': { + alias: 'a', + description: 'GitHub credentials pair used for Basic authentication (ex. "user:token" or simply "token")', + required: false, + }, 'skip-github-deps': { alias: 's', description: 'Skip fetching dependencies when working with a GitHub hosted microservice', From 9d5b6d1d664c101ddd639d5f01a5226c18047d41 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 22 Feb 2016 19:24:10 +0200 Subject: [PATCH 120/133] Add github private repos --- src/bin/commands/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/commands/install.js b/src/bin/commands/install.js index 5e3fc30f..a19e6828 100644 --- a/src/bin/commands/install.js +++ b/src/bin/commands/install.js @@ -148,7 +148,7 @@ module.exports = function(dependency) { if (gitHubCred.length === 1) { // @todo: read git user followed by this fallback? - gitHubCred.unshift(depObj.shortDependencyName); + gitHubCred.unshift(depObj.repositoryUser); } depObj.auth(gitHubCred[0], gitHubCred[1]); From 369fe4b2234e596c9ffe81577d1e2b1af1b5c788 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 23 Feb 2016 19:03:56 +0200 Subject: [PATCH 121/133] Implement module publishing --- src/bin/commands/publish.js | 123 ++++++++++++++++++++++++++++++++++++ src/bin/manifest.js | 17 +++++ src/bin/registry-server.js | 43 +++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 src/bin/commands/publish.js create mode 100755 src/bin/registry-server.js diff --git a/src/bin/commands/publish.js b/src/bin/commands/publish.js new file mode 100644 index 00000000..bfa97f94 --- /dev/null +++ b/src/bin/commands/publish.js @@ -0,0 +1,123 @@ +#!/usr/bin/env node +/** + * Created by AlexanderC on 8/4/15. + */ + +'use strict'; + +module.exports = function(microservicePath) { + + // @todo: move it in some json config? + var DEFAULT_REGISTRY_BASE_HOST = 'https://deep.mg'; + var SAMPLE_PROPERTY_CONFIG = { + appIdentifier: 'appIdentifier', + env: 'prod', + awsAccountId: '0000000000', + aws: { + accessKeyId: 'accessKeyId', + secretAccessKey: 'secretAccessKey', + region: 'us-east-1', + }, + }; + + var path = require('path'); + var fs = require('fs'); + var fse = require('fs-extra'); + var tmp = require('tmp'); + var AuthToken = require('../../lib.compiled/Registry/AuthToken').AuthToken; + var RegistryConfig = require('../../lib.compiled/Registry/Config').Config; + var Registry = require('deep-package-manager').Registry_Registry; + var RegistryAuthorizer = require('deep-package-manager').Registry_Storage_Driver_Helpers_Api_Auth_Authorizer; + var Microservice = require('deep-package-manager').Microservice_Instance; + var LambdaExtractor = require('../../lib.compiled/Helpers/LambdasExtractor').LambdasExtractor; + var Property = require('deep-package-manager').Property_Instance; + var Config = require('deep-package-manager').Property_Config; + var Lambda = require('deep-package-manager').Property_Lambda; + var Core = require('deep-core'); + + var registryBaseHost = this.opts.locate('registry').value || + RegistryConfig.create().refresh('registry').read('registry') || + DEFAULT_REGISTRY_BASE_HOST; + + if (microservicePath.indexOf(path.sep) !== 0) { + microservicePath = path.join(process.cwd(), microservicePath); + } + + var tmpDirObj = tmp.dirSync(); + var tmpPropertyPath = tmpDirObj.name; + var tmpMicroservicePath = path.join(tmpPropertyPath, path.basename(microservicePath)); + + // Gracefully teardown... + (function() { + process.on('uncaughtException', function(error) { + console.error(error); + fse.removeSync(tmpPropertyPath); + this.exit(1); + }.bind(this)); + + process.on('SIGINT', function() { + console.log('Gracefully shutting down from SIGINT (Ctrl-C)...'); + fse.removeSync(tmpPropertyPath); + this.exit(1); + }.bind(this)); + }.bind(this))(); + + console.log('Copying microservice sources into ' + tmpMicroservicePath); + fse.copySync(microservicePath, tmpMicroservicePath); + + var propertyConfigFile = path.join(tmpPropertyPath, Config.DEFAULT_FILENAME); + console.log('Persisting temporary property config in ' + propertyConfigFile); + fse.outputJsonSync(propertyConfigFile, SAMPLE_PROPERTY_CONFIG); + + createRegistry.bind(this)(function(registry) { + registry.publishModule(tmpMicroservicePath, function(error) { + fse.removeSync(tmpPropertyPath); + + if (error) { + console.error('Error publishing microservice: ' + error); + this.exit(1); + } + + console.log('Microservice has been successfully published'); + }.bind(this)); + }.bind(this)); + + function getRegistryToken() { + return (new AuthToken()).refresh().toString(); + } + + var property = new Property(tmpPropertyPath); + + console.log('Cleaning up microservice'); + + console.log('Remove custom parameters and tests'); + fse.removeSync(path.join(microservicePath, Microservice.PARAMS_FILE)); + fse.removeSync(path.join(microservicePath, 'Tests')); + + (new LambdaExtractor(property)) + .extractWorking(LambdaExtractor.NPM_PACKAGE_FILTER) + .forEach(function(lambdaPath) { + console.log('Cleaning up backend in ' + lambdaPath); + + fse.removeSync(path.join(lambdaPath, '.DS_Store')); //@todo: do we need this case covered? + fse.removeSync(path.join(lambdaPath, 'node_modules')); + fse.removeSync(path.join(lambdaPath, Core.AWS.Lambda.Runtime.VALIDATION_SCHEMAS_DIR)); + fse.removeSync(path.join(lambdaPath, Lambda.CONFIG_FILE)); + }.bind(this)); + + function createRegistry(cb) { + console.log('Initializing remote registry'); + + Registry.createApiRegistry(registryBaseHost, function(error, registry) { + if (error) { + console.error(error); + fse.removeSync(tmpPropertyPath); + this.exit(1); + } + + registry.storage.driver.authorizer = RegistryAuthorizer.createHeaderToken(getRegistryToken()); + + cb(registry); + }.bind(this), true); + } +}; diff --git a/src/bin/manifest.js b/src/bin/manifest.js index 2319e3b2..7c98ca85 100644 --- a/src/bin/manifest.js +++ b/src/bin/manifest.js @@ -183,6 +183,23 @@ module.exports = { }, }, }, + publish: { + example: 'deepify publish ./sample-microservice', + description: 'Publish microservice (may require manual approval before getting public)', + opts: { + registry: { + alias: 'r', + description: 'Custom registry url (ex. https://deep.mg)', + required: false, + }, + }, + args: { + path: { + description: 'The path to the microservice you want to publish', + required: true, + }, + }, + }, 'registry-cfg': { example: 'deepify registry-cfg token --set "some_custom_auth_token"', description: 'Read/Set the registry configuration value (read unless called with --set)', diff --git a/src/bin/registry-server.js b/src/bin/registry-server.js new file mode 100755 index 00000000..55bdfbd2 --- /dev/null +++ b/src/bin/registry-server.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node +/** + * Created by AlexanderC on 2/23/16. + */ + +var input = process.argv; +input.shift(); +input.shift(); + +var RegistryServer = require('deep-package-manager').Registry_Local_Server; +var path = require('path'); + +var serverPath = path.join(process.cwd(), '.deepRegistry'); + +if (input.length > 0) { + serverPath = input[0]; + + if (serverPath.indexOf(path.sep) !== 0) { + serverPath = path.join(process.cwd(), serverPath); + } +} + +var server = new RegistryServer(serverPath); + +server.start(function(error) { + if (error) { + console.error(error); + process.exit(1); + } + + console.log('--->', RegistryServer.DEFAULT_REGISTRY_HOST); + console.info('\nPress Ctrl-C to stop the server'); +}); + +process.on('uncaughtException', function(error) { + server.stop(); + console.error(error); + process.exit(1); +}); + +process.on('SIGINT', function() { + server.stop(); +}); From fac8dc41d778da333263101c5166063e721145e2 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Tue, 23 Feb 2016 19:15:02 +0200 Subject: [PATCH 122/133] Implement module publishing --- src/bin/commands/publish.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/commands/publish.js b/src/bin/commands/publish.js index bfa97f94..e510bf49 100644 --- a/src/bin/commands/publish.js +++ b/src/bin/commands/publish.js @@ -99,7 +99,6 @@ module.exports = function(microservicePath) { .forEach(function(lambdaPath) { console.log('Cleaning up backend in ' + lambdaPath); - fse.removeSync(path.join(lambdaPath, '.DS_Store')); //@todo: do we need this case covered? fse.removeSync(path.join(lambdaPath, 'node_modules')); fse.removeSync(path.join(lambdaPath, Core.AWS.Lambda.Runtime.VALIDATION_SCHEMAS_DIR)); fse.removeSync(path.join(lambdaPath, Lambda.CONFIG_FILE)); From e602663ad424810a6aa7f17dd74fac0f509ae9e2 Mon Sep 17 00:00:00 2001 From: mgoria Date: Wed, 24 Feb 2016 12:28:43 +0200 Subject: [PATCH 123/133] Release new patch version --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 55b0567a..2b9ded3e 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.14", + "version": "1.6.15", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 64dd3aef59b4735b226e89726b26979ae484c4ca Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Thu, 25 Feb 2016 16:13:00 +0200 Subject: [PATCH 124/133] Remove unused dep --- src/bin/commands/publish.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/commands/publish.js b/src/bin/commands/publish.js index e510bf49..9535e199 100644 --- a/src/bin/commands/publish.js +++ b/src/bin/commands/publish.js @@ -21,7 +21,6 @@ module.exports = function(microservicePath) { }; var path = require('path'); - var fs = require('fs'); var fse = require('fs-extra'); var tmp = require('tmp'); var AuthToken = require('../../lib.compiled/Registry/AuthToken').AuthToken; From ff32f3ee1e6b4e52f8421ca985a8c6b0b74cf310 Mon Sep 17 00:00:00 2001 From: mgoria Date: Thu, 25 Feb 2016 16:52:30 +0200 Subject: [PATCH 125/133] Publish new patch version --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 2b9ded3e..034fb0bc 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.15", + "version": "1.6.16", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From aa3fb95299c820e68016760e37f9da82da069da0 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Thu, 25 Feb 2016 17:12:23 +0200 Subject: [PATCH 126/133] Fix deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 034fb0bc..f8477945 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.16", + "version": "1.6.17", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From 1e27deb5d88736c892449d68745e3491b842d321 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Thu, 25 Feb 2016 17:17:00 +0200 Subject: [PATCH 127/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index f8477945..d365a31c 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.17", + "version": "1.6.18", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From cd1098af9164b3d98aceba5b5f6d1349d57ca341 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Thu, 25 Feb 2016 21:50:22 +0200 Subject: [PATCH 128/133] Fix compile-prod when no lambdas --- src/bin/commands/compile-prod.js | 5 +++++ src/lib/NodeJS/NpmInstall.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/bin/commands/compile-prod.js b/src/bin/commands/compile-prod.js index e747c1e0..75d040d4 100644 --- a/src/bin/commands/compile-prod.js +++ b/src/bin/commands/compile-prod.js @@ -176,6 +176,11 @@ 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, diff --git a/src/lib/NodeJS/NpmInstall.js b/src/lib/NodeJS/NpmInstall.js index 6cace5ff..b5e92505 100644 --- a/src/lib/NodeJS/NpmInstall.js +++ b/src/lib/NodeJS/NpmInstall.js @@ -53,6 +53,11 @@ export class NpmInstall { * @returns {NpmInstall} */ runChunk(cb, chunkSize = NpmInstall.DEFAULT_CHUNK_SIZE, silent = NpmInstall.DEFAULT_SILENT_STATE) { + if (this._dirs.length <= 0) { + cb(); + return this; + } + this._runChunkItem( NpmInstall._chunkArray(this._dirs, chunkSize), silent, From 3bc7c9c744cc5c8234dd4819fd02ac43fb6b394c Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 26 Feb 2016 11:03:12 +0200 Subject: [PATCH 129/133] Tweak deps tree optimizer --- src/lib/NodeJS/NpmDependency.js | 19 +++++++++++++++---- src/lib/NodeJS/UndefinedDepsResolver.js | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib/NodeJS/NpmDependency.js b/src/lib/NodeJS/NpmDependency.js index 1b8f3057..e5a417f6 100644 --- a/src/lib/NodeJS/NpmDependency.js +++ b/src/lib/NodeJS/NpmDependency.js @@ -142,7 +142,7 @@ export class NpmDependency { /** * @param {String} dependencyName * @param {String|RegExp|null} version - * @returns {NpmDependency|null} + * @returns {NpmDependency|null|*} */ find(dependencyName, version = null) { let depObj = NpmDependency._resolveFullDepName(dependencyName); @@ -216,6 +216,8 @@ export class NpmDependency { * @returns {NpmDependency} */ removeUndefined() { + let childrenCopy = []; + for (let i in this._children) { if (!this._children.hasOwnProperty(i)) { continue; @@ -224,13 +226,15 @@ export class NpmDependency { let childDep = this._children[i]; if (!childDep.version || childDep.version === 'undefined') { - delete this._children[i]; continue; } + childrenCopy.push(childDep); childDep.removeUndefined(); } + this._children = childrenCopy; + return this; } @@ -287,6 +291,10 @@ export class NpmDependency { addChild(child) { this._children.push(child); + if (child.parent !== this) { + child.parent = this; + } + return this; } @@ -309,6 +317,10 @@ export class NpmDependency { */ set parent(parent) { this._parent = parent; + + if (this._parent.children.indexOf(this) === -1) { + this._parent.addChild(this); + } } /** @@ -348,7 +360,6 @@ export class NpmDependency { depData.name = depName; let dep = NpmDependency.createFromRawObject(depData, isMain); - dep.parent = mainDep; mainDep.addChild(dep); } @@ -370,7 +381,7 @@ export class NpmDependency { */ toString(noHeader = false) { let str = ''; - let pad = ' '.repeat(this._getParentsDepth()); + let pad = new Array(this._getParentsDepth()).join(' '); if (!noHeader) { str += `- ${pad}${this.fullName}${os.EOL}`; diff --git a/src/lib/NodeJS/UndefinedDepsResolver.js b/src/lib/NodeJS/UndefinedDepsResolver.js index d7b3f5e1..fd0f609e 100644 --- a/src/lib/NodeJS/UndefinedDepsResolver.js +++ b/src/lib/NodeJS/UndefinedDepsResolver.js @@ -137,7 +137,6 @@ export class UndefinedDepsResolver { this._cloneChildrenStack(childDep, clonedDep); parentDep.addChild(clonedDep); - clonedDep.parent = parentDep; if (!clonedDep.version || clonedDep.version === 'undefined') { let shadowKey = `${clonedDep.name}@${clonedDep.requestedVersion}`; From 4db4cd56f540d7fe3ce9dbb6d15720e327ca3bad Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Fri, 26 Feb 2016 12:19:14 +0200 Subject: [PATCH 130/133] Publish deepify --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index d365a31c..b4f538ab 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.18", + "version": "1.6.19", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform", From e8dffa4b7e7aa08ec3b2dadc868cda80fd7ef74d Mon Sep 17 00:00:00 2001 From: vcernomschi Date: Fri, 26 Feb 2016 14:31:14 +0200 Subject: [PATCH 131/133] Skipping code transpiling to ES5 and uglifiing --- .travis.yml | 3 +-- src/node-bin/compile.sh | 9 ++++++--- src/node-bin/obfuscate-compiled.sh | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 99d331b4..85d71384 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ sudo: false node_js: - '0.12' - '4.2' - - '5.3' - - '5.4' + - '5.7' cache: directories: - "$(npm root -g)" diff --git a/src/node-bin/compile.sh b/src/node-bin/compile.sh index 7e75a105..d65c99b2 100644 --- a/src/node-bin/compile.sh +++ b/src/node-bin/compile.sh @@ -1,6 +1,9 @@ -#!/usr/bin/env bash -if [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then +if [ "$TRAVIS" == "true" ]; then + echo "Skipping code transpiling to ES5 becuase we are in travis" +elif [ -d 'lib/' ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then BABEL_ENV=production babel lib/ --out-dir lib.compiled/; -elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then +elif [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]; then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" +else + echo "Skipping code transpiling to ES5..." fi diff --git a/src/node-bin/obfuscate-compiled.sh b/src/node-bin/obfuscate-compiled.sh index eafe4546..824f0dbb 100644 --- a/src/node-bin/obfuscate-compiled.sh +++ b/src/node-bin/obfuscate-compiled.sh @@ -1,6 +1,7 @@ -#!/usr/bin/env bash -if [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then - npm list -g --depth 0 uglify > /dev/null 2>&1 || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; +if [ "$TRAVIS" == "true" ]; then + echo "Skipping running uglify becuase we are in travis" +elif [ -d 'lib/' ] && [ "$OSTYPE" != "msys" ] && [ "$OSTYPE" != "win32" ] && [ "$OSTYPE" != "win64" ]; then + `which uglify` || npm install uglify -g; for f in $(find lib.compiled -type f -name *.js); do uglify -s ${f} -o ${f}; done; elif [ -d 'lib/' ] && ([ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "win64" ]); then echo "You should have installed and configured http://git-scm.com/ and run all bash command by using git-bash.exe" elif [ -d 'lib/' ] && [ "$OSTYPE" == "msys" ]; then From 2c20940885ee9c4332bca408283452d01ebc976a Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 29 Feb 2016 12:26:42 +0200 Subject: [PATCH 132/133] Integrate fake config replacement on deploy process --- src/bin/commands/deploy.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/bin/commands/deploy.js b/src/bin/commands/deploy.js index 8d0953fc..e8e4bff1 100644 --- a/src/bin/commands/deploy.js +++ b/src/bin/commands/deploy.js @@ -14,6 +14,7 @@ module.exports = function(mainPath) { var Bin = require('../../lib.compiled/NodeJS/Bin').Bin; var Prompt = require('../../lib.compiled/Terminal/Prompt').Prompt; var Property = require('deep-package-manager').Property_Instance; + var SharedAwsConfig = require('deep-package-manager').Helpers_SharedAwsConfig; var Config = require('deep-package-manager').Property_Config; var S3Service = require('deep-package-manager').Provisioning_Service_S3Service; var ProvisioningCollisionsDetectedException = require('deep-package-manager').Property_Exception_ProvisioningCollisionsDetectedException; @@ -130,16 +131,28 @@ module.exports = function(mainPath) { }.bind(this)); } + function ensureAWSProdKeys(cb) { + (new SharedAwsConfig()).refillPropertyConfigIfNeeded(config, function(refilled) { + if (refilled) { + fse.outputJsonSync(configFile, config); + } + + cb(); + }); + } + function startDeploy() { - propertyInstance = new Property(tmpPropertyPath, Config.DEFAULT_FILENAME); + ensureAWSProdKeys(function() { + propertyInstance = new Property(tmpPropertyPath, Config.DEFAULT_FILENAME); - propertyInstance.assureFrontendEngine(function(error) { - if (error) { - console.error('Error while assuring frontend engine: ' + error); - } + propertyInstance.assureFrontendEngine(function(error) { + if (error) { + console.error('Error while assuring frontend engine: ' + error); + } - propertyInstance.runInitMsHooks(function() { - prepareProduction.bind(this)(propertyInstance.path, doDeploy.bind(this)); + propertyInstance.runInitMsHooks(function() { + prepareProduction.bind(this)(propertyInstance.path, doDeploy.bind(this)); + }.bind(this)); }.bind(this)); }.bind(this)); } From 10114197ba9888f61047ce0bd4a74f4994759b01 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Mon, 29 Feb 2016 14:24:00 +0200 Subject: [PATCH 133/133] Release deepify v1.7.0 --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index b4f538ab..9f6d5bd0 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "deepify", - "version": "1.6.19", + "version": "1.7.0", "description": "DEEP Development Tools", "keywords": [ "Digital Enterprise End-To-End Platform",