2021-11-02 13:11:20 -05:00
|
|
|
import { basename, extname, isAbsolute, join, resolve } from 'path'
|
|
|
|
|
|
|
|
let rootPath: string
|
|
|
|
|
|
|
|
function root () {
|
|
|
|
if (rootPath) return rootPath
|
|
|
|
|
|
|
|
rootPath = __dirname
|
|
|
|
|
2022-01-03 10:13:11 -06:00
|
|
|
if (basename(rootPath) === 'tools') rootPath = resolve(rootPath, '..')
|
|
|
|
if (basename(rootPath) === 'scripts') rootPath = resolve(rootPath, '..')
|
2021-12-17 04:58:15 -06:00
|
|
|
if (basename(rootPath) === 'common') rootPath = resolve(rootPath, '..')
|
2021-11-02 13:11:20 -05:00
|
|
|
if (basename(rootPath) === 'core-utils') rootPath = resolve(rootPath, '..')
|
|
|
|
if (basename(rootPath) === 'shared') rootPath = resolve(rootPath, '..')
|
|
|
|
if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..')
|
|
|
|
if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..')
|
|
|
|
|
|
|
|
return rootPath
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildPath (path: string) {
|
|
|
|
if (isAbsolute(path)) return path
|
|
|
|
|
|
|
|
return join(root(), path)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLowercaseExtension (filename: string) {
|
|
|
|
const ext = extname(filename) || ''
|
|
|
|
|
|
|
|
return ext.toLowerCase()
|
|
|
|
}
|
|
|
|
|
2021-12-17 04:58:15 -06:00
|
|
|
function buildAbsoluteFixturePath (path: string, customCIPath = false) {
|
|
|
|
if (isAbsolute(path)) return path
|
|
|
|
|
|
|
|
if (customCIPath && process.env.GITHUB_WORKSPACE) {
|
|
|
|
return join(process.env.GITHUB_WORKSPACE, 'fixtures', path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return join(root(), 'server', 'tests', 'fixtures', path)
|
|
|
|
}
|
|
|
|
|
2021-11-02 13:11:20 -05:00
|
|
|
export {
|
|
|
|
root,
|
|
|
|
buildPath,
|
2021-12-17 04:58:15 -06:00
|
|
|
buildAbsoluteFixturePath,
|
2021-11-02 13:11:20 -05:00
|
|
|
getLowercaseExtension
|
|
|
|
}
|