From 5ee897c3e7c042c3d27312d2e34d959cd96e82e3 Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Thu, 3 Jan 2019 00:08:03 -0800 Subject: [PATCH] converted utils to tsc --- app-cli/built/models/IModels.js | 3 + app-cli/built/models/IModels.js.map | 1 + app-cli/built/utils/loginHelpers.js | 13 +- app-cli/built/utils/loginHelpers.js.map | 2 +- app-cli/built/utils/machineUtils.js | 10 +- app-cli/built/utils/machineUtils.js.map | 2 +- app-cli/built/utils/messageHandler.js | 3 +- app-cli/built/utils/messageHandler.js.map | 2 +- app-cli/built/utils/validationsHandler.js | 26 ++-- app-cli/built/utils/validationsHandler.js.map | 2 +- app-cli/src/models/IModels.ts | 10 ++ app-cli/src/utils/loginHelpers.js | 46 -------- app-cli/src/utils/loginHelpers.ts | 45 +++++++ app-cli/src/utils/machineUtils.js | 56 --------- app-cli/src/utils/machineUtils.ts | 58 +++++++++ app-cli/src/utils/messageHandler.js | 46 -------- app-cli/src/utils/messageHandler.ts | 46 ++++++++ app-cli/src/utils/validationsHandler.js | 111 ------------------ app-cli/src/utils/validationsHandler.ts | 102 ++++++++++++++++ 19 files changed, 296 insertions(+), 288 deletions(-) create mode 100644 app-cli/built/models/IModels.js create mode 100644 app-cli/built/models/IModels.js.map create mode 100644 app-cli/src/models/IModels.ts delete mode 100644 app-cli/src/utils/loginHelpers.js create mode 100644 app-cli/src/utils/loginHelpers.ts delete mode 100644 app-cli/src/utils/machineUtils.js create mode 100644 app-cli/src/utils/machineUtils.ts delete mode 100644 app-cli/src/utils/messageHandler.js create mode 100644 app-cli/src/utils/messageHandler.ts delete mode 100644 app-cli/src/utils/validationsHandler.js create mode 100644 app-cli/src/utils/validationsHandler.ts diff --git a/app-cli/built/models/IModels.js b/app-cli/built/models/IModels.js new file mode 100644 index 0000000..8f4cd75 --- /dev/null +++ b/app-cli/built/models/IModels.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=IModels.js.map \ No newline at end of file diff --git a/app-cli/built/models/IModels.js.map b/app-cli/built/models/IModels.js.map new file mode 100644 index 0000000..1821df8 --- /dev/null +++ b/app-cli/built/models/IModels.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IModels.js","sourceRoot":"","sources":["../../src/models/IModels.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/app-cli/built/utils/loginHelpers.js b/app-cli/built/utils/loginHelpers.js index ada451e..543693a 100755 --- a/app-cli/built/utils/loginHelpers.js +++ b/app-cli/built/utils/loginHelpers.js @@ -1,17 +1,16 @@ -const MachineHelper = require("../helpers/MachineHelper"); +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const MachineHelper = require('../helpers/MachineHelper'); function cleanUpUrl(url) { if (!url || !url.length) return null; let cleanedUrl = url; - const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === "/"; + const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === '/'; if (hasSlashAtTheEnd) { // Remove the slash at the end cleanedUrl = url.substr(0, url.length - 1); } - return cleanedUrl - .replace("http://", "") - .replace("https://", "") - .trim(); + return cleanedUrl.replace('http://', '').replace('https://', '').trim(); } function findDefaultCaptainName() { let currentSuffix = MachineHelper.machines.length + 1; @@ -24,7 +23,7 @@ function getCaptainFullName(suffix) { const formatSuffix = suffix < 10 ? `0${suffix}` : suffix; return `captain-${formatSuffix}`; } -const isSuffixValid = suffixNumber => MachineHelper.machines.map(machine => { +const isSuffixValid = (suffixNumber) => MachineHelper.machines.map((machine) => { machine.name !== getCaptainFullName(suffixNumber); }); module.exports = { diff --git a/app-cli/built/utils/loginHelpers.js.map b/app-cli/built/utils/loginHelpers.js.map index be815f4..11494f8 100644 --- a/app-cli/built/utils/loginHelpers.js.map +++ b/app-cli/built/utils/loginHelpers.js.map @@ -1 +1 @@ -{"version":3,"file":"loginHelpers.js","sourceRoot":"","sources":["../../src/utils/loginHelpers.js"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,OAAO,CA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CAAC,CAAC,OAAiB,EAAE,EAAE;IAChD,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,YAAY,CAAC,CAAC;AACnD,CAAC,CAAC,CAAC;AAEJ,MAAM,CAAC,OAAO,GAAG;IAChB,UAAU;IACV,sBAAsB;IACtB,aAAa;IACb,kBAAkB;CAClB,CAAC"} \ No newline at end of file diff --git a/app-cli/built/utils/machineUtils.js b/app-cli/built/utils/machineUtils.js index 35f7b28..505bfcf 100755 --- a/app-cli/built/utils/machineUtils.js +++ b/app-cli/built/utils/machineUtils.js @@ -1,7 +1,9 @@ -const DeployApi = require("../api/DeployApi"); -const MachineHelper = require("../helpers/MachineHelper"); +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const DeployApi = require('../api/DeployApi'); +const MachineHelper = require('../helpers/MachineHelper'); function initMachineFromLocalStorage() { - const possibleApp = MachineHelper.apps.find(app => app.cwd === process.cwd()); + const possibleApp = MachineHelper.apps.find((app) => app.cwd === process.cwd()); if (possibleApp) { DeployApi.setMachineToDeploy(possibleApp.machineToDeploy); DeployApi.setAppName(possibleApp.appName); @@ -14,7 +16,7 @@ function saveMachineToLocalStorage() { const currentDirectory = process.cwd(); let appExists = false; // Update app - const updatedApps = apps.map(app => { + const updatedApps = apps.map((app) => { if (app.cwd === currentDirectory) { appExists = true; return { diff --git a/app-cli/built/utils/machineUtils.js.map b/app-cli/built/utils/machineUtils.js.map index 57194db..03de31e 100644 --- a/app-cli/built/utils/machineUtils.js.map +++ b/app-cli/built/utils/machineUtils.js.map @@ -1 +1 @@ -{"version":3,"file":"machineUtils.js","sourceRoot":"","sources":["../../src/utils/machineUtils.js"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAC7C,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AAEzD,SAAS,2BAA2B;IAClC,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,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KAC5B;AACH,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,2BAA2B;IAC3B,yBAAyB;CAC1B,CAAA"} \ No newline at end of file +{"version":3,"file":"machineUtils.js","sourceRoot":"","sources":["../../src/utils/machineUtils.ts"],"names":[],"mappings":";;AAEA,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC9C,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAE1D,SAAS,2BAA2B;IACnC,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAS,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEtF,IAAI,WAAW,EAAE;QAChB,SAAS,CAAC,kBAAkB,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;QAE1D,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAE1C,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;KACpD;AACF,CAAC;AAED,6CAA6C;AAC7C,SAAS,yBAAyB;IACjC,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;IAChC,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACvC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,aAAa;IACb,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAS,EAAE,EAAE;QAC1C,IAAI,GAAG,CAAC,GAAG,KAAK,gBAAgB,EAAE;YACjC,SAAS,GAAG,IAAI,CAAC;YAEjB,OAAO;gBACN,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,OAAO,EAAE,SAAS,CAAC,OAAO;gBAC1B,YAAY,EAAE,SAAS,CAAC,YAAY;gBACpC,eAAe,EAAE,SAAS,CAAC,eAAe;aAC1C,CAAC;SACF;QAED,OAAO,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;IAEH,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAEnC,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,MAAM,GAAG;YACd,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;YAClB,OAAO,EAAE,SAAS,CAAC,OAAO;YAC1B,YAAY,EAAE,SAAS,CAAC,YAAY;YACpC,eAAe,EAAE,SAAS,CAAC,eAAe;SAC1C,CAAC;QAEF,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEzB,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC5B;AACF,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IAChB,2BAA2B;IAC3B,yBAAyB;CACzB,CAAC"} \ No newline at end of file diff --git a/app-cli/built/utils/messageHandler.js b/app-cli/built/utils/messageHandler.js index fb5bcac..22c9094 100755 --- a/app-cli/built/utils/messageHandler.js +++ b/app-cli/built/utils/messageHandler.js @@ -1,4 +1,5 @@ -const chalk = require("chalk"); +"use strict"; +const chalk = require('chalk'); function printMessage(message) { console.log(message); } diff --git a/app-cli/built/utils/messageHandler.js.map b/app-cli/built/utils/messageHandler.js.map index c9ea4b4..ce6d4d9 100644 --- a/app-cli/built/utils/messageHandler.js.map +++ b/app-cli/built/utils/messageHandler.js.map @@ -1 +1 @@ -{"version":3,"file":"messageHandler.js","sourceRoot":"","sources":["../../src/utils/messageHandler.js"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE9B,SAAS,YAAY,CAAC,OAAO;IAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AACtB,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAO;IAClC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAEpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAO,EAAE,IAAI,GAAG,KAAK;IAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAEtC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACzB,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAO,EAAE,IAAI,GAAG,KAAK;IAChD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAExC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACzB,CAAC;AAED,SAAS,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,KAAK;IACrC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAEvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACzB,CAAC;AAED,SAAS,YAAY,CAAC,KAAK;IACzB,IAAI,KAAK,CAAC,MAAM,EAAE;QAChB,UAAU,CAAC,YAAY,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAA;KAC1E;SAAM;QACL,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;KACtC;AACH,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,YAAY;IACZ,mBAAmB;IACnB,UAAU;IACV,iBAAiB;IACjB,mBAAmB;IACnB,YAAY;CACb,CAAA"} \ No newline at end of file +{"version":3,"file":"messageHandler.js","sourceRoot":"","sources":["../../src/utils/messageHandler.ts"],"names":[],"mappings":";AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/B,SAAS,YAAY,CAAC,OAAe;IACpC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAe;IAC3C,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAErB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAe,EAAE,IAAI,GAAG,KAAK;IACvD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAEvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAe,EAAE,IAAI,GAAG,KAAK;IACzD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAEzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,IAAI,GAAG,KAAK;IAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAExC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,YAAY,CAAC,KAAU;IAC/B,IAAI,KAAK,CAAC,MAAM,EAAE;QACjB,UAAU,CAAC,YAAY,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;KAC1E;SAAM;QACN,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;KACtC;AACF,CAAC;AAED,iBAAS;IACR,YAAY;IACZ,mBAAmB;IACnB,UAAU;IACV,iBAAiB;IACjB,mBAAmB;IACnB,YAAY;CACZ,CAAC"} \ No newline at end of file diff --git a/app-cli/built/utils/validationsHandler.js b/app-cli/built/utils/validationsHandler.js index 4f9ff97..5080b7f 100755 --- a/app-cli/built/utils/validationsHandler.js +++ b/app-cli/built/utils/validationsHandler.js @@ -6,23 +6,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; -const fs = require("fs-extra"); -const DeployApi = require("../api/DeployApi"); -const { printError } = require("./messageHandler"); -const { requestLogin } = require("../commands/login"); -const { initMachineFromLocalStorage } = require("../utils/machineUtils"); +const fs = require('fs-extra'); +const DeployApi = require('../api/DeployApi'); +const { printError } = require('./messageHandler'); +const { requestLogin } = require('../commands/login'); +const { initMachineFromLocalStorage } = require('../utils/machineUtils'); function validateIsGitRepository() { - const gitFolderExists = fs.pathExistsSync("./.git"); + const gitFolderExists = fs.pathExistsSync('./.git'); if (!gitFolderExists) { - printError("\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n", true); + printError('\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n', true); } } function validateDefinitionFile() { - const captainDefinitionExists = fs.pathExistsSync("./captain-definition"); + const captainDefinitionExists = fs.pathExistsSync('./captain-definition'); if (!captainDefinitionExists) { - printError("\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n", true); + printError('\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n', true); } - const contents = fs.readFileSync("./captain-definition", "utf8"); + const contents = fs.readFileSync('./captain-definition', 'utf8'); let contentsJson = null; try { contentsJson = JSON.parse(contents); @@ -32,13 +32,13 @@ function validateDefinitionFile() { } if (contentsJson) { if (!contentsJson.schemaVersion) { - printError("**** ERROR: captain-definition needs schemaVersion. Please see docs! ****", true); + printError('**** ERROR: captain-definition needs schemaVersion. Please see docs! ****', true); } if (!contentsJson.templateId && !contentsJson.dockerfileLines) { - printError("**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****", true); + printError('**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****', true); } if (contentsJson.templateId && contentsJson.dockerfileLines) { - printError("**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****", true); + printError('**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****', true); } } } diff --git a/app-cli/built/utils/validationsHandler.js.map b/app-cli/built/utils/validationsHandler.js.map index 3921845..6ce3cdb 100644 --- a/app-cli/built/utils/validationsHandler.js.map +++ b/app-cli/built/utils/validationsHandler.js.map @@ -1 +1 @@ -{"version":3,"file":"validationsHandler.js","sourceRoot":"","sources":["../../src/utils/validationsHandler.js"],"names":[],"mappings":";;;;;;;;AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAC9B,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAC7C,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAClD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AACrD,MAAM,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAExE,SAAS,uBAAuB;IAC9B,MAAM,eAAe,GAAG,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;IAEnD,IAAI,CAAC,eAAe,EAAE;QACpB,UAAU,CACR,gHAAgH,EAChH,IAAI,CACL,CAAA;KACF;AACH,CAAC;AAED,SAAS,sBAAsB;IAC7B,MAAM,uBAAuB,GAAG,EAAE,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAA;IAEzE,IAAI,CAAC,uBAAuB,EAAE;QAC5B,UAAU,CACR,gFAAgF,EAChF,IAAI,CACL,CAAA;KACF;IAED,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAA;IAChE,IAAI,YAAY,GAAG,IAAI,CAAA;IAEvB,IAAI;QACF,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KACpC;IAAC,OAAO,C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;CACjB,CAAA"} \ No newline at end of file +{"version":3,"file":"validationsHandler.js","sourceRoot":"","sources":["../../src/utils/validationsHandler.ts"],"names":[],"mappings":";;;;;;;;AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC9C,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACnD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACtD,MAAM,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAEzE,SAAS,uBAAuB;IAC/B,MAAM,eAAe,GAAG,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEpD,IAAI,CAAC,eAAe,EAAE;QACrB,UAAU,CACT,gHAAgH,EAChH,IAAI,CACJ,CAAC;KACF;AACF,CAAC;AAED,SAAS,sBAAsB;IAC9B,MAAM,uBAAuB,GAAG,EAAE,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;IAE1E,IAAI,CAAC,uBAAuB,EAAE;QAC7B,UAAU,CAAC,gFAAgF,EAAE,IAAI,CAAC,CAAC;KACnG;IAED,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;IACjE,IAAI,YAAY,GAAG,IAAI,CAAC;IAExB,IAAI;QACH,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;KACpC;IAAC,OAAO,CAAC,EAAE;QACX,UAAU,CAAC,yEAAyE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;KAC/F;IAED,IAAI,YAAY,EAAE;QACjB,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE;YAChC,UAAU,CAAC,2EAA2E,EAAE,IAAI,CAAC,CAAC;SAC9F;QAED,IAAI,CAAC,YAAY,CAAC,UAAU,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE;YAC9D,UAAU,CACT,2FAA2F,EAC3F,IAAI,CACJ,CAAC;SACF;QAED,IAAI,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,eAAe,EAAE;YAC5D,UAAU,CACT,qGAAqG,EACrG,IAAI,CACJ,CAAC;SACF;KACD;AACF,CAAC;AAED,kEAAkE;AAClE,SAAS,gBAAgB,CAAC,UAAiC,EAAE,MAAc;IAC1E,0BAA0B;IAC1B,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE;QACvB,OAAO,KAAK,CAAC;KACb;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,SAAiB;IACrC,IACC,kKAAkK,CAAC,IAAI,CACtK,SAAS,CACT,EACA;QACD,OAAO,IAAI,CAAC;KACZ;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAe,sBAAsB;;QACpC,yBAAyB;QACzB,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,gBAAgB,EAAE,CAAC;QAE3D,mBAAmB;QACnB,WAAW;QACX,kBAAkB;QAClB,IAAI,CAAC,eAAe,EAAE;YACrB,MAAM,cAAc,GAAG,MAAM,YAAY,EAAE,CAAC;YAE5C,6BAA6B;YAC7B,2BAA2B,EAAE,CAAC;YAE9B,OAAO,cAAc,CAAC;SACtB;aAAM;YACN,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC;SAChC;IACF,CAAC;CAAA;AAED,MAAM,CAAC,OAAO,GAAG;IAChB,sBAAsB;IACtB,uBAAuB;IACvB,sBAAsB;IACtB,WAAW;IACX,gBAAgB;CAChB,CAAC"} \ No newline at end of file diff --git a/app-cli/src/models/IModels.ts b/app-cli/src/models/IModels.ts new file mode 100644 index 0000000..8123046 --- /dev/null +++ b/app-cli/src/models/IModels.ts @@ -0,0 +1,10 @@ +export interface IApp { + cwd: string; + appName: string; + branchToPush: string; + machineToDeploy: string; +} + +export interface IMachine { + name: string; +} diff --git a/app-cli/src/utils/loginHelpers.js b/app-cli/src/utils/loginHelpers.js deleted file mode 100644 index 187c417..0000000 --- a/app-cli/src/utils/loginHelpers.js +++ /dev/null @@ -1,46 +0,0 @@ -const MachineHelper = require("../helpers/MachineHelper") - -function cleanUpUrl(url) { - if (!url || !url.length) return null - - let cleanedUrl = url - const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === "/" - - if (hasSlashAtTheEnd) { - // Remove the slash at the end - cleanedUrl = url.substr(0, url.length - 1) - } - - return cleanedUrl - .replace("http://", "") - .replace("https://", "") - .trim() -} - -function findDefaultCaptainName() { - let currentSuffix = MachineHelper.machines.length + 1 - - while (!isSuffixValid(currentSuffix)) { - currentSuffix++ - } - - return getCaptainFullName(currentSuffix) -} - -function getCaptainFullName(suffix) { - const formatSuffix = suffix < 10 ? `0${suffix}` : suffix - - return `captain-${formatSuffix}` -} - -const isSuffixValid = suffixNumber => - MachineHelper.machines.map(machine => { - machine.name !== getCaptainFullName(suffixNumber) - }) - -module.exports = { - cleanUpUrl, - findDefaultCaptainName, - isSuffixValid, - getCaptainFullName -} diff --git a/app-cli/src/utils/loginHelpers.ts b/app-cli/src/utils/loginHelpers.ts new file mode 100644 index 0000000..f40f59b --- /dev/null +++ b/app-cli/src/utils/loginHelpers.ts @@ -0,0 +1,45 @@ +import { IMachine } from '../models/IModels'; + +const MachineHelper = require('../helpers/MachineHelper'); + +function cleanUpUrl(url: string) { + if (!url || !url.length) return null; + + let cleanedUrl = url; + const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === '/'; + + if (hasSlashAtTheEnd) { + // Remove the slash at the end + cleanedUrl = url.substr(0, url.length - 1); + } + + return cleanedUrl.replace('http://', '').replace('https://', '').trim(); +} + +function findDefaultCaptainName() { + let currentSuffix = MachineHelper.machines.length + 1; + + while (!isSuffixValid(currentSuffix)) { + currentSuffix++; + } + + return getCaptainFullName(currentSuffix); +} + +function getCaptainFullName(suffix: number) { + const formatSuffix = suffix < 10 ? `0${suffix}` : suffix; + + return `captain-${formatSuffix}`; +} + +const isSuffixValid = (suffixNumber: number) => + MachineHelper.machines.map((machine: IMachine) => { + machine.name !== getCaptainFullName(suffixNumber); + }); + +module.exports = { + cleanUpUrl, + findDefaultCaptainName, + isSuffixValid, + getCaptainFullName +}; diff --git a/app-cli/src/utils/machineUtils.js b/app-cli/src/utils/machineUtils.js deleted file mode 100644 index 53b27a7..0000000 --- a/app-cli/src/utils/machineUtils.js +++ /dev/null @@ -1,56 +0,0 @@ -const DeployApi = require("../api/DeployApi") -const MachineHelper = require("../helpers/MachineHelper") - -function initMachineFromLocalStorage() { - const possibleApp = MachineHelper.apps.find(app => app.cwd === process.cwd()) - - if (possibleApp) { - DeployApi.setMachineToDeploy(possibleApp.machineToDeploy) - - DeployApi.setAppName(possibleApp.appName) - - DeployApi.setBranchToPush(possibleApp.branchToPush) - } -} - -// Saves the app directory into local storage -function saveMachineToLocalStorage() { - const apps = MachineHelper.apps - const currentDirectory = process.cwd() - let appExists = false - // Update app - const updatedApps = apps.map(app => { - if (app.cwd === currentDirectory) { - appExists = true - - return { - cwd: app.cwd, - appName: DeployApi.appName, - branchToPush: DeployApi.branchToPush, - machineToDeploy: DeployApi.machineToDeploy - } - } - - return app - }) - - MachineHelper.setApps(updatedApps) - - if (!appExists) { - const newApp = { - cwd: process.cwd(), - appName: DeployApi.appName, - branchToPush: DeployApi.branchToPush, - machineToDeploy: DeployApi.machineToDeploy - } - - updatedApps.push(newApp) - - MachineHelper.setApps(apps) - } -} - -module.exports = { - initMachineFromLocalStorage, - saveMachineToLocalStorage -} diff --git a/app-cli/src/utils/machineUtils.ts b/app-cli/src/utils/machineUtils.ts new file mode 100644 index 0000000..5896215 --- /dev/null +++ b/app-cli/src/utils/machineUtils.ts @@ -0,0 +1,58 @@ +import { IApp } from '../models/IModels'; + +const DeployApi = require('../api/DeployApi'); +const MachineHelper = require('../helpers/MachineHelper'); + +function initMachineFromLocalStorage() { + const possibleApp = MachineHelper.apps.find((app: IApp) => app.cwd === process.cwd()); + + if (possibleApp) { + DeployApi.setMachineToDeploy(possibleApp.machineToDeploy); + + DeployApi.setAppName(possibleApp.appName); + + DeployApi.setBranchToPush(possibleApp.branchToPush); + } +} + +// Saves the app directory into local storage +function saveMachineToLocalStorage() { + const apps = MachineHelper.apps; + const currentDirectory = process.cwd(); + let appExists = false; + // Update app + const updatedApps = apps.map((app: IApp) => { + if (app.cwd === currentDirectory) { + appExists = true; + + return { + cwd: app.cwd, + appName: DeployApi.appName, + branchToPush: DeployApi.branchToPush, + machineToDeploy: DeployApi.machineToDeploy + }; + } + + return app; + }); + + MachineHelper.setApps(updatedApps); + + if (!appExists) { + const newApp = { + cwd: process.cwd(), + appName: DeployApi.appName, + branchToPush: DeployApi.branchToPush, + machineToDeploy: DeployApi.machineToDeploy + }; + + updatedApps.push(newApp); + + MachineHelper.setApps(apps); + } +} + +module.exports = { + initMachineFromLocalStorage, + saveMachineToLocalStorage +}; diff --git a/app-cli/src/utils/messageHandler.js b/app-cli/src/utils/messageHandler.js deleted file mode 100644 index 77152ea..0000000 --- a/app-cli/src/utils/messageHandler.js +++ /dev/null @@ -1,46 +0,0 @@ -const chalk = require("chalk") - -function printMessage(message) { - console.log(message) -} - -function printMessageAndExit(message) { - console.log(message) - - process.exit(0) -} - -function printGreenMessage(message, exit = false) { - console.log(`${chalk.green(message)}`) - - exit && process.exit(0) -} - -function printMagentaMessage(message, exit = false) { - console.log(`${chalk.magenta(message)}`) - - exit && process.exit(0) -} - -function printError(error, exit = false) { - console.log(`${chalk.bold.red(error)}`) - - exit && process.exit(0) -} - -function errorHandler(error) { - if (error.status) { - printError(`\nError: ${error.status}\nError: ${error.description}`, true) - } else { - printError(`\nError: ${error}`, true) - } -} - -module.exports = { - printMessage, - printMessageAndExit, - printError, - printGreenMessage, - printMagentaMessage, - errorHandler -} diff --git a/app-cli/src/utils/messageHandler.ts b/app-cli/src/utils/messageHandler.ts new file mode 100644 index 0000000..74fd4c3 --- /dev/null +++ b/app-cli/src/utils/messageHandler.ts @@ -0,0 +1,46 @@ +const chalk = require('chalk'); + +function printMessage(message: string) { + console.log(message); +} + +function printMessageAndExit(message: string) { + console.log(message); + + process.exit(0); +} + +function printGreenMessage(message: string, exit = false) { + console.log(`${chalk.green(message)}`); + + exit && process.exit(0); +} + +function printMagentaMessage(message: string, exit = false) { + console.log(`${chalk.magenta(message)}`); + + exit && process.exit(0); +} + +function printError(error: string, exit = false) { + console.log(`${chalk.bold.red(error)}`); + + exit && process.exit(0); +} + +function errorHandler(error: any) { + if (error.status) { + printError(`\nError: ${error.status}\nError: ${error.description}`, true); + } else { + printError(`\nError: ${error}`, true); + } +} + +export = { + printMessage, + printMessageAndExit, + printError, + printGreenMessage, + printMagentaMessage, + errorHandler +}; diff --git a/app-cli/src/utils/validationsHandler.js b/app-cli/src/utils/validationsHandler.js deleted file mode 100644 index 21f8d93..0000000 --- a/app-cli/src/utils/validationsHandler.js +++ /dev/null @@ -1,111 +0,0 @@ -const fs = require("fs-extra") -const DeployApi = require("../api/DeployApi") -const { printError } = require("./messageHandler") -const { requestLogin } = require("../commands/login") -const { initMachineFromLocalStorage } = require("../utils/machineUtils") - -function validateIsGitRepository() { - const gitFolderExists = fs.pathExistsSync("./.git") - - if (!gitFolderExists) { - printError( - "\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n", - true - ) - } -} - -function validateDefinitionFile() { - const captainDefinitionExists = fs.pathExistsSync("./captain-definition") - - if (!captainDefinitionExists) { - printError( - "\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n", - true - ) - } - - const contents = fs.readFileSync("./captain-definition", "utf8") - let contentsJson = null - - try { - contentsJson = JSON.parse(contents) - } catch (e) { - printError( - `**** ERROR: captain-definition file is not a valid JSON! ****\n Error:${e}`, - true - ) - } - - if (contentsJson) { - if (!contentsJson.schemaVersion) { - printError( - "**** ERROR: captain-definition needs schemaVersion. Please see docs! ****", - true - ) - } - - if (!contentsJson.templateId && !contentsJson.dockerfileLines) { - printError( - "**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****", - true - ) - } - - if (contentsJson.templateId && contentsJson.dockerfileLines) { - printError( - "**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****", - true - ) - } - } -} - -// Only show that question if there is no option given as argument -function optionIsNotGiven(allOptions, option) { - // console.log(allOptions) - if (allOptions[option]) { - return false - } - - return true -} - -function isIpAddress(ipaddress) { - if ( - /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test( - ipaddress - ) - ) { - return true - } - - return false -} - -async function validateAuthentication() { - // 1. Check if valid auth - const isAuthenticated = await DeployApi.isAuthTokenValid() - - // 2. Request login - // 3. Login - // 4. Update token - if (!isAuthenticated) { - const loggedInStatus = await requestLogin() - - // Refresh token in DeployApi - initMachineFromLocalStorage() - - return loggedInStatus - } else { - return Boolean(isAuthenticated) - } -} - -module.exports = { - validateAuthentication, - validateIsGitRepository, - validateDefinitionFile, - isIpAddress, - optionIsNotGiven -} diff --git a/app-cli/src/utils/validationsHandler.ts b/app-cli/src/utils/validationsHandler.ts new file mode 100644 index 0000000..00204c0 --- /dev/null +++ b/app-cli/src/utils/validationsHandler.ts @@ -0,0 +1,102 @@ +const fs = require('fs-extra'); +const DeployApi = require('../api/DeployApi'); +const { printError } = require('./messageHandler'); +const { requestLogin } = require('../commands/login'); +const { initMachineFromLocalStorage } = require('../utils/machineUtils'); + +function validateIsGitRepository() { + const gitFolderExists = fs.pathExistsSync('./.git'); + + if (!gitFolderExists) { + printError( + '\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n', + true + ); + } +} + +function validateDefinitionFile() { + const captainDefinitionExists = fs.pathExistsSync('./captain-definition'); + + if (!captainDefinitionExists) { + printError('\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n', true); + } + + const contents = fs.readFileSync('./captain-definition', 'utf8'); + let contentsJson = null; + + try { + contentsJson = JSON.parse(contents); + } catch (e) { + printError(`**** ERROR: captain-definition file is not a valid JSON! ****\n Error:${e}`, true); + } + + if (contentsJson) { + if (!contentsJson.schemaVersion) { + printError('**** ERROR: captain-definition needs schemaVersion. Please see docs! ****', true); + } + + if (!contentsJson.templateId && !contentsJson.dockerfileLines) { + printError( + '**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****', + true + ); + } + + if (contentsJson.templateId && contentsJson.dockerfileLines) { + printError( + '**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****', + true + ); + } + } +} + +// Only show that question if there is no option given as argument +function optionIsNotGiven(allOptions: { [id: string]: any }, option: string) { + // console.log(allOptions) + if (allOptions[option]) { + return false; + } + + return true; +} + +function isIpAddress(ipaddress: string) { + if ( + /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test( + ipaddress + ) + ) { + return true; + } + + return false; +} + +async function validateAuthentication() { + // 1. Check if valid auth + const isAuthenticated = await DeployApi.isAuthTokenValid(); + + // 2. Request login + // 3. Login + // 4. Update token + if (!isAuthenticated) { + const loggedInStatus = await requestLogin(); + + // Refresh token in DeployApi + initMachineFromLocalStorage(); + + return loggedInStatus; + } else { + return Boolean(isAuthenticated); + } +} + +module.exports = { + validateAuthentication, + validateIsGitRepository, + validateDefinitionFile, + isIpAddress, + optionIsNotGiven +};