aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils/common/path.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-17 11:58:15 +0100
committerChocobozzz <me@florianbigard.com>2021-12-17 12:24:03 +0100
commitc55e3d7227fe1453869e309025996b9d75256d5d (patch)
tree08e9b0ca210d75c82c8606fef0852eca020e8e0e /shared/core-utils/common/path.ts
parentbf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (diff)
downloadPeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.gz
PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.zst
PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.zip
Move test functions outside extra-utils
Diffstat (limited to 'shared/core-utils/common/path.ts')
-rw-r--r--shared/core-utils/common/path.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/shared/core-utils/common/path.ts b/shared/core-utils/common/path.ts
new file mode 100644
index 000000000..ec507538b
--- /dev/null
+++ b/shared/core-utils/common/path.ts
@@ -0,0 +1,46 @@
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
10 if (basename(rootPath) === 'common') rootPath = resolve(rootPath, '..')
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
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
41export {
42 root,
43 buildPath,
44 buildAbsoluteFixturePath,
45 getLowercaseExtension
46}