import * as fs from "fs" ; /**
 * Typing for the fields of package.json we care about
 */ export interface PackageJson { [ key ] : string ; } /**
 * A function that json from a file
 */ export interface ReadJsonSync { ( packageJsonPath ) : any | undefined ; } export interface FileExistsSync { ( name ) : boolean ; } export interface FileExistsAsync { ( path , callback ) : void ; } export interface ReadJsonAsyncCallback { ( err ? , content ? ) : void ; } export interface ReadJsonAsync { ( path , callback ) : void ; } export function fileExistsSync ( path ) { try { const stats = fs . statSync ( path ) ; return stats . isFile ( ) ; } catch ( err ) { return false ; } } param file export function readJsonFromDiskSync ( packageJsonPath ) { if ( ! fs . existsSync ( packageJsonPath ) ) { return undefined ; } return require ( packageJsonPath ) ; } export function readJsonFromDiskAsync ( path , callback ) { fs . readFile ( path , "utf8" , ( err , result ) => { if ( err || ! result ) { return callback ( ) ; } const json = JSON . parse ( result ) ; return callback ( undefined , json ) ; } ) ; } export function fileExistsAsync ( path2 , callback2 ) { fs . stat ( path2 , ( err , stats ) => { if ( err ) { return callback2 ( undefined , false ) ; } callback2 ( undefined , stats ? stats . isFile ( ) : false ) ; } ) ; } export function removeExtension ( path ) { return path . substring ( 0 , path . lastIndexOf ( "." ) ) || path ; }