@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
267 lines (266 loc) • 10.9 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.processCLI = void 0;
// import Configstore from "configstore";
const log_1 = require("diginext-utils/dist/xconsole/log");
const yargs_1 = __importDefault(require("yargs"));
const config_1 = require("./config/config");
const analytics_1 = require("./modules/analytics");
const new_app_1 = __importDefault(require("./modules/apps/new-app"));
const transferRepo_1 = __importDefault(require("./modules/apps/transferRepo"));
const cdn_1 = require("./modules/cdn");
const cli_1 = require("./modules/cli");
const db_1 = require("./modules/db");
const deploy = __importStar(require("./modules/deploy"));
const execDomain_1 = require("./modules/domains/execDomain");
const git_1 = require("./modules/git");
const pipeline_1 = require("./modules/pipeline");
const custom_1 = __importStar(require("./modules/providers/custom"));
const digitalocean_1 = __importStar(require("./modules/providers/digitalocean"));
const gcloud_1 = __importStar(require("./modules/providers/gcloud"));
const registry_1 = require("./modules/registry");
const server_1 = require("./modules/server");
const generateSnippet_1 = __importDefault(require("./modules/snippets/generateSnippet"));
const plugins_1 = require("./plugins");
const exec_ai_1 = require("./modules/ai/exec-ai");
const init_app_1 = require("./modules/apps/init-app");
const view_logs_1 = require("./modules/apps/view-logs");
const request_build_1 = require("./modules/build/request-build");
const start_build_and_run_1 = require("./modules/build/start-build-and-run");
const show_cli_info_1 = require("./modules/cli/show-cli-info");
const update_cli_1 = require("./modules/cli/update-cli");
const cli_cluster_1 = require("./modules/cluster/cli-cluster");
const dotenv_exec_1 = require("./modules/deploy/dotenv-exec");
const parse_options_to_app_config_1 = require("./modules/deploy/parse-options-to-app-config");
const request_deploy_1 = require("./modules/deploy/request-deploy");
const kubectl_cli_1 = require("./modules/k8s/kubectl-cli");
const test_command_1 = require("./modules/test-command");
/**
* Initialize CONFIG STORE (in document directory of the local machine)
*/
// export const conf = new Configstore(pkg.name);
async function processCLI(options) {
options.version = (0, plugins_1.currentVersion)();
let env = "dev";
if (options.isStaging)
env = "staging";
if (options.isProd)
env = "prod";
if (options.env)
env = options.env;
// debugging info
if (options.isDebugging) {
await (0, show_cli_info_1.showClientInfo)(options);
console.log("CLI options :>> ", options);
}
switch (options.action) {
case "test":
await (0, test_command_1.testCommand)(options);
break;
case "info":
await (0, show_cli_info_1.showClientInfo)(options);
break;
case "profile":
await (0, cli_1.showProfile)(options);
break;
case "login":
await (0, cli_1.cliLogin)({
secondAction: options.secondAction,
url: options.url,
accessToken: options.token,
apiToken: options.apiToken,
isDebugging: options.isDebugging,
});
break;
case "logout":
await (0, cli_1.cliLogout)();
break;
case "server":
await (0, cli_1.cliAuthenticate)(options);
await (0, git_1.generateSSH)(); // make sure we got the PUBLIC KEY and PRIVATE KEY for SSH setup later on
await (0, server_1.execServer)(options);
return;
case "config":
await (0, cli_1.cliAuthenticate)(options);
await (0, config_1.execConfig)(options);
break;
case "update":
await (0, update_cli_1.updateCli)();
break;
case "new":
await (0, cli_1.cliAuthenticate)(options);
await (0, new_app_1.default)(options);
break;
case "init":
await (0, cli_1.cliAuthenticate)(options);
await (0, init_app_1.execInitApp)(options);
break;
case "upgrade":
return (0, log_1.logWarn)(`This command is deprecated.`);
case "log":
case "logs":
return (0, view_logs_1.viewAppLogs)(options);
case "ask":
await (0, cli_1.cliAuthenticate)(options);
await (0, exec_ai_1.execAI)(options);
break;
case "cdn":
await (0, cli_1.cliAuthenticate)(options);
await (0, cdn_1.execCDN)(options);
break;
case "auth":
await (0, cli_1.cliAuthenticate)(options);
switch (options.provider) {
case "custom":
await custom_1.default.authenticate(options);
return;
case "digitalocean":
await digitalocean_1.default.authenticate(options);
return;
case "gcloud":
await gcloud_1.default.authenticate(options);
return;
default:
await (0, log_1.log)(`What's up, mate?`);
return;
}
case "registry":
await (0, cli_1.cliAuthenticate)(options);
await (0, registry_1.execRegistry)(options);
return;
case "domain":
await (0, cli_1.cliAuthenticate)(options);
await (0, execDomain_1.execDomain)(options);
return;
case "gcloud":
await (0, cli_1.cliAuthenticate)(options);
options.provider = "gcloud";
await (0, gcloud_1.execGoogleCloud)(options);
return;
case "digitalocean":
await (0, cli_1.cliAuthenticate)(options);
options.provider = "digitalocean";
await (0, digitalocean_1.execDigitalOcean)(options);
return;
case "custom":
await (0, cli_1.cliAuthenticate)(options);
options.provider = "custom";
await (0, custom_1.execCustomProvider)(options);
return;
case "git":
await (0, cli_1.cliAuthenticate)(options);
await (0, git_1.execGit)(options);
return;
case "cluster":
await (0, cli_1.cliAuthenticate)(options);
await (0, cli_cluster_1.execCluster)(options);
return;
case "db":
await (0, cli_1.cliAuthenticate)(options);
await (0, db_1.execDatabase)(options, env);
return;
case "pipeline":
await (0, cli_1.cliAuthenticate)(options);
await (0, pipeline_1.execPipeline)(options);
return;
case "kubectl":
case "kb":
await (0, cli_1.cliAuthenticate)(options);
await (0, kubectl_cli_1.execKubectl)(options);
return;
case "build":
await (0, cli_1.cliAuthenticate)(options);
await (0, request_build_1.requestBuild)(options);
return;
case "run":
await (0, cli_1.cliAuthenticate)(options);
options.isLocal = true;
await (0, parse_options_to_app_config_1.parseOptionsToAppConfig)(options);
await (0, start_build_and_run_1.startBuildAndRun)(options);
return;
case "dotenv":
await (0, cli_1.cliAuthenticate)(options);
await (0, dotenv_exec_1.execDotenvCommand)(options);
return;
case "up":
case "deploy":
await (0, cli_1.cliAuthenticate)(options);
// request server to build & deploy from source
if (options.envs.length > 1) {
// deploy to multiple deploy envs
for (const _env of options.envs) {
options.env = _env;
await (0, request_deploy_1.requestDeploy)(options);
}
}
else {
// deploy to single deploy env
await (0, request_deploy_1.requestDeploy)(options);
}
return;
case "rollout":
return (0, log_1.logWarn)(`This command is deprecated.`);
case "down":
await (0, cli_1.cliAuthenticate)(options);
await deploy.execTakeDown(options);
return;
case "analytics":
await (0, cli_1.cliAuthenticate)(options);
await (0, analytics_1.execAnalytics)(options);
return;
case "free":
return (0, log_1.logWarn)(`This command is deprecated.`);
case "tf":
case "transfer":
await (0, cli_1.cliAuthenticate)(options);
await (0, transferRepo_1.default)(options);
return;
case "snippets":
case "snpt":
await (0, generateSnippet_1.default)(options);
return;
default:
yargs_1.default.showHelp();
break;
}
}
exports.processCLI = processCLI;
// Only start a server mode when needed
if (process.env.CLI_MODE == "server")
Promise.resolve().then(() => __importStar(require("./server")));
// Otherwise, parse & execute CLI commands...
(0, cli_1.parseCliOptions)().then((inputOptions) => !inputOptions.isDebugging
? processCLI(inputOptions)
.then(() => process.exit(0))
.catch((e) => {
(0, log_1.logError)(e.toString());
process.exit(1);
})
: processCLI(inputOptions).then(() => process.exit(1)));