@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
163 lines (162 loc) • 7.03 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.cloneRepo = void 0;
const chalk_1 = __importDefault(require("chalk"));
const console_1 = __importDefault(require("console"));
const log_1 = require("diginext-utils/dist/xconsole/log");
const fs = __importStar(require("fs"));
const path_1 = __importDefault(require("path"));
const app_helper_1 = require("../../modules/apps/app-helper");
const selectApp_1 = __importDefault(require("../../modules/apps/selectApp"));
const selectProject_1 = __importDefault(require("../../modules/apps/selectProject"));
const framework_1 = require("../../modules/framework");
const ask_for_git_provider_1 = require("../../modules/git/ask-for-git-provider");
const initalizeAndCreateDefaultBranches_1 = require("../../modules/git/initalizeAndCreateDefaultBranches");
const printInformation_1 = require("../../modules/project/printInformation");
const plugins_1 = require("../../plugins");
//
async function transferRepo(options) {
var _a, _b, _c;
options.project = await (0, selectProject_1.default)(options, false);
options.app = await (0, selectApp_1.default)(options, false);
console_1.default.log(chalk_1.default.yellow("Chọn git provider muốn clone đến (Đừng chọn bitbucket, chưa test! )"));
const oldData = {
provider: options.app.git.provider,
repoSSH: options.app.git.repoSSH,
repoURL: options.app.git.repoURL,
};
// console.log("oldData :>> ", oldData);
// console.log("options :>> ", options);
// {
// // Repo URL : https://bitbucket.org/digitopvn/test-project-gaol-webapp
// // Remote SSH : git@bitbucket.org:digitopvn/test-project-gaol-webapp.git
// const [updatedApp] = await DB.update(
// "app",
// { slug: options.slug },
// {
// git: {
// //
// provider: "bitbucket",
// repoSSH: "git@bitbucket.org:digitopvn/test-project-gaol-webapp.git",
// repoURL: "https://bitbucket.org/digitopvn/test-project-gaol-webapp",
// },
// }
// );
// console.log("updatedApp :>> ", updatedApp);
// }
// return;
let gitProvider = await (0, ask_for_git_provider_1.askForGitProvider)();
options.targetDirectory = path_1.default.resolve(process.cwd(), options.repoSlug);
if (fs.existsSync(options.targetDirectory)) {
if (options.overwrite) {
fs.rmSync(options.targetDirectory, { recursive: true, force: true });
}
else {
(0, log_1.logError)(`App directory with name "${options.slug}" was already existed.`);
return;
}
}
if (!fs.existsSync(options.targetDirectory))
fs.mkdirSync(options.targetDirectory);
const __option = {
framework: {
...options.app.framework,
...(_a = options.app) === null || _a === void 0 ? void 0 : _a.git,
name: (_c = (_b = options.app) === null || _b === void 0 ? void 0 : _b.git) === null || _c === void 0 ? void 0 : _c.repoSSH,
},
targetDirectory: options.targetDirectory,
};
const success = await (0, framework_1.pullingRepoToNewGitDir)(__option);
if (!success)
return;
await (0, plugins_1.wait)(500);
// //create git in github
// Create new repo:
const repoData = {
name: options.repoSlug,
private: !options.isPublic,
};
if (options.isDebugging)
console_1.default.log("[cloneRepo] CREATE REPO > repoData :>> ", repoData);
if (options.app.git.provider != gitProvider.type) {
//
const { DB } = await Promise.resolve().then(() => __importStar(require("../../modules/api/DB")));
const newRepo = await DB.create("git_repo", repoData, {
subpath: "/orgs/repos",
filter: { slug: gitProvider.slug },
});
if (options.isDebugging)
console_1.default.log("[cloneRepo] CREATE REPO > newRepo :>> ", newRepo);
if (newRepo) {
options.gitProvider = newRepo.provider;
options.repoSSH = newRepo.ssh_url;
options.repoURL = newRepo.repo_url;
}
else {
options.gitProvider = gitProvider.type;
options.repoSSH = `git@github.com:digitopvn/${options.repoSlug}.git`;
options.repoURL = `https://github.com/digitopvn/${options.repoSlug}.git`;
}
// update git info to database
const [updatedApp] = await DB.update("app", { slug: options.slug }, { git: { provider: options.gitProvider, repoSSH: options.repoSSH, repoURL: options.repoURL } });
if (!updatedApp) {
(0, log_1.logError)("Can't create new app due to network issue while updating git repo info.");
return;
}
}
else {
options.gitProvider = options.app.git.provider;
options.repoSSH = options.app.git.repoSSH;
options.repoURL = options.app.git.repoURL;
}
options.app.git = {
provider: options.gitProvider,
repoSSH: options.repoSSH,
repoURL: options.repoURL,
};
const { DB } = await Promise.resolve().then(() => __importStar(require("../../modules/api/DB")));
// return;
// // first commit & create default branches (main, dev/*)
const error = await (0, initalizeAndCreateDefaultBranches_1.initalizeAndCreateDefaultBranches)(options);
if (error) {
// update git info to database
const [updatedApp] = await DB.update("app", { slug: options.slug }, {
git: {
...oldData,
},
});
return;
// error
}
// print project information:
const finalConfig = (0, app_helper_1.getAppConfigFromApp)(options.app);
(0, printInformation_1.printInformation)(finalConfig);
}
exports.default = transferRepo;
exports.cloneRepo = transferRepo;