UNPKG

git-bolt

Version:

Git utilities for faster development

39 lines (32 loc) 1.06 kB
import chalk from 'chalk'; import fs from 'fs'; import git from 'isomorphic-git'; import { saveGitHubToken } from '../utils/auth.js'; import { askQuestion, closeReadlineInterface } from '../utils/input.js'; async function initCommand(repoUrl, options) { try { // Get token from options, environment, or ask user let token = options.token || process.env.GITHUB_TOKEN; if (!token) { token = await askQuestion('Enter your GitHub personal access token: '); } // Save token await saveGitHubToken(token); // Initialize repository await git.init({ fs, dir: '.' }); // Add remote await git.addRemote({ fs, dir: '.', remote: 'origin', url: repoUrl }); console.log(chalk.green('Repository initialized successfully!')); } catch (error) { console.error(chalk.red('Error:'), error.message); process.exit(1); } finally { closeReadlineInterface(); } } export { initCommand };