fix: proper error handling when conf does not exists (#106)

This commit is contained in:
Adam Uhlíř 2022-05-10 17:56:30 +02:00 committed by GitHub
parent 97ad7c80d9
commit c1a1d3a885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,16 +16,26 @@ export function stripCommit(version: string): string {
async function searchPackageJson(): Promise<string | undefined> {
const expectedPath = path.join(process.cwd(), 'package.json')
const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' }))
return pkgJson?.engines?.bee
try {
const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' }))
return pkgJson?.engines?.bee
} catch (e) {
return undefined
}
}
async function searchBeeFactory(): Promise<string | undefined> {
const expectedPath = path.join(process.cwd(), '.beefactory.json')
const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' }))
return pkgJson?.version
try {
const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' }))
return pkgJson?.version
} catch (e) {
return undefined
}
}
export async function findBeeVersion(): Promise<string> {