UNPKG

novu

Version:

Novu CLI. Run Novu Studio and sync workflows with Novu Cloud

62 lines (61 loc) 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.tryGitInit = tryGitInit; const child_process_1 = require("child_process"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); function isInGitRepository() { try { (0, child_process_1.execSync)('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }); return true; } catch (_) { } return false; } function isInMercurialRepository() { try { (0, child_process_1.execSync)('hg --cwd . root', { stdio: 'ignore' }); return true; } catch (_) { } return false; } function isDefaultBranchSet() { try { (0, child_process_1.execSync)('git config init.defaultBranch', { stdio: 'ignore' }); return true; } catch (_) { } return false; } function tryGitInit(root) { let didInit = false; try { (0, child_process_1.execSync)('git --version', { stdio: 'ignore' }); if (isInGitRepository() || isInMercurialRepository()) { return false; } (0, child_process_1.execSync)('git init', { stdio: 'ignore' }); didInit = true; if (!isDefaultBranchSet()) { (0, child_process_1.execSync)('git checkout -b main', { stdio: 'ignore' }); } (0, child_process_1.execSync)('git add -A', { stdio: 'ignore' }); (0, child_process_1.execSync)('git commit -m "Initial commit from Create Novu App"', { stdio: 'ignore', }); return true; } catch (e) { if (didInit) { try { fs_1.default.rmSync(path_1.default.join(root, '.git'), { recursive: true, force: true }); } catch (_) { } } return false; } }