UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

48 lines 1.7 kB
import fs from 'fs'; import path from 'path'; import chalk from 'chalk'; import inquirer from 'inquirer'; import { workspace, logger, selectProject, execSync } from './../../utils/index.js'; const getFirebaseJson = () => { const firebaseJsonPath = path.join(process.cwd(), 'firebase.json'); if (!fs.existsSync(firebaseJsonPath)) { logger.error('No firebase.json file found. ' + 'Make sure you run this command in the root of the Atlas project.'); } return JSON.parse(fs.readFileSync(firebaseJsonPath)); }; export default () => { if (!workspace.isOnBranch('master', 'main')) { logger.warning('You are not on the master/main branch. Be careful selecting the project!'); } selectProject('.firebaserc', { promptMessage: 'Select a Google Cloud Project to deploy to:' }).then(async ({ projectId }) => { const firebaseJson = getFirebaseJson(); if (!firebaseJson.firestore) { logger.error('No firestore settings found in firebase.json.'); } const confirm = await inquirer.prompt([{ type: 'confirm', name: 'value', default: false, message: `Deploy all Firestore indexes to ${chalk.bold(projectId)}?` }]); if (confirm.value) { const spinner = logger.spinner('Deploying Firestore indexes...'); try { execSync('firebase deploy', { stdio: 'inherit', project: projectId, only: 'firestore:indexes' }); spinner.succeed('Firestore indexes deployed successfully.'); } catch (error) { spinner.fail('Deployment failed. See the error above for details.'); } } else { logger.warning('Deployment canceled by the user.'); } }); };