@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
56 lines • 1.95 kB
JavaScript
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 (options = {}) => {
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 {
firestore,
storage
} = options;
if (firestore || !storage) {
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 rules to ${chalk.bold(projectId)}?`
}]);
if (confirm.value) {
const spinner = logger.spinner('Deploying Firestore rules...');
try {
execSync('firebase deploy', {
stdio: 'inherit',
project: projectId,
only: 'firestore:rules'
});
spinner.succeed('Firestore rules deployed successfully.');
} catch (error) {
spinner.fail('Deployment failed. See the error above for details.');
}
} else {
logger.warning('Deployment canceled by the user.');
}
} else if (options['storage']) {
logger.warning('Storage rules are not yet supported.');
}
});
};