import { realpathSync as realpath, accessSync as access, existsSync as exists } from 'fs'
import { dirname } from 'path'
/**
* IIFE to resolve Magento document root
* @returns <string> Returns Magento document root
*/
export const mageRoot = (() => {
let mageRoot = dirname(realpath(import.meta.url.slice(7)))
while (!(exists(`${ mageRoot }/app/Mage.php`) || exists(`${ mageRoot }/bin/magento`))) {
mageRoot = dirname(mageRoot)
}
return mageRoot
})()