UNPKG

@topgroup/diginext

Version:

A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.

98 lines (97 loc) 4.57 kB
"use strict"; 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.createApp = void 0; const log_1 = require("diginext-utils/dist/xconsole/log"); const fs_1 = __importDefault(require("fs")); // import Listr from "listr"; const path_1 = __importDefault(require("path")); const app_helper_1 = require("../../modules/apps/app-helper"); const framework_1 = require("../../modules/framework"); const initalizeAndCreateDefaultBranches_1 = require("../../modules/git/initalizeAndCreateDefaultBranches"); const printInformation_1 = require("../../modules/project/printInformation"); const create_empty_app_dir_1 = require("./create-empty-app-dir"); const new_app_by_form_1 = require("./new-app-by-form"); /** * Create new app with pre-setup: git, cli, config,... */ async function createApp(options) { const { DB } = await Promise.resolve().then(() => __importStar(require("../../modules/api/DB"))); // FORM > Create new project & app: const newApp = await (0, new_app_by_form_1.createAppByForm)(options); // console.log("newApp :>> ", newApp); // make sure it always create new directory: options.skipCreatingDirectory = false; if (!options.project) { (0, log_1.logError)(`Project is required for creating new app.`); return; } options.projectSlug = options.project.slug; // setup git: options.repoSlug = `${options.projectSlug}-${newApp.slug}`.toLowerCase(); if (typeof options.targetDirectory == "undefined") options.targetDirectory = path_1.default.resolve(process.cwd(), options.repoSlug); const { skipCreatingDirectory } = options; if (!skipCreatingDirectory) { if (fs_1.default.existsSync(options.targetDirectory)) { if (options.overwrite) { fs_1.default.rmSync(options.targetDirectory, { recursive: true, force: true }); } else { (0, log_1.logError)(`App directory with name "${options.repoSlug}" was already existed.`); return; } } if (!fs_1.default.existsSync(options.targetDirectory)) fs_1.default.mkdirSync(options.targetDirectory); } if (options.isDebugging) console.log("createApp() > options.framework :>> ", options.framework); // pull/clone framework... if (options.framework && options.framework.slug !== "none") { await (0, framework_1.pullingFramework)(options); } else { await (0, create_empty_app_dir_1.createEmptyAppDirectory)(options); } // update git info to database const updateAppData = { git: { provider: options.gitProvider, repoSSH: options.repoSSH, repoURL: options.repoURL } }; if (options.isDebugging) console.log("[NEW APP] updateAppData :>> ", updateAppData); const updatedApp = await DB.updateOne("app", { slug: options.slug }, updateAppData); if (!updatedApp) throw new Error("Unable to create new app, try again with `--debug` flag to diagnose."); // setup git remote & create initial commits, branches await (0, initalizeAndCreateDefaultBranches_1.initalizeAndCreateDefaultBranches)(options); // print project information: const finalConfig = (0, app_helper_1.getAppConfigFromApp)(updatedApp); (0, printInformation_1.printInformation)(finalConfig); return newApp; } exports.default = createApp; exports.createApp = createApp;