fix(.oh-my-zsh/custom/getFirebaseProject.js): add error handling if "firebase-tools.json" was not found

This commit is contained in:
Anton Shubin 2020-04-07 21:50:16 +03:00
parent 191cba3ad9
commit 37d613f932

View File

@ -1,7 +1,19 @@
const json = require(`${process.env.HOME}/.config/configstore/firebase-tools.json`); const { readFileSync } = require(`fs`);
const firebaseProjectName = json.activeProjects[process.argv[2]]; const folderPath = process.argv[2];
try {
const pathToFirebaseToolsJson = `${process.env.HOME}/.config/configstore/firebase-tools.json`;
const fileContent = readFileSync(pathToFirebaseToolsJson);
const firebaseToolsJson = JSON.parse(fileContent);
const firebaseProjectName = firebaseToolsJson.activeProjects[folderPath];
if (firebaseProjectName) { if (firebaseProjectName) {
console.log(firebaseProjectName); console.log(firebaseProjectName);
} }
} catch (error) {
if (error.code && error.code === "ENOENT") {
console.error(`Couldn't find file "${pathToFirebaseToolsJson}". Please create it with "$ firebase use <projectName>" in your project folder.`);
} else {
console.error(error);
}
}