]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/common/path.ts
Fix redis connection timeout
[github/Chocobozzz/PeerTube.git] / shared / core-utils / common / path.ts
CommitLineData
06aad801 1import { basename, extname, isAbsolute, join, resolve } from 'path'
2
3let rootPath: string
4
5function root () {
6 if (rootPath) return rootPath
7
8 rootPath = __dirname
9
c55e3d72 10 if (basename(rootPath) === 'common') rootPath = resolve(rootPath, '..')
06aad801 11 if (basename(rootPath) === 'core-utils') rootPath = resolve(rootPath, '..')
12 if (basename(rootPath) === 'shared') rootPath = resolve(rootPath, '..')
13 if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..')
14 if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..')
15
16 return rootPath
17}
18
19function buildPath (path: string) {
20 if (isAbsolute(path)) return path
21
22 return join(root(), path)
23}
24
25function getLowercaseExtension (filename: string) {
26 const ext = extname(filename) || ''
27
28 return ext.toLowerCase()
29}
30
c55e3d72
C
31function buildAbsoluteFixturePath (path: string, customCIPath = false) {
32 if (isAbsolute(path)) return path
33
34 if (customCIPath && process.env.GITHUB_WORKSPACE) {
35 return join(process.env.GITHUB_WORKSPACE, 'fixtures', path)
36 }
37
38 return join(root(), 'server', 'tests', 'fixtures', path)
39}
40
06aad801 41export {
42 root,
43 buildPath,
c55e3d72 44 buildAbsoluteFixturePath,
06aad801 45 getLowercaseExtension
46}