diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-17 11:58:15 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-17 12:24:03 +0100 |
commit | c55e3d7227fe1453869e309025996b9d75256d5d (patch) | |
tree | 08e9b0ca210d75c82c8606fef0852eca020e8e0e /shared/core-utils/common/path.ts | |
parent | bf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (diff) | |
download | PeerTube-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.ts | 46 |
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 @@ | |||
1 | import { basename, extname, isAbsolute, join, resolve } from 'path' | ||
2 | |||
3 | let rootPath: string | ||
4 | |||
5 | function 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 | |||
19 | function buildPath (path: string) { | ||
20 | if (isAbsolute(path)) return path | ||
21 | |||
22 | return join(root(), path) | ||
23 | } | ||
24 | |||
25 | function getLowercaseExtension (filename: string) { | ||
26 | const ext = extname(filename) || '' | ||
27 | |||
28 | return ext.toLowerCase() | ||
29 | } | ||
30 | |||
31 | function 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 | |||
41 | export { | ||
42 | root, | ||
43 | buildPath, | ||
44 | buildAbsoluteFixturePath, | ||
45 | getLowercaseExtension | ||
46 | } | ||