import findup from 'find-up' ; import fsExtra from 'fs-extra' ; import path from 'path' ; export function getPackageJsonPath ( ) { return findClosestPackageJson ( __filename ) ! ; } export function getPackageRoot ( ) { const packageJsonPath = getPackageJsonPath ( ) ; return path . dirname ( packageJsonPath ) ; } export interface PackageJson { name : string ; version : string ; engines : { node : string ; } ; } export function findClosestPackageJson ( file ) { return findup . sync ( 'package.json' , { cwd : path . dirname ( file ) } ) ; } export async function getPackageJson ( ) { const root = getPackageRoot ( ) ; return fsExtra . readJSON ( path . join ( root , 'package.json' ) ) ; } export function getRedspotVersion ( ) { const packageJsonPath = findClosestPackageJson ( __filename ) ; if ( packageJsonPath === null ) { return null ; } try { const packageJson = fsExtra . readJsonSync ( packageJsonPath ) ; return packageJson . version ; } catch ( e ) { return null ; } }