import { existsSync , mkdirSync , mkdtempSync , readdirSync , readFileSync , rmdirSync , writeFileSync , } from 'fs' ; import { copySync } from 'fs-extra' ; import { homedir } from 'os' ; import { basename } from 'path' ; import { JSONObject } from '../interfaces' ; import { isWindows } from './environment-info' ; import { execCommand } from './system' ; export function pathExists ( path ) { return existsSync ( path ) ; } export function readDir ( path ) { return readdirSync ( path ) ; } export function readJSON ( path ) { const fileContent = readFileSync ( path , 'utf8' ) ; if ( ! fileContent ) return undefined ; return JSON . parse ( fileContent ) ; } export function writeJSON ( path , object ) { writeFileSync ( path , JSON . stringify ( object ) ) ; } export function createDir ( path ) { return mkdirSync ( path ) ; } export function createTempDir ( name ) { return mkdtempSync ( name ) ; } export function copy ( from , to ) { copySync ( from , to ) ; } export function removeRecursively ( path ) { rmdirSync ( path , { recursive : true } ) ; } export function getHomeDirectory ( ) { return isWindows ( ) ? homedir ( ) : execCommand ( 'eval echo ~${SUDO_USER}' ) ; } export function getCurrentDirectory ( ) { return basename ( process . cwd ( ) ) ; }