@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
40 lines • 1.33 kB
JavaScript
import fs from 'fs';
import inquirer from 'inquirer';
export default (firebasercPath, options = {}) => {
const {
promptMessage = 'Select a Google Cloud project:',
environment
} = options;
if (!fs.existsSync(firebasercPath)) {
Promise.reject(new Error('.firebaserc not found. Make sure you run this cmd from the root of your project. ' + 'A .firebaserc configuration file is required to continue.'));
}
const config = JSON.parse(fs.readFileSync(firebasercPath));
if (!config.projects) {
Promise.reject(new Error('No projects defined. Please add a projects property to your .firebaserc file.'));
}
if (environment) {
if (!config.projects[environment]) {
Promise.reject(new Error(`No project found for environment ${environment}. ` + `Please add a projects.${environment} property to your .firebaserc file.`));
} else {
return Promise.resolve({
projectId: config.projects[environment],
config
});
}
}
return inquirer.prompt([{
type: 'list',
name: 'projectId',
message: promptMessage,
choices: Object.entries(config.projects).map(([environment, projectId]) => ({
name: `${projectId} (${environment})`,
value: projectId,
short: projectId
}))
}]).then(({
projectId
}) => ({
projectId,
config
}));
};