diff --git a/.oh-my-zsh/custom/getFirebaseProject.js b/.oh-my-zsh/custom/getFirebaseProject.js index f34fab6..a25eed0 100644 --- a/.oh-my-zsh/custom/getFirebaseProject.js +++ b/.oh-my-zsh/custom/getFirebaseProject.js @@ -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) { - console.log(firebaseProjectName); + if (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 " in your project folder.`); + } else { + console.error(error); + } } \ No newline at end of file