commands converted to ts

This commit is contained in:
Kasra Bigdeli
2019-01-03 23:48:38 -08:00
parent 28b7d8e2d0
commit 8f63c31c9f
39 changed files with 924 additions and 1003 deletions
+28 -33
View File
@@ -1,59 +1,54 @@
#!/usr/bin/env node
const { printError } = require("../utils/messageHandler");
const packagejson = require("../../package.json");
const updateNotifier = require("update-notifier");
const program = require("commander");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logout = require("./logout");
const { printError } = require('../utils/messageHandler');
const packagejson = require('../../package.json');
const updateNotifier = require('update-notifier');
const program = require('commander');
updateNotifier({ pkg: packagejson }).notify({ isGlobal: true });
// Command actions
const serversetup = require("./serversetup");
const { login } = require("./login");
const logout = require("./logout");
const list = require("./list");
const deploy = require("./deploy");
const serversetup = require('./serversetup');
const { login } = require('./login');
const list = require('./list');
const deploy = require('./deploy');
// Setup
program.version(packagejson.version).description(packagejson.description);
// Commands
program
.command("serversetup")
.description("Performs necessary actions and prepares your Captain server.")
.command('serversetup')
.description('Performs necessary actions and prepares your Captain server.')
.action(() => {
serversetup();
});
program
.command("login")
.description("Login to a CaptainDuckDuck machine. You can be logged in to multiple machines simultaneously.")
.command('login')
.description('Login to a CaptainDuckDuck machine. You can be logged in to multiple machines simultaneously.')
.action(() => {
login();
});
program
.command("logout")
.description("Logout from a specific Captain machine.")
.action(() => {
program.command('logout').description('Logout from a specific Captain machine.').action(() => {
logout();
});
program
.command("list")
.alias("ls")
.description("List all Captain machines currently logged in.")
.action(() => {
program.command('list').alias('ls').description('List all Captain machines currently logged in.').action(() => {
list();
});
program
.command("deploy")
.command('deploy')
.description("Deploy your app (current directory) to a specific Captain machine. You'll be prompted to choose your Captain machine.")
.option("-t, --tarFile <value>", "Specify file to be uploaded (rather than using git archive)")
.option("-d, --default", "Run with default options")
.option("-s, --stateless", "Run deploy stateless")
.option("-h, --host <value>", "Only for stateless mode: Host of the captain machine")
.option("-a, --appName <value>", "Only for stateless mode: Name of the app")
.option("-p, --pass <value>", "Only for stateless mode: Password for Captain")
.option("-b, --branch <value>", "Only for stateless mode: Branch name (default master)")
.action(options => {
.option('-t, --tarFile <value>', 'Specify file to be uploaded (rather than using git archive)')
.option('-d, --default', 'Run with default options')
.option('-s, --stateless', 'Run deploy stateless')
.option('-h, --host <value>', 'Only for stateless mode: Host of the captain machine')
.option('-a, --appName <value>', 'Only for stateless mode: Name of the app')
.option('-p, --pass <value>', 'Only for stateless mode: Password for Captain')
.option('-b, --branch <value>', 'Only for stateless mode: Branch name (default master)')
.action((options) => {
deploy(options);
});
// Error on unknown commands
program.on("command:*", () => {
const wrongCommands = program.args.join(" ");
program.on('command:*', () => {
const wrongCommands = program.args.join(' ');
printError(`\nInvalid command: ${wrongCommands}\nSee --help for a list of available commands.`, true);
});
program.parse(process.argv);
@@ -1 +1 @@
{"version":3,"file":"captainduckduck.js","sourceRoot":"","sources":["../../src/commands/captainduckduck.js"],"names":[],"mappings":";AAEA,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;AACzD,MAAM,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AACjD,MAAM,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AACjD,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAEpC,cAAc,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;AAE/D,kBAAkB;AAClB,MAAM,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAC5C,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AACpC,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAClC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAElC,QAAQ;AAC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EAAE,IAAI,CAAC,CAAC;AACvG,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
+43 -41
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -7,18 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const MachineHelper = require("../helpers/MachineHelper");
const DeployApi = require("../api/DeployApi");
const LoginApi = require("../api/LoginApi");
const { printError, printMessage } = require("../utils/messageHandler");
const { validateIsGitRepository, validateDefinitionFile, optionIsNotGiven, validateAuthentication } = require("../utils/validationsHandler");
const { uploadFile } = require("../utils/fileHelper");
const { gitArchiveFile } = require("../utils/fileHelper");
const fs = require("fs-extra");
const path = require("path");
const inquirer = require("inquirer");
const commandExistsSync = require("command-exists").sync;
const { initMachineFromLocalStorage } = require("../utils/machineUtils");
Object.defineProperty(exports, "__esModule", { value: true });
const MachineHelper_1 = require("../helpers/MachineHelper");
const inquirer = require('inquirer');
const DeployApi = require('../api/DeployApi');
const LoginApi = require('../api/LoginApi');
const { printError, printMessage } = require('../utils/messageHandler');
const { validateIsGitRepository, validateDefinitionFile, optionIsNotGiven, validateAuthentication } = require('../utils/validationsHandler');
const { uploadFile } = require('../utils/fileHelper');
const { gitArchiveFile } = require('../utils/fileHelper');
const fs = require('fs-extra');
const path = require('path');
const commandExistsSync = require('command-exists').sync;
const { initMachineFromLocalStorage } = require('../utils/machineUtils');
function deployAsDefaultValues() {
return __awaiter(this, void 0, void 0, function* () {
try {
@@ -26,13 +28,13 @@ function deployAsDefaultValues() {
if (isValidAuthentication) {
const { appName, branchToPush, machineToDeploy } = DeployApi;
if (!appName || !branchToPush || !machineToDeploy) {
printError("Default deploy failed. There are no default options selected.", true);
printError('Default deploy failed. There are no default options selected.', true);
}
printMessage(`Deploying to ${machineToDeploy.name}`);
deployFromGitProject();
}
else {
printError("Incorrect login details", true);
printError('Incorrect login details', true);
}
}
catch (e) {
@@ -51,14 +53,14 @@ function deployAsStateless(host, appName, branch, pass) {
const data = JSON.parse(response);
const newToken = data.token;
// Update the token to the machine that corresponds (if needed)
MachineHelper.updateMachineAuthToken(name, newToken);
MachineHelper_1.default.updateMachineAuthToken(name, newToken);
if (data) {
printMessage(`Starting stateless deploy to\n${host}\n${branch}\n${appName}`);
deployFromGitProject();
}
}
else {
printError("You are missing parameters for deploying on stateless. <host> <password> <app name> <branch>");
printError('You are missing parameters for deploying on stateless. <host> <password> <app name> <branch>');
}
});
}
@@ -69,11 +71,11 @@ function deployFromTarFile(tarFile) {
if (isValidAuthentication) {
// Send from tar file
const filePath = tarFile;
const gitHash = "sendviatarfile";
const gitHash = 'sendviatarfile';
yield uploadFile(filePath, gitHash);
}
else {
printError("Incorrect login details", true);
printError('Incorrect login details', true);
}
}
catch (e) {
@@ -82,11 +84,11 @@ function deployFromTarFile(tarFile) {
});
}
function deployFromGitProject() {
if (!commandExistsSync("git")) {
if (!commandExistsSync('git')) {
printError("'git' command not found...");
printError("Captain needs 'git' to create tar file of your source files...", true);
}
const zipFileNameToDeploy = "temporary-captain-to-deploy.tar";
const zipFileNameToDeploy = 'temporary-captain-to-deploy.tar';
const zipFileFullPath = path.join(process.cwd(), zipFileNameToDeploy);
printMessage(`Saving tar file to:\n${zipFileFullPath}\n`);
// Removes the temporarly file created
@@ -109,7 +111,7 @@ function deploy(options) {
validateIsGitRepository();
validateDefinitionFile();
}
printMessage("Preparing deployment to Captain...\n");
printMessage('Preparing deployment to Captain...\n');
if (options.default) {
deployAsDefaultValues();
}
@@ -122,38 +124,38 @@ function deploy(options) {
else {
const questions = [
{
type: "list",
name: "captainNameToDeploy",
default: DeployApi.machineToDeploy.name || "",
message: "Select the Captain Machine you want to deploy to:",
choices: MachineHelper.getMachinesAsOptions(),
when: () => optionIsNotGiven(options, "host")
type: 'list',
name: 'captainNameToDeploy',
default: DeployApi.machineToDeploy.name || '',
message: 'Select the Captain Machine you want to deploy to:',
choices: MachineHelper_1.default.getMachinesAsOptions(),
when: () => optionIsNotGiven(options, 'host')
},
{
type: "input",
default: DeployApi.branchToPush || "master",
name: "branchToPush",
type: 'input',
default: DeployApi.branchToPush || 'master',
name: 'branchToPush',
message: "Enter the 'git' branch you would like to deploy:",
when: () => optionIsNotGiven(options, "branch")
when: () => optionIsNotGiven(options, 'branch')
},
{
type: "input",
type: 'input',
default: DeployApi.appName,
name: "appName",
message: "Enter the Captain app name this directory will be deployed to:",
when: () => optionIsNotGiven(options, "appName")
name: 'appName',
message: 'Enter the Captain app name this directory will be deployed to:',
when: () => optionIsNotGiven(options, 'appName')
},
{
type: "confirm",
name: "confirmedToDeploy",
message: "Note that uncommitted files and files in gitignore (if any) will not be pushed to server. Please confirm so that deployment process can start.",
type: 'confirm',
name: 'confirmedToDeploy',
message: 'Note that uncommitted files and files in gitignore (if any) will not be pushed to server. Please confirm so that deployment process can start.',
default: true,
when: () => optionIsNotGiven(options, "stateless")
when: () => optionIsNotGiven(options, 'stateless')
}
];
const answers = yield inquirer.prompt(questions);
if (!answers.confirmedToDeploy && !options.stateless) {
printMessage("\nOperation cancelled by the user...\n");
printMessage('\nOperation cancelled by the user...\n');
process.exit(0);
}
const captainNameToDeploy = answers.captainNameToDeploy;
@@ -171,7 +173,7 @@ function deploy(options) {
deployFromGitProject();
}
else {
printError("Incorrect login details", true);
printError('Incorrect login details', true);
}
}
catch (e) {
File diff suppressed because one or more lines are too long
+9 -10
View File
@@ -1,19 +1,18 @@
#!/usr/bin/env node
const chalk = require("chalk");
const MachineHelper = require("../helpers/MachineHelper");
const { printMessage } = require("../utils/messageHandler");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chalk = require('chalk');
const MachineHelper_1 = require("../helpers/MachineHelper");
const { printMessage } = require('../utils/messageHandler');
function _displayMachine(machine) {
console.log(">> " +
chalk.greenBright(machine.name) +
" at " +
chalk.cyan(machine.baseUrl));
console.log('>> ' + chalk.greenBright(machine.name) + ' at ' + chalk.cyan(machine.baseUrl));
}
function list() {
printMessage("\nLogged in Captain Machines:\n");
MachineHelper.machines.map(machine => {
printMessage('\nLogged in Captain Machines:\n');
MachineHelper_1.default.getMachines().map((machine) => {
_displayMachine(machine);
});
printMessage("");
printMessage('');
}
module.exports = list;
//# sourceMappingURL=list.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.js"],"names":[],"mappings":";AAEA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;AAE3D,SAAS,eAAe,CAAC,OAAO;IAC9B,OAAO,CAAC,GAAG,CACT,KAAK;QACH,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;QAC/B,MAAM;QACN,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAC9B,CAAA;AACH,CAAC;AAED,SAAS,IAAI;IACX,YAAY,CAAC,iCAAiC,CAAC,CAAA;IAE/C,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QACnC,eAAe,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEF,YAAY,CAAC,EAAE,CAAC,CAAA;AAClB,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,IAAI,CAAA"}
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":";;;AAEA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,4DAAqD;AAErD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAE5D,SAAS,eAAe,CAAC,OAAiB;IACzC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED,SAAS,IAAI;IACZ,YAAY,CAAC,iCAAiC,CAAC,CAAC;IAEhD,uBAAa,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3C,eAAe,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,YAAY,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC"}
+41 -39
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -7,28 +8,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const MachineHelper = require("../helpers/MachineHelper");
const { printMessage, printGreenMessage, printError } = require("../utils/messageHandler");
const inquirer = require("inquirer");
const DeployApi = require("../api/DeployApi");
const { cleanUpUrl, findDefaultCaptainName } = require("../utils/loginHelpers");
const { SAMPLE_DOMAIN } = require("../utils/constants");
const LoginApi = require("../api/LoginApi");
Object.defineProperty(exports, "__esModule", { value: true });
const MachineHelper_1 = require("../helpers/MachineHelper");
const { printMessage, printGreenMessage, printError } = require('../utils/messageHandler');
const inquirer = require('inquirer');
const DeployApi = require('../api/DeployApi');
const { cleanUpUrl, findDefaultCaptainName } = require('../utils/loginHelpers');
const { SAMPLE_DOMAIN } = require('../utils/constants');
const LoginApi = require('../api/LoginApi');
// In case the token is expired
function requestLogin() {
return __awaiter(this, void 0, void 0, function* () {
const { baseUrl, name } = DeployApi.machineToDeploy;
printMessage("Your auth token is not valid anymore. Try to login again.");
printMessage('Your auth token is not valid anymore. Try to login again.');
const questions = [
{
type: "password",
name: "captainPassword",
message: "Please enter your password for " + baseUrl,
validate: function (value) {
type: 'password',
name: 'captainPassword',
message: 'Please enter your password for ' + baseUrl,
validate: (value) => {
if (value && value.trim()) {
return true;
}
return "Please enter your password for " + baseUrl;
return 'Please enter your password for ' + baseUrl;
}
}
];
@@ -40,26 +42,26 @@ function requestLogin() {
if (!newToken)
return false;
// Update the token to the machine that corresponds
MachineHelper.updateMachineAuthToken(name, newToken);
MachineHelper_1.default.updateMachineAuthToken(name, newToken);
return true;
});
}
function login() {
return __awaiter(this, void 0, void 0, function* () {
printMessage("Login to a Captain Machine");
printMessage('Login to a Captain Machine');
const questions = [
{
type: "input",
type: 'input',
default: SAMPLE_DOMAIN,
name: "captainAddress",
message: "\nEnter address of the Captain machine. \nIt is captain.[your-captain-root-domain] :",
validate: value => {
name: 'captainAddress',
message: '\nEnter address of the Captain machine. \nIt is captain.[your-captain-root-domain] :',
validate: (value) => {
if (value === SAMPLE_DOMAIN) {
return "Enter a valid URL";
return 'Enter a valid URL';
}
if (!cleanUpUrl(value))
return "This is an invalid URL: " + value;
MachineHelper.machines.map(machine => {
return 'This is an invalid URL: ' + value;
MachineHelper_1.default.getMachines().map((machine) => {
if (cleanUpUrl(machine.baseUrl) === cleanUpUrl(value)) {
return `${value} already exist as ${machine.name}. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`;
}
@@ -67,33 +69,33 @@ function login() {
if (value && value.trim()) {
return true;
}
return "Please enter a valid address.";
return 'Please enter a valid address.';
}
},
{
type: "confirm",
name: "captainHasRootSsl",
message: "Is HTTPS activated for this Captain machine?",
type: 'confirm',
name: 'captainHasRootSsl',
message: 'Is HTTPS activated for this Captain machine?',
default: true
},
{
type: "password",
name: "captainPassword",
message: "Enter your password:",
validate: value => {
type: 'password',
name: 'captainPassword',
message: 'Enter your password:',
validate: (value) => {
if (value && value.trim()) {
return true;
}
return "Please enter your password.";
return 'Please enter your password.';
}
},
{
type: "input",
name: "captainName",
message: "Enter a name for this Captain machine:",
type: 'input',
name: 'captainName',
message: 'Enter a name for this Captain machine:',
default: findDefaultCaptainName(),
validate: value => {
MachineHelper.machines.map(machine => {
validate: (value) => {
MachineHelper_1.default.getMachines().map((machine) => {
if (machine.name === value) {
return `${value} already exist. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`;
}
@@ -101,13 +103,13 @@ function login() {
if (value.match(/^[-\d\w]+$/i)) {
return true;
}
return "Please enter a Captain Name.";
return 'Please enter a Captain Name.';
}
}
];
const answers = yield inquirer.prompt(questions);
const { captainHasRootSsl, captainPassword, captainAddress, captainName } = answers;
const handleHttp = captainHasRootSsl ? "https://" : "http://";
const handleHttp = captainHasRootSsl ? 'https://' : 'http://';
const baseUrl = `${handleHttp}${cleanUpUrl(captainAddress)}`;
try {
const data = yield LoginApi.loginMachine(baseUrl, captainPassword);
@@ -121,7 +123,7 @@ function login() {
baseUrl,
name: captainName
};
MachineHelper.addMachine(newMachine);
MachineHelper_1.default.addMachine(newMachine);
printGreenMessage(`Logged in successfully to ${baseUrl}`);
printGreenMessage(`Authorization token is now saved as ${captainName} \n`);
}
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.js"],"names":[],"mappings":";;;;;;;;;AAEA,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzD,MAAM,EACJ,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACX,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;AACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACpC,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAC7C,MAAM,EAAE,UA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,GAAG,GAAG,UAAU,GAAG,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAE7D,IAAI;YACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAElC,0CAA0C;YAC1C,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;aACnD;YAED,MAAM,UAAU,GAAG;gBAClB,SAAS,EAAE,QAAQ,CAAC,KAAK;gBACzB,OAAO;gBACP,IAAI,EAAE,WAAW;aACjB,CAAC;YAEF,uBAAa,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAErC,iBAAiB,CAAC,6BAA6B,OAAO,EAAE,CAAC,CAAC;YAE1D,iBAAiB,CAAC,uCAAuC,WAAW,KAAK,CAAC,CAAC;SAC3E;QAAC,OAAO,KAAK,EAAE;YACf,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;YAE3D,UAAU,CAAC,wCAAwC,WAAW,OAAO,YAAY,EAAE,CAAC,CAAC;SACrF;IACF,CAAC;CAAA;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC"}
+13 -12
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -7,35 +8,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const MachineHelper = require("../helpers/MachineHelper");
const { printMessage } = require("../utils/messageHandler");
const inquirer = require("inquirer");
const MachineHelper = require('../helpers/MachineHelper');
const { printMessage } = require('../utils/messageHandler');
const inquirer = require('inquirer');
function generateQuestions() {
const listOfMachines = MachineHelper.getMachinesAsOptions();
return [
{
type: "list",
name: "captainNameToLogout",
message: "Select the Captain Machine you want to logout from:",
type: 'list',
name: 'captainNameToLogout',
message: 'Select the Captain Machine you want to logout from:',
choices: listOfMachines
},
{
type: "confirm",
name: "confirmedToLogout",
message: "Are you sure you want to logout from this Captain machine?",
type: 'confirm',
name: 'confirmedToLogout',
message: 'Are you sure you want to logout from this Captain machine?',
default: false,
when: answers => answers.captainNameToLogout
when: (answers) => answers.captainNameToLogout
}
];
}
function logout() {
return __awaiter(this, void 0, void 0, function* () {
const questions = generateQuestions();
printMessage("Logout from a Captain Machine and clear auth info");
printMessage('Logout from a Captain Machine and clear auth info');
const answers = yield inquirer.prompt(questions);
const { captainNameToLogout } = answers;
if (!captainNameToLogout) {
printMessage("\nOperation cancelled by the user...\n", true);
printMessage('\nOperation cancelled by the user...\n', true);
}
MachineHelper.logoutMachine(captainNameToLogout);
});
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.js"],"names":[],"mappings":";;;;;;;;;AAEA,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;AAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAEpC,SAAS,iBAAiB;IACxB,MAAM,cAAc,GAAG,aAAa,CAAC,oBAAoB,EAAE,CAAA;IAE3D,OAAO;QACL;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,qBAAqB;YAC3B,OAAO,EAAE,qDAAqD;YAC9D,OAAO,EAAE,cAAc;SACxB;QACD;YACE,IAAI,EA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mB;SACnD;KACD,CAAC;AACH,CAAC;AAED,SAAe,MAAM;;QACpB,MAAM,SAAS,GAAG,iBAAiB,EAAE,CAAC;QAEtC,YAAY,CAAC,mDAAmD,CAAC,CAAC;QAElE,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACjD,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;QAExC,IAAI,CAAC,mBAAmB,EAAE;YACzB,YAAY,CAAC,wCAAwC,EAAE,IAAI,CAAC,CAAC;SAC7D;QAED,aAAa,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAClD,CAAC;CAAA;AAED,iBAAS,MAAM,CAAC"}
+52 -51
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -7,39 +8,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const MachineHelper = require("../helpers/MachineHelper");
const SystemApi = require("../api/SystemApi");
const LoginApi = require("../api/LoginApi");
const inquirer = require("inquirer");
const { findDefaultCaptainName } = require("../utils/loginHelpers");
const { isIpAddress } = require("../utils/validationsHandler");
const { SAMPLE_IP, DEFAULT_PASSWORD } = require("../utils/constants");
const { printMessage, printError, printMessageAndExit, errorHandler } = require("../utils/messageHandler");
const validationsHandler_1 = require("../utils/validationsHandler");
const SystemApi = require('../api/SystemApi');
const LoginApi = require('../api/LoginApi');
const inquirer = require('inquirer');
const { findDefaultCaptainName } = require('../utils/loginHelpers');
const { SAMPLE_IP, DEFAULT_PASSWORD } = require('../utils/constants');
const { printMessage, printError, printMessageAndExit, errorHandler } = require('../utils/messageHandler');
const MachineHelper_1 = require("../helpers/MachineHelper");
let newPasswordFirstTry = undefined;
const questions = [
{
type: "list",
name: "hasInstalledCaptain",
message: "Have you already installed Captain on your server by running the following line:" +
"\nmkdir /captain && docker run -p 80:80 -p 443:443 -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock dockersaturn/captainduckduck ?",
default: "Yes",
choices: ["Yes", "No"],
filter: value => {
type: 'list',
name: 'hasInstalledCaptain',
message: 'Have you already installed Captain on your server by running the following line:' +
'\nmkdir /captain && docker run -p 80:80 -p 443:443 -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock dockersaturn/captainduckduck ?',
default: 'Yes',
choices: ['Yes', 'No'],
filter: (value) => {
const answerFromUser = value.trim();
if (answerFromUser === "Yes")
if (answerFromUser === 'Yes')
return answerFromUser;
printMessage("\n\nCannot start the setup process if Captain is not installed.");
printMessageAndExit("Please read tutorial on CaptainDuckDuck.com to learn how to install CaptainDuckDuck on a server.");
printMessage('\n\nCannot start the setup process if Captain is not installed.');
printMessageAndExit('Please read tutorial on CaptainDuckDuck.com to learn how to install CaptainDuckDuck on a server.');
}
},
{
type: "input",
type: 'input',
default: SAMPLE_IP,
name: "captainAddress",
message: "Enter IP address of your captain server:",
name: 'captainAddress',
message: 'Enter IP address of your captain server:',
filter: (value) => __awaiter(this, void 0, void 0, function* () {
const ipFromUser = value.trim();
if (ipFromUser === SAMPLE_IP || !isIpAddress(ipFromUser)) {
if (ipFromUser === SAMPLE_IP || !validationsHandler_1.isIpAddress(ipFromUser)) {
printError(`\nThis is an invalid IP Address: ${ipFromUser}`, true);
}
try {
@@ -56,9 +57,9 @@ const questions = [
})
},
{
type: "password",
name: "captainOriginalPassword",
message: "Enter your current password:",
type: 'password',
name: 'captainOriginalPassword',
message: 'Enter your current password:',
when: () => !LoginApi.token,
filter: (value) => __awaiter(this, void 0, void 0, function* () {
try {
@@ -75,11 +76,11 @@ const questions = [
})
},
{
type: "input",
name: "captainRootDomain",
message: "Enter a root domain for this Captain server. For example, enter test.yourdomain.com if you" +
" setup your DNS to point *.test.yourdomain.com to ip address of your server" +
": ",
type: 'input',
name: 'captainRootDomain',
message: 'Enter a root domain for this Captain server. For example, enter test.yourdomain.com if you' +
' setup your DNS to point *.test.yourdomain.com to ip address of your server' +
': ',
filter: (value) => __awaiter(this, void 0, void 0, function* () {
try {
const captainRootDomainFromUser = value.trim();
@@ -96,8 +97,8 @@ const questions = [
})
},
{
type: "input",
name: "emailAddress",
type: 'input',
name: 'emailAddress',
message: "Enter your 'valid' email address to enable HTTPS: ",
filter: (value) => __awaiter(this, void 0, void 0, function* () {
try {
@@ -114,25 +115,25 @@ const questions = [
})
},
{
type: "password",
name: "newPasswordFirstTry",
message: "Enter a new password:",
filter: value => {
type: 'password',
name: 'newPasswordFirstTry',
message: 'Enter a new password:',
filter: (value) => {
newPasswordFirstTry = value;
return value;
}
},
{
type: "password",
name: "newPassword",
message: "Enter a new password:",
type: 'password',
name: 'newPassword',
message: 'Enter a new password:',
filter: (value) => __awaiter(this, void 0, void 0, function* () {
const { customDomainFromUser } = SystemApi;
try {
const confirmPasswordValueFromUser = value;
const machineUrl = `https://${customDomainFromUser}`;
if (newPasswordFirstTry !== confirmPasswordValueFromUser) {
printError("Passwords do not match", true);
printError('Passwords do not match', true);
}
const changePassData = yield LoginApi.changePass(machineUrl, confirmPasswordValueFromUser);
if (changePassData) {
@@ -142,32 +143,32 @@ const questions = [
}
}
catch (e) {
printError("\nIMPORTANT!! Server setup is completed by password is not changed.");
printError("\nYou CANNOT use serversetup anymore. To continue:");
printError('\nIMPORTANT!! Server setup is completed by password is not changed.');
printError('\nYou CANNOT use serversetup anymore. To continue:');
printError(`\n- Go to https://${customDomainFromUser} login with default password and change the password in settings.`);
printError(`\n- In terminal (here), type captainduckduck login and enter this as your root domain: ${customDomainFromUser}`, true);
}
})
},
{
type: "input",
name: "captainName",
message: "Enter a name for this Captain machine:",
type: 'input',
name: 'captainName',
message: 'Enter a name for this Captain machine:',
default: findDefaultCaptainName(),
validate: value => {
validate: (value) => {
const newMachineName = value.trim();
MachineHelper.machines.map(machine => machine.name === newMachineName &&
MachineHelper_1.default.getMachines().map((machine) => machine.name === newMachineName &&
`${newMachineName} already exist. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`);
if (value.match(/^[-\d\w]+$/i)) {
return true;
}
return "Please enter a Captain Name.";
return 'Please enter a Captain Name.';
}
}
];
function serversetup() {
return __awaiter(this, void 0, void 0, function* () {
printMessage("\nSetup your Captain server\n");
printMessage('\nSetup your Captain server\n');
const answers = yield inquirer.prompt(questions);
const captainAddress = `https://${SystemApi.customDomainFromUser}`;
const newMachine = {
@@ -175,9 +176,9 @@ function serversetup() {
baseUrl: captainAddress,
name: answers.captainName
};
MachineHelper.addMachine(newMachine);
MachineHelper_1.default.addMachine(newMachine);
printMessage(`\n\nCaptain is available at ${captainAddress}`);
printMessage("\nFor more details and docs see http://www.captainduckduck.com\n\n");
printMessage('\nFor more details and docs see http://www.captainduckduck.com\n\n');
});
}
module.exports = serversetup;
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"serversetup.js","sourceRoot":"","sources":["../../src/commands/serversetup.js"],"names":[],"mappings":";;;;;;;;;AAEA,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzD,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACpC,MAAM,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AACnE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAA;AAC9D,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AACrE,MAAM,EACJ,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,YAAY,EACb,GAAG,OAAO,CAAC,yBAAyB,CAAC,C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uHAAuH,CACzI,CAAC;YAEF,IAAI,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;gBAC/B,OAAO,IAAI,CAAC;aACZ;YAED,OAAO,8BAA8B,CAAC;QACvC,CAAC;KACD;CACD,CAAC;AAEF,SAAe,WAAW;;QACzB,YAAY,CAAC,+BAA+B,CAAC,CAAC;QAE9C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACjD,MAAM,cAAc,GAAG,WAAW,SAAS,CAAC,oBAAoB,EAAE,CAAC;QACnE,MAAM,UAAU,GAAG;YAClB,SAAS,EAAE,QAAQ,CAAC,KAAK;YACzB,OAAO,EAAE,cAAc;YACvB,IAAI,EAAE,OAAO,CAAC,WAAW;SACzB,CAAC;QAEF,uBAAa,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAErC,YAAY,CAAC,+BAA+B,cAAc,EAAE,CAAC,CAAC;QAE9D,YAAY,CAAC,oEAAoE,CAAC,CAAC;IACpF,CAAC;CAAA;AAED,iBAAS,WAAW,CAAC"}
+5 -1
View File
@@ -28,6 +28,9 @@ class MachineHelper {
});
return [...firstItemInOption, ...listOfMachines];
}
getMachines() {
return this.machines;
}
setMachines(newMachines) {
this.machines = newMachines;
configs.set('captainMachines', newMachines);
@@ -73,5 +76,6 @@ class MachineHelper {
printMessage(`You are now logged out from ${removedMachine.name} at ${removedMachine.baseUrl}...\n`);
}
}
module.exports = new MachineHelper();
const instance = new MachineHelper();
exports.default = instance;
//# sourceMappingURL=MachineHelper.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"MachineHelper.js","sourceRoot":"","sources":["../../src/helpers/MachineHelper.ts"],"names":[],"mappings":";;AAEA,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAC5D,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,o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tB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QAEpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,UAAU,CAAC,UAAoB;QAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC;QACnC,MAAM,WAAW,GAAG,CAAE,GAAG,YAAY,EAAE,UAAU,CAAE,CAAC;QAEpD,uBAAuB;QACvB,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QAE5C,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,aAAa,CAAC,WAAmB;QAChC,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1F,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;QAEpF,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAE9B,YAAY,CAAC,+BAA+B,cAAc,CAAC,IAAI,OAAO,cAAc,CAAC,OAAO,OAAO,CAAC,CAAC;IACtG,CAAC;CACD;AAED,MAAM,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;AAErC,kBAAe,QAAQ,CAAC"}
-1
View File
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const { printMessage, printError, printGreenMessage, printMagentaMessage } = require('./messageHandler');
const SpinnerHelper = require('../helpers/SpinnerHelper');
const child_process_1 = require("child_process");
+1 -1
View File
@@ -1 +1 @@
{"version":3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AS,CAAC,OAAO,IAAI,EAAE,IAAI,CAAC,CAAC;aACzE;SACD;QAAC,OAAO,CAAC,EAAE;YACX,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SAC5B;IACF,CAAC;CAAA;AAED,SAAS,kBAAkB,CAAC,QAAgB;IAC3C,IAAI,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;QAChC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;KACxB;AACF,CAAC;AACD,iBAAS;IACR,cAAc;IACd,aAAa;IACb,UAAU;IACV,sBAAsB;CACtB,CAAC"}
+3 -4
View File
@@ -1,6 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MachineHelper = require('../helpers/MachineHelper');
const MachineHelper_1 = require("../helpers/MachineHelper");
function cleanUpUrl(url) {
if (!url || !url.length)
return null;
@@ -13,7 +12,7 @@ function cleanUpUrl(url) {
return cleanedUrl.replace('http://', '').replace('https://', '').trim();
}
function findDefaultCaptainName() {
let currentSuffix = MachineHelper.machines.length + 1;
let currentSuffix = MachineHelper_1.default.getMachines().length + 1;
while (!isSuffixValid(currentSuffix)) {
currentSuffix++;
}
@@ -23,7 +22,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_1.default.getMachines().map((machine) => {
machine.name !== getCaptainFullName(suffixNumber);
});
module.exports = {
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"loginHelpers.js","sourceRoot":"","sources":["../../src/utils/loginHelpers.ts"],"names":[],"mappings":";;AAEA,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAE1D,SAAS,UAAU,CAAC,GAAW;IAC9B,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAO,IA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sBAAsB;IACtB,aAAa;IACb,kBAAkB;CAClB,CAAC"}
-1
View File
@@ -1,5 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const DeployApi = require('../api/DeployApi');
const MachineHelper = require('../helpers/MachineHelper');
function initMachineFromLocalStorage() {
+1 -1
View File
@@ -1 +1 @@
{"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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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,iBAAS;IACR,2BAA2B;IAC3B,yBAAyB;CACzB,CAAC"}
+7 -7
View File
@@ -1,3 +1,4 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -6,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require('fs-extra');
const DeployApi = require('../api/DeployApi');
const { printError } = require('./messageHandler');
@@ -17,6 +19,7 @@ function validateIsGitRepository() {
printError('\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n', true);
}
}
exports.validateIsGitRepository = validateIsGitRepository;
function validateDefinitionFile() {
const captainDefinitionExists = fs.pathExistsSync('./captain-definition');
if (!captainDefinitionExists) {
@@ -42,6 +45,7 @@ function validateDefinitionFile() {
}
}
}
exports.validateDefinitionFile = validateDefinitionFile;
// Only show that question if there is no option given as argument
function optionIsNotGiven(allOptions, option) {
// console.log(allOptions)
@@ -50,12 +54,14 @@ function optionIsNotGiven(allOptions, option) {
}
return true;
}
exports.optionIsNotGiven = optionIsNotGiven;
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;
}
exports.isIpAddress = isIpAddress;
function validateAuthentication() {
return __awaiter(this, void 0, void 0, function* () {
// 1. Check if valid auth
@@ -74,11 +80,5 @@ function validateAuthentication() {
}
});
}
module.exports = {
validateAuthentication,
validateIsGitRepository,
validateDefinitionFile,
isIpAddress,
optionIsNotGiven
};
exports.validateAuthentication = validateAuthentication;
//# sourceMappingURL=validationsHandler.js.map
@@ -1 +1 @@
{"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,CA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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"}
{"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,SAAgB,uBAAuB;IACtC,MAAM,eAAe,GAAG,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEpD,IAAI,CAAC,eAAe,EAAE;QACrB,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CAAC;KACZ;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAVD,kCAUC;AAED,SAAsB,sBAAsB;;QAC3C,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;AAjBD,wDAiBC"}
-87
View File
@@ -1,87 +0,0 @@
#!/usr/bin/env node
const { printError } = require("../utils/messageHandler")
const packagejson = require("../../package.json")
const updateNotifier = require("update-notifier")
const program = require("commander")
updateNotifier({ pkg: packagejson }).notify({ isGlobal: true })
// Command actions
const serversetup = require("./serversetup")
const { login } = require("./login")
const logout = require("./logout")
const list = require("./list")
const deploy = require("./deploy")
// Setup
program.version(packagejson.version).description(packagejson.description)
// Commands
program
.command("serversetup")
.description("Performs necessary actions and prepares your Captain server.")
.action(() => {
serversetup()
})
program
.command("login")
.description(
"Login to a CaptainDuckDuck machine. You can be logged in to multiple machines simultaneously."
)
.action(() => {
login()
})
program
.command("logout")
.description("Logout from a specific Captain machine.")
.action(() => {
logout()
})
program
.command("list")
.alias("ls")
.description("List all Captain machines currently logged in.")
.action(() => {
list()
})
program
.command("deploy")
.description(
"Deploy your app (current directory) to a specific Captain machine. You'll be prompted to choose your Captain machine."
)
.option(
"-t, --tarFile <value>",
"Specify file to be uploaded (rather than using git archive)"
)
.option("-d, --default", "Run with default options")
.option("-s, --stateless", "Run deploy stateless")
.option(
"-h, --host <value>",
"Only for stateless mode: Host of the captain machine"
)
.option("-a, --appName <value>", "Only for stateless mode: Name of the app")
.option("-p, --pass <value>", "Only for stateless mode: Password for Captain")
.option(
"-b, --branch <value>",
"Only for stateless mode: Branch name (default master)"
)
.action(options => {
deploy(options)
})
// Error on unknown commands
program.on("command:*", () => {
const wrongCommands = program.args.join(" ")
printError(
`\nInvalid command: ${wrongCommands}\nSee --help for a list of available commands.`,
true
)
})
program.parse(process.argv)
+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env node
import logout = require("./logout");
const { printError } = require('../utils/messageHandler');
const packagejson = require('../../package.json');
const updateNotifier = require('update-notifier');
const program = require('commander');
updateNotifier({ pkg: packagejson }).notify({ isGlobal: true });
// Command actions
const serversetup = require('./serversetup');
const { login } = require('./login');
const list = require('./list');
const deploy = require('./deploy');
// Setup
program.version(packagejson.version).description(packagejson.description);
// Commands
program
.command('serversetup')
.description('Performs necessary actions and prepares your Captain server.')
.action(() => {
serversetup();
});
program
.command('login')
.description('Login to a CaptainDuckDuck machine. You can be logged in to multiple machines simultaneously.')
.action(() => {
login();
});
program.command('logout').description('Logout from a specific Captain machine.').action(() => {
logout();
});
program.command('list').alias('ls').description('List all Captain machines currently logged in.').action(() => {
list();
});
program
.command('deploy')
.description(
"Deploy your app (current directory) to a specific Captain machine. You'll be prompted to choose your Captain machine."
)
.option('-t, --tarFile <value>', 'Specify file to be uploaded (rather than using git archive)')
.option('-d, --default', 'Run with default options')
.option('-s, --stateless', 'Run deploy stateless')
.option('-h, --host <value>', 'Only for stateless mode: Host of the captain machine')
.option('-a, --appName <value>', 'Only for stateless mode: Name of the app')
.option('-p, --pass <value>', 'Only for stateless mode: Password for Captain')
.option('-b, --branch <value>', 'Only for stateless mode: Branch name (default master)')
.action((options: any) => {
deploy(options);
});
// Error on unknown commands
program.on('command:*', () => {
const wrongCommands = program.args.join(' ');
printError(`\nInvalid command: ${wrongCommands}\nSee --help for a list of available commands.`, true);
});
program.parse(process.argv);
-216
View File
@@ -1,216 +0,0 @@
#!/usr/bin/env node
const MachineHelper = require("../helpers/MachineHelper")
const DeployApi = require("../api/DeployApi")
const LoginApi = require("../api/LoginApi")
const { printError, printMessage } = require("../utils/messageHandler")
const {
validateIsGitRepository,
validateDefinitionFile,
optionIsNotGiven,
validateAuthentication
} = require("../utils/validationsHandler")
const { uploadFile } = require("../utils/fileHelper")
const { gitArchiveFile } = require("../utils/fileHelper")
const fs = require("fs-extra")
const path = require("path")
const inquirer = require("inquirer")
const commandExistsSync = require("command-exists").sync
const { initMachineFromLocalStorage } = require("../utils/machineUtils")
async function deployAsDefaultValues() {
try {
const isValidAuthentication = await validateAuthentication()
if (isValidAuthentication) {
const { appName, branchToPush, machineToDeploy } = DeployApi
if (!appName || !branchToPush || !machineToDeploy) {
printError(
"Default deploy failed. There are no default options selected.",
true
)
}
printMessage(`Deploying to ${machineToDeploy.name}`)
deployFromGitProject()
} else {
printError("Incorrect login details", true)
}
} catch (e) {
printError(e.message, true)
}
}
async function deployAsStateless(host, appName, branch, pass) {
const isStateless = host && appName && branch && pass
if (isStateless) {
// login first
printMessage(`Trying to login to ${host}\n`)
const { name } = DeployApi.machineToDeploy
const response = await LoginApi.loginMachine(host, pass)
const data = JSON.parse(response)
const newToken = data.token
// Update the token to the machine that corresponds (if needed)
MachineHelper.updateMachineAuthToken(name, newToken)
if (data) {
printMessage(
`Starting stateless deploy to\n${host}\n${branch}\n${appName}`
)
deployFromGitProject()
}
} else {
printError(
"You are missing parameters for deploying on stateless. <host> <password> <app name> <branch>"
)
}
}
async function deployFromTarFile(tarFile) {
try {
const isValidAuthentication = await validateAuthentication()
if (isValidAuthentication) {
// Send from tar file
const filePath = tarFile
const gitHash = "sendviatarfile"
await uploadFile(filePath, gitHash)
} else {
printError("Incorrect login details", true)
}
} catch (e) {
printError(e.message, true)
}
}
function deployFromGitProject() {
if (!commandExistsSync("git")) {
printError("'git' command not found...")
printError(
"Captain needs 'git' to create tar file of your source files...",
true
)
}
const zipFileNameToDeploy = "temporary-captain-to-deploy.tar"
const zipFileFullPath = path.join(process.cwd(), zipFileNameToDeploy)
printMessage(`Saving tar file to:\n${zipFileFullPath}\n`)
// Removes the temporarly file created
try {
const tempFileExists = fs.pathExistsSync(zipFileFullPath)
if (tempFileExists) {
fs.removeSync(zipFileFullPath)
}
} catch (e) {
// IgnoreError
}
gitArchiveFile(zipFileFullPath, DeployApi.branchToPush)
}
async function deploy(options) {
// Reads local storage and sets the machine if found
initMachineFromLocalStorage()
if (!options.tarFile || !options.stateless) {
validateIsGitRepository()
validateDefinitionFile()
}
printMessage("Preparing deployment to Captain...\n")
if (options.default) {
deployAsDefaultValues()
} else if (options.stateless) {
deployAsStateless(
options.host,
options.appName,
options.branch,
options.pass
)
} else if (options.tarFile) {
deployFromTarFile(options.tarFile)
} else {
const questions = [
{
type: "list",
name: "captainNameToDeploy",
default: DeployApi.machineToDeploy.name || "",
message: "Select the Captain Machine you want to deploy to:",
choices: MachineHelper.getMachinesAsOptions(),
when: () => optionIsNotGiven(options, "host")
},
{
type: "input",
default: DeployApi.branchToPush || "master",
name: "branchToPush",
message: "Enter the 'git' branch you would like to deploy:",
when: () => optionIsNotGiven(options, "branch")
},
{
type: "input",
default: DeployApi.appName,
name: "appName",
message:
"Enter the Captain app name this directory will be deployed to:",
when: () => optionIsNotGiven(options, "appName")
},
{
type: "confirm",
name: "confirmedToDeploy",
message:
"Note that uncommitted files and files in gitignore (if any) will not be pushed to server. Please confirm so that deployment process can start.",
default: true,
when: () => optionIsNotGiven(options, "stateless")
}
]
const answers = await inquirer.prompt(questions)
if (!answers.confirmedToDeploy && !options.stateless) {
printMessage("\nOperation cancelled by the user...\n")
process.exit(0)
}
const captainNameToDeploy = answers.captainNameToDeploy
const branchToPush = answers.branchToPush || options.branch
const appName = answers.appName || options.appName
DeployApi.updateMachineToDeploy(captainNameToDeploy || options.host)
DeployApi.setBranchToPush(branchToPush)
DeployApi.setAppName(appName)
printMessage(`Deploying to ${DeployApi.machineToDeploy.name}`)
// Normal deploy
if (answers.confirmedToDeploy) {
try {
const isValidAuthentication = await validateAuthentication()
if (isValidAuthentication) {
deployFromGitProject()
} else {
printError("Incorrect login details", true)
}
} catch (e) {
printError(e.message, true)
}
}
}
}
module.exports = deploy
+200
View File
@@ -0,0 +1,200 @@
#!/usr/bin/env node
import MachineHelper from '../helpers/MachineHelper';
const inquirer = require('inquirer');
const DeployApi = require('../api/DeployApi');
const LoginApi = require('../api/LoginApi');
const { printError, printMessage } = require('../utils/messageHandler');
const {
validateIsGitRepository,
validateDefinitionFile,
optionIsNotGiven,
validateAuthentication
} = require('../utils/validationsHandler');
const { uploadFile } = require('../utils/fileHelper');
const { gitArchiveFile } = require('../utils/fileHelper');
const fs = require('fs-extra');
const path = require('path');
const commandExistsSync = require('command-exists').sync;
const { initMachineFromLocalStorage } = require('../utils/machineUtils');
async function deployAsDefaultValues() {
try {
const isValidAuthentication = await validateAuthentication();
if (isValidAuthentication) {
const { appName, branchToPush, machineToDeploy } = DeployApi;
if (!appName || !branchToPush || !machineToDeploy) {
printError('Default deploy failed. There are no default options selected.', true);
}
printMessage(`Deploying to ${machineToDeploy.name}`);
deployFromGitProject();
} else {
printError('Incorrect login details', true);
}
} catch (e) {
printError(e.message, true);
}
}
async function deployAsStateless(host: string, appName: string, branch: string, pass: string) {
const isStateless = host && appName && branch && pass;
if (isStateless) {
// login first
printMessage(`Trying to login to ${host}\n`);
const { name } = DeployApi.machineToDeploy;
const response = await LoginApi.loginMachine(host, pass);
const data = JSON.parse(response);
const newToken = data.token;
// Update the token to the machine that corresponds (if needed)
MachineHelper.updateMachineAuthToken(name, newToken);
if (data) {
printMessage(`Starting stateless deploy to\n${host}\n${branch}\n${appName}`);
deployFromGitProject();
}
} else {
printError('You are missing parameters for deploying on stateless. <host> <password> <app name> <branch>');
}
}
async function deployFromTarFile(tarFile: string) {
try {
const isValidAuthentication = await validateAuthentication();
if (isValidAuthentication) {
// Send from tar file
const filePath = tarFile;
const gitHash = 'sendviatarfile';
await uploadFile(filePath, gitHash);
} else {
printError('Incorrect login details', true);
}
} catch (e) {
printError(e.message, true);
}
}
function deployFromGitProject() {
if (!commandExistsSync('git')) {
printError("'git' command not found...");
printError("Captain needs 'git' to create tar file of your source files...", true);
}
const zipFileNameToDeploy = 'temporary-captain-to-deploy.tar';
const zipFileFullPath = path.join(process.cwd(), zipFileNameToDeploy);
printMessage(`Saving tar file to:\n${zipFileFullPath}\n`);
// Removes the temporarly file created
try {
const tempFileExists = fs.pathExistsSync(zipFileFullPath);
if (tempFileExists) {
fs.removeSync(zipFileFullPath);
}
} catch (e) {
// IgnoreError
}
gitArchiveFile(zipFileFullPath, DeployApi.branchToPush);
}
async function deploy(options: any) {
// Reads local storage and sets the machine if found
initMachineFromLocalStorage();
if (!options.tarFile || !options.stateless) {
validateIsGitRepository();
validateDefinitionFile();
}
printMessage('Preparing deployment to Captain...\n');
if (options.default) {
deployAsDefaultValues();
} else if (options.stateless) {
deployAsStateless(options.host, options.appName, options.branch, options.pass);
} else if (options.tarFile) {
deployFromTarFile(options.tarFile);
} else {
const questions = [
{
type: 'list',
name: 'captainNameToDeploy',
default: DeployApi.machineToDeploy.name || '',
message: 'Select the Captain Machine you want to deploy to:',
choices: MachineHelper.getMachinesAsOptions(),
when: () => optionIsNotGiven(options, 'host')
},
{
type: 'input',
default: DeployApi.branchToPush || 'master',
name: 'branchToPush',
message: "Enter the 'git' branch you would like to deploy:",
when: () => optionIsNotGiven(options, 'branch')
},
{
type: 'input',
default: DeployApi.appName,
name: 'appName',
message: 'Enter the Captain app name this directory will be deployed to:',
when: () => optionIsNotGiven(options, 'appName')
},
{
type: 'confirm',
name: 'confirmedToDeploy',
message:
'Note that uncommitted files and files in gitignore (if any) will not be pushed to server. Please confirm so that deployment process can start.',
default: true,
when: () => optionIsNotGiven(options, 'stateless')
}
];
const answers = await inquirer.prompt(questions);
if (!answers.confirmedToDeploy && !options.stateless) {
printMessage('\nOperation cancelled by the user...\n');
process.exit(0);
}
const captainNameToDeploy = answers.captainNameToDeploy;
const branchToPush = answers.branchToPush || options.branch;
const appName = answers.appName || options.appName;
DeployApi.updateMachineToDeploy(captainNameToDeploy || options.host);
DeployApi.setBranchToPush(branchToPush);
DeployApi.setAppName(appName);
printMessage(`Deploying to ${DeployApi.machineToDeploy.name}`);
// Normal deploy
if (answers.confirmedToDeploy) {
try {
const isValidAuthentication = await validateAuthentication();
if (isValidAuthentication) {
deployFromGitProject();
} else {
printError('Incorrect login details', true);
}
} catch (e) {
printError(e.message, true);
}
}
}
}
export = deploy;
-26
View File
@@ -1,26 +0,0 @@
#!/usr/bin/env node
const chalk = require("chalk")
const MachineHelper = require("../helpers/MachineHelper")
const { printMessage } = require("../utils/messageHandler")
function _displayMachine(machine) {
console.log(
">> " +
chalk.greenBright(machine.name) +
" at " +
chalk.cyan(machine.baseUrl)
)
}
function list() {
printMessage("\nLogged in Captain Machines:\n")
MachineHelper.machines.map(machine => {
_displayMachine(machine)
})
printMessage("")
}
module.exports = list
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env node
const chalk = require('chalk');
import MachineHelper from '../helpers/MachineHelper';
import { IMachine } from '../models/IModels';
const { printMessage } = require('../utils/messageHandler');
function _displayMachine(machine: IMachine) {
console.log('>> ' + chalk.greenBright(machine.name) + ' at ' + chalk.cyan(machine.baseUrl));
}
function list() {
printMessage('\nLogged in Captain Machines:\n');
MachineHelper.getMachines().map((machine) => {
_displayMachine(machine);
});
printMessage('');
}
export = list;
-158
View File
@@ -1,158 +0,0 @@
#!/usr/bin/env node
const MachineHelper = require("../helpers/MachineHelper")
const {
printMessage,
printGreenMessage,
printError
} = require("../utils/messageHandler")
const inquirer = require("inquirer")
const DeployApi = require("../api/DeployApi")
const { cleanUpUrl, findDefaultCaptainName } = require("../utils/loginHelpers")
const { SAMPLE_DOMAIN } = require("../utils/constants")
const LoginApi = require("../api/LoginApi")
// In case the token is expired
async function requestLogin() {
const { baseUrl, name } = DeployApi.machineToDeploy
printMessage("Your auth token is not valid anymore. Try to login again.")
const questions = [
{
type: "password",
name: "captainPassword",
message: "Please enter your password for " + baseUrl,
validate: function(value) {
if (value && value.trim()) {
return true
}
return "Please enter your password for " + baseUrl
}
}
]
const loginPassword = await inquirer.prompt(questions)
const password = loginPassword.captainPassword
const response = await LoginApi.loginMachine(baseUrl, password)
const data = JSON.parse(response)
const newToken = data.token
if (!newToken) return false
// Update the token to the machine that corresponds
MachineHelper.updateMachineAuthToken(name, newToken)
return true
}
async function login() {
printMessage("Login to a Captain Machine")
const questions = [
{
type: "input",
default: SAMPLE_DOMAIN,
name: "captainAddress",
message:
"\nEnter address of the Captain machine. \nIt is captain.[your-captain-root-domain] :",
validate: value => {
if (value === SAMPLE_DOMAIN) {
return "Enter a valid URL"
}
if (!cleanUpUrl(value)) return "This is an invalid URL: " + value
MachineHelper.machines.map(machine => {
if (cleanUpUrl(machine.baseUrl) === cleanUpUrl(value)) {
return `${value} already exist as ${
machine.name
}. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`
}
})
if (value && value.trim()) {
return true
}
return "Please enter a valid address."
}
},
{
type: "confirm",
name: "captainHasRootSsl",
message: "Is HTTPS activated for this Captain machine?",
default: true
},
{
type: "password",
name: "captainPassword",
message: "Enter your password:",
validate: value => {
if (value && value.trim()) {
return true
}
return "Please enter your password."
}
},
{
type: "input",
name: "captainName",
message: "Enter a name for this Captain machine:",
default: findDefaultCaptainName(),
validate: value => {
MachineHelper.machines.map(machine => {
if (machine.name === value) {
return `${value} already exist. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`
}
})
if (value.match(/^[-\d\w]+$/i)) {
return true
}
return "Please enter a Captain Name."
}
}
]
const answers = await inquirer.prompt(questions)
const {
captainHasRootSsl,
captainPassword,
captainAddress,
captainName
} = answers
const handleHttp = captainHasRootSsl ? "https://" : "http://"
const baseUrl = `${handleHttp}${cleanUpUrl(captainAddress)}`
try {
const data = await LoginApi.loginMachine(baseUrl, captainPassword)
const response = JSON.parse(data)
// TODO - This status should be 200 maybe?
if (response.status !== 100) {
throw new Error(JSON.stringify(response, null, 2))
}
const newMachine = {
authToken: response.token,
baseUrl,
name: captainName
}
MachineHelper.addMachine(newMachine)
printGreenMessage(`Logged in successfully to ${baseUrl}`)
printGreenMessage(`Authorization token is now saved as ${captainName} \n`)
} catch (error) {
const errorMessage = error.message ? error.message : error
printError(
`Something bad happened. Cannot save "${captainName}" \n${errorMessage}`
)
}
}
module.exports = { login, requestLogin }
+145
View File
@@ -0,0 +1,145 @@
#!/usr/bin/env node
import MachineHelper from '../helpers/MachineHelper';
const { printMessage, printGreenMessage, printError } = require('../utils/messageHandler');
const inquirer = require('inquirer');
const DeployApi = require('../api/DeployApi');
const { cleanUpUrl, findDefaultCaptainName } = require('../utils/loginHelpers');
const { SAMPLE_DOMAIN } = require('../utils/constants');
const LoginApi = require('../api/LoginApi');
// In case the token is expired
async function requestLogin() {
const { baseUrl, name } = DeployApi.machineToDeploy;
printMessage('Your auth token is not valid anymore. Try to login again.');
const questions = [
{
type: 'password',
name: 'captainPassword',
message: 'Please enter your password for ' + baseUrl,
validate: (value: string) => {
if (value && value.trim()) {
return true;
}
return 'Please enter your password for ' + baseUrl;
}
}
];
const loginPassword = await inquirer.prompt(questions);
const password = loginPassword.captainPassword;
const response = await LoginApi.loginMachine(baseUrl, password);
const data = JSON.parse(response);
const newToken = data.token;
if (!newToken) return false;
// Update the token to the machine that corresponds
MachineHelper.updateMachineAuthToken(name, newToken);
return true;
}
async function login() {
printMessage('Login to a Captain Machine');
const questions = [
{
type: 'input',
default: SAMPLE_DOMAIN,
name: 'captainAddress',
message: '\nEnter address of the Captain machine. \nIt is captain.[your-captain-root-domain] :',
validate: (value: string) => {
if (value === SAMPLE_DOMAIN) {
return 'Enter a valid URL';
}
if (!cleanUpUrl(value)) return 'This is an invalid URL: ' + value;
MachineHelper.getMachines().map((machine) => {
if (cleanUpUrl(machine.baseUrl) === cleanUpUrl(value)) {
return `${value} already exist as ${machine.name}. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`;
}
});
if (value && value.trim()) {
return true;
}
return 'Please enter a valid address.';
}
},
{
type: 'confirm',
name: 'captainHasRootSsl',
message: 'Is HTTPS activated for this Captain machine?',
default: true
},
{
type: 'password',
name: 'captainPassword',
message: 'Enter your password:',
validate: (value: string) => {
if (value && value.trim()) {
return true;
}
return 'Please enter your password.';
}
},
{
type: 'input',
name: 'captainName',
message: 'Enter a name for this Captain machine:',
default: findDefaultCaptainName(),
validate: (value: string) => {
MachineHelper.getMachines().map((machine) => {
if (machine.name === value) {
return `${value} already exist. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`;
}
});
if (value.match(/^[-\d\w]+$/i)) {
return true;
}
return 'Please enter a Captain Name.';
}
}
];
const answers = await inquirer.prompt(questions);
const { captainHasRootSsl, captainPassword, captainAddress, captainName } = answers;
const handleHttp = captainHasRootSsl ? 'https://' : 'http://';
const baseUrl = `${handleHttp}${cleanUpUrl(captainAddress)}`;
try {
const data = await LoginApi.loginMachine(baseUrl, captainPassword);
const response = JSON.parse(data);
// TODO - This status should be 200 maybe?
if (response.status !== 100) {
throw new Error(JSON.stringify(response, null, 2));
}
const newMachine = {
authToken: response.token,
baseUrl,
name: captainName
};
MachineHelper.addMachine(newMachine);
printGreenMessage(`Logged in successfully to ${baseUrl}`);
printGreenMessage(`Authorization token is now saved as ${captainName} \n`);
} catch (error) {
const errorMessage = error.message ? error.message : error;
printError(`Something bad happened. Cannot save "${captainName}" \n${errorMessage}`);
}
}
export = { login, requestLogin };
-42
View File
@@ -1,42 +0,0 @@
#!/usr/bin/env node
const MachineHelper = require("../helpers/MachineHelper")
const { printMessage } = require("../utils/messageHandler")
const inquirer = require("inquirer")
function generateQuestions() {
const listOfMachines = MachineHelper.getMachinesAsOptions()
return [
{
type: "list",
name: "captainNameToLogout",
message: "Select the Captain Machine you want to logout from:",
choices: listOfMachines
},
{
type: "confirm",
name: "confirmedToLogout",
message: "Are you sure you want to logout from this Captain machine?",
default: false,
when: answers => answers.captainNameToLogout
}
]
}
async function logout() {
const questions = generateQuestions()
printMessage("Logout from a Captain Machine and clear auth info")
const answers = await inquirer.prompt(questions)
const { captainNameToLogout } = answers
if (!captainNameToLogout) {
printMessage("\nOperation cancelled by the user...\n", true)
}
MachineHelper.logoutMachine(captainNameToLogout)
}
module.exports = logout
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env node
const MachineHelper = require('../helpers/MachineHelper');
const { printMessage } = require('../utils/messageHandler');
const inquirer = require('inquirer');
function generateQuestions() {
const listOfMachines = MachineHelper.getMachinesAsOptions();
return [
{
type: 'list',
name: 'captainNameToLogout',
message: 'Select the Captain Machine you want to logout from:',
choices: listOfMachines
},
{
type: 'confirm',
name: 'confirmedToLogout',
message: 'Are you sure you want to logout from this Captain machine?',
default: false,
when: (answers: any) => answers.captainNameToLogout
}
];
}
async function logout() {
const questions = generateQuestions();
printMessage('Logout from a Captain Machine and clear auth info');
const answers = await inquirer.prompt(questions);
const { captainNameToLogout } = answers;
if (!captainNameToLogout) {
printMessage('\nOperation cancelled by the user...\n', true);
}
MachineHelper.logoutMachine(captainNameToLogout);
}
export = logout;
-241
View File
@@ -1,241 +0,0 @@
#!/usr/bin/env node
const MachineHelper = require("../helpers/MachineHelper")
const SystemApi = require("../api/SystemApi")
const LoginApi = require("../api/LoginApi")
const inquirer = require("inquirer")
const { findDefaultCaptainName } = require("../utils/loginHelpers")
const { isIpAddress } = require("../utils/validationsHandler")
const { SAMPLE_IP, DEFAULT_PASSWORD } = require("../utils/constants")
const {
printMessage,
printError,
printMessageAndExit,
errorHandler
} = require("../utils/messageHandler")
let newPasswordFirstTry = undefined
const questions = [
{
type: "list",
name: "hasInstalledCaptain",
message:
"Have you already installed Captain on your server by running the following line:" +
"\nmkdir /captain && docker run -p 80:80 -p 443:443 -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock dockersaturn/captainduckduck ?",
default: "Yes",
choices: ["Yes", "No"],
filter: value => {
const answerFromUser = value.trim()
if (answerFromUser === "Yes") return answerFromUser
printMessage(
"\n\nCannot start the setup process if Captain is not installed."
)
printMessageAndExit(
"Please read tutorial on CaptainDuckDuck.com to learn how to install CaptainDuckDuck on a server."
)
}
},
{
type: "input",
default: SAMPLE_IP,
name: "captainAddress",
message: "Enter IP address of your captain server:",
filter: async value => {
const ipFromUser = value.trim()
if (ipFromUser === SAMPLE_IP || !isIpAddress(ipFromUser)) {
printError(`\nThis is an invalid IP Address: ${ipFromUser}`, true)
}
try {
// login using captain42. and set the ipAddressToServer
const data = await LoginApi.loginMachine(
`http://${ipFromUser}:3000`,
DEFAULT_PASSWORD
)
SystemApi.setIpAddressOfServer(ipFromUser)
// All went well
if (data) return ipFromUser
} catch (e) {
errorHandler(e)
}
}
},
{
type: "password",
name: "captainOriginalPassword",
message: "Enter your current password:",
when: () => !LoginApi.token,
filter: async value => {
try {
const captainPasswordFromUser = value.trim()
const data = await LoginApi.loginMachine(
`http://${SystemApi.ipAddressOfServer}:3000`,
captainPasswordFromUser
)
if (data) {
SystemApi.setIpAddressOfServer(captainPasswordFromUser)
LoginApi.setOldPassword(captainPasswordFromUser)
}
} catch (e) {
errorHandler(e)
}
}
},
{
type: "input",
name: "captainRootDomain",
message:
"Enter a root domain for this Captain server. For example, enter test.yourdomain.com if you" +
" setup your DNS to point *.test.yourdomain.com to ip address of your server" +
": ",
filter: async value => {
try {
const captainRootDomainFromUser = value.trim()
const data = await SystemApi.setCustomDomain(
`http://${SystemApi.ipAddressOfServer}:3000`,
captainRootDomainFromUser
)
if (data) {
const newCustomDomainFromUser = `captain.${captainRootDomainFromUser}`
SystemApi.setCustomDomainFromUser(newCustomDomainFromUser)
return captainRootDomainFromUser
}
} catch (e) {
errorHandler(e)
}
}
},
{
type: "input",
name: "emailAddress",
message: "Enter your 'valid' email address to enable HTTPS: ",
filter: async value => {
try {
const emailAddressFromUser = value.trim()
const { customDomainFromUser } = SystemApi
await SystemApi.enableHttps(
`http://${customDomainFromUser}`,
emailAddressFromUser
)
const data = await SystemApi.forceHttps(
`https://${customDomainFromUser}`
)
if (data) return emailAddressFromUser
} catch (e) {
errorHandler(e)
}
}
},
{
type: "password",
name: "newPasswordFirstTry",
message: "Enter a new password:",
filter: value => {
newPasswordFirstTry = value
return value
}
},
{
type: "password",
name: "newPassword",
message: "Enter a new password:",
filter: async value => {
const { customDomainFromUser } = SystemApi
try {
const confirmPasswordValueFromUser = value
const machineUrl = `https://${customDomainFromUser}`
if (newPasswordFirstTry !== confirmPasswordValueFromUser) {
printError("Passwords do not match", true)
}
const changePassData = await LoginApi.changePass(
machineUrl,
confirmPasswordValueFromUser
)
if (changePassData) {
const loginData = await LoginApi.login(
machineUrl,
confirmPasswordValueFromUser
)
if (loginData) return
}
} catch (e) {
printError(
"\nIMPORTANT!! Server setup is completed by password is not changed."
)
printError("\nYou CANNOT use serversetup anymore. To continue:")
printError(
`\n- Go to https://${customDomainFromUser} login with default password and change the password in settings.`
)
printError(
`\n- In terminal (here), type captainduckduck login and enter this as your root domain: ${customDomainFromUser}`,
true
)
}
}
},
{
type: "input",
name: "captainName",
message: "Enter a name for this Captain machine:",
default: findDefaultCaptainName(),
validate: value => {
const newMachineName = value.trim()
MachineHelper.machines.map(
machine =>
machine.name === newMachineName &&
`${newMachineName} already exist. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`
)
if (value.match(/^[-\d\w]+$/i)) {
return true
}
return "Please enter a Captain Name."
}
}
]
async function serversetup() {
printMessage("\nSetup your Captain server\n")
const answers = await inquirer.prompt(questions)
const captainAddress = `https://${SystemApi.customDomainFromUser}`
const newMachine = {
authToken: LoginApi.token,
baseUrl: captainAddress,
name: answers.captainName
}
MachineHelper.addMachine(newMachine)
printMessage(`\n\nCaptain is available at ${captainAddress}`)
printMessage(
"\nFor more details and docs see http://www.captainduckduck.com\n\n"
)
}
module.exports = serversetup
+218
View File
@@ -0,0 +1,218 @@
#!/usr/bin/env node
import { isIpAddress } from '../utils/validationsHandler';
const SystemApi = require('../api/SystemApi');
const LoginApi = require('../api/LoginApi');
const inquirer = require('inquirer');
const { findDefaultCaptainName } = require('../utils/loginHelpers');
const { SAMPLE_IP, DEFAULT_PASSWORD } = require('../utils/constants');
const { printMessage, printError, printMessageAndExit, errorHandler } = require('../utils/messageHandler');
import MachineHelper from '../helpers/MachineHelper';
let newPasswordFirstTry: string | undefined = undefined;
const questions = [
{
type: 'list',
name: 'hasInstalledCaptain',
message:
'Have you already installed Captain on your server by running the following line:' +
'\nmkdir /captain && docker run -p 80:80 -p 443:443 -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock dockersaturn/captainduckduck ?',
default: 'Yes',
choices: [ 'Yes', 'No' ],
filter: (value: string) => {
const answerFromUser = value.trim();
if (answerFromUser === 'Yes') return answerFromUser;
printMessage('\n\nCannot start the setup process if Captain is not installed.');
printMessageAndExit(
'Please read tutorial on CaptainDuckDuck.com to learn how to install CaptainDuckDuck on a server.'
);
}
},
{
type: 'input',
default: SAMPLE_IP,
name: 'captainAddress',
message: 'Enter IP address of your captain server:',
filter: async (value: string) => {
const ipFromUser = value.trim();
if (ipFromUser === SAMPLE_IP || !isIpAddress(ipFromUser)) {
printError(`\nThis is an invalid IP Address: ${ipFromUser}`, true);
}
try {
// login using captain42. and set the ipAddressToServer
const data = await LoginApi.loginMachine(`http://${ipFromUser}:3000`, DEFAULT_PASSWORD);
SystemApi.setIpAddressOfServer(ipFromUser);
// All went well
if (data) return ipFromUser;
} catch (e) {
errorHandler(e);
}
}
},
{
type: 'password',
name: 'captainOriginalPassword',
message: 'Enter your current password:',
when: () => !LoginApi.token,
filter: async (value: string) => {
try {
const captainPasswordFromUser = value.trim();
const data = await LoginApi.loginMachine(
`http://${SystemApi.ipAddressOfServer}:3000`,
captainPasswordFromUser
);
if (data) {
SystemApi.setIpAddressOfServer(captainPasswordFromUser);
LoginApi.setOldPassword(captainPasswordFromUser);
}
} catch (e) {
errorHandler(e);
}
}
},
{
type: 'input',
name: 'captainRootDomain',
message:
'Enter a root domain for this Captain server. For example, enter test.yourdomain.com if you' +
' setup your DNS to point *.test.yourdomain.com to ip address of your server' +
': ',
filter: async (value: string) => {
try {
const captainRootDomainFromUser = value.trim();
const data = await SystemApi.setCustomDomain(
`http://${SystemApi.ipAddressOfServer}:3000`,
captainRootDomainFromUser
);
if (data) {
const newCustomDomainFromUser = `captain.${captainRootDomainFromUser}`;
SystemApi.setCustomDomainFromUser(newCustomDomainFromUser);
return captainRootDomainFromUser;
}
} catch (e) {
errorHandler(e);
}
}
},
{
type: 'input',
name: 'emailAddress',
message: "Enter your 'valid' email address to enable HTTPS: ",
filter: async (value: string) => {
try {
const emailAddressFromUser = value.trim();
const { customDomainFromUser } = SystemApi;
await SystemApi.enableHttps(`http://${customDomainFromUser}`, emailAddressFromUser);
const data = await SystemApi.forceHttps(`https://${customDomainFromUser}`);
if (data) return emailAddressFromUser;
} catch (e) {
errorHandler(e);
}
}
},
{
type: 'password',
name: 'newPasswordFirstTry',
message: 'Enter a new password:',
filter: (value: string) => {
newPasswordFirstTry = value;
return value;
}
},
{
type: 'password',
name: 'newPassword',
message: 'Enter a new password:',
filter: async (value: string) => {
const { customDomainFromUser } = SystemApi;
try {
const confirmPasswordValueFromUser = value;
const machineUrl = `https://${customDomainFromUser}`;
if (newPasswordFirstTry !== confirmPasswordValueFromUser) {
printError('Passwords do not match', true);
}
const changePassData = await LoginApi.changePass(machineUrl, confirmPasswordValueFromUser);
if (changePassData) {
const loginData = await LoginApi.login(machineUrl, confirmPasswordValueFromUser);
if (loginData) return;
}
} catch (e) {
printError('\nIMPORTANT!! Server setup is completed by password is not changed.');
printError('\nYou CANNOT use serversetup anymore. To continue:');
printError(
`\n- Go to https://${customDomainFromUser} login with default password and change the password in settings.`
);
printError(
`\n- In terminal (here), type captainduckduck login and enter this as your root domain: ${customDomainFromUser}`,
true
);
}
}
},
{
type: 'input',
name: 'captainName',
message: 'Enter a name for this Captain machine:',
default: findDefaultCaptainName(),
validate: (value: string) => {
const newMachineName = value.trim();
MachineHelper.getMachines().map(
(machine) =>
machine.name === newMachineName &&
`${newMachineName} already exist. If you want to replace the existing entry, you have to first use <logout> command, and then re-login.`
);
if (value.match(/^[-\d\w]+$/i)) {
return true;
}
return 'Please enter a Captain Name.';
}
}
];
async function serversetup() {
printMessage('\nSetup your Captain server\n');
const answers = await inquirer.prompt(questions);
const captainAddress = `https://${SystemApi.customDomainFromUser}`;
const newMachine = {
authToken: LoginApi.token,
baseUrl: captainAddress,
name: answers.captainName
};
MachineHelper.addMachine(newMachine);
printMessage(`\n\nCaptain is available at ${captainAddress}`);
printMessage('\nFor more details and docs see http://www.captainduckduck.com\n\n');
}
export = serversetup;
+7 -1
View File
@@ -35,6 +35,10 @@ class MachineHelper {
return [ ...firstItemInOption, ...listOfMachines ];
}
getMachines() {
return this.machines;
}
setMachines(newMachines: IMachine[]) {
this.machines = newMachines;
@@ -104,4 +108,6 @@ class MachineHelper {
}
}
module.exports = new MachineHelper();
const instance = new MachineHelper();
export default instance;
+1 -2
View File
@@ -161,8 +161,7 @@ function deleteFileFromDisk(filePath: string) {
fs.removeSync(filePath);
}
}
module.exports = {
export = {
gitArchiveFile,
getFileStream,
uploadFile,
+4 -5
View File
@@ -1,6 +1,5 @@
import { IMachine } from '../models/IModels';
const MachineHelper = require('../helpers/MachineHelper');
import MachineHelper from '../helpers/MachineHelper';
function cleanUpUrl(url: string) {
if (!url || !url.length) return null;
@@ -17,7 +16,7 @@ function cleanUpUrl(url: string) {
}
function findDefaultCaptainName() {
let currentSuffix = MachineHelper.machines.length + 1;
let currentSuffix = MachineHelper.getMachines().length + 1;
while (!isSuffixValid(currentSuffix)) {
currentSuffix++;
@@ -33,11 +32,11 @@ function getCaptainFullName(suffix: number) {
}
const isSuffixValid = (suffixNumber: number) =>
MachineHelper.machines.map((machine: IMachine) => {
MachineHelper.getMachines().map((machine: IMachine) => {
machine.name !== getCaptainFullName(suffixNumber);
});
module.exports = {
export = {
cleanUpUrl,
findDefaultCaptainName,
isSuffixValid,
+1 -1
View File
@@ -52,7 +52,7 @@ function saveMachineToLocalStorage() {
}
}
module.exports = {
export = {
initMachineFromLocalStorage,
saveMachineToLocalStorage
};
+5 -13
View File
@@ -4,7 +4,7 @@ const { printError } = require('./messageHandler');
const { requestLogin } = require('../commands/login');
const { initMachineFromLocalStorage } = require('../utils/machineUtils');
function validateIsGitRepository() {
export function validateIsGitRepository() {
const gitFolderExists = fs.pathExistsSync('./.git');
if (!gitFolderExists) {
@@ -15,7 +15,7 @@ function validateIsGitRepository() {
}
}
function validateDefinitionFile() {
export function validateDefinitionFile() {
const captainDefinitionExists = fs.pathExistsSync('./captain-definition');
if (!captainDefinitionExists) {
@@ -53,7 +53,7 @@ function validateDefinitionFile() {
}
// Only show that question if there is no option given as argument
function optionIsNotGiven(allOptions: { [id: string]: any }, option: string) {
export function optionIsNotGiven(allOptions: { [id: string]: any }, option: string) {
// console.log(allOptions)
if (allOptions[option]) {
return false;
@@ -62,7 +62,7 @@ function optionIsNotGiven(allOptions: { [id: string]: any }, option: string) {
return true;
}
function isIpAddress(ipaddress: string) {
export 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
@@ -74,7 +74,7 @@ function isIpAddress(ipaddress: string) {
return false;
}
async function validateAuthentication() {
export async function validateAuthentication() {
// 1. Check if valid auth
const isAuthenticated = await DeployApi.isAuthTokenValid();
@@ -92,11 +92,3 @@ async function validateAuthentication() {
return Boolean(isAuthenticated);
}
}
module.exports = {
validateAuthentication,
validateIsGitRepository,
validateDefinitionFile,
isIpAddress,
optionIsNotGiven
};