]>
Commit | Line | Data |
---|---|---|
06aad801 | 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 | ||
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 | ||
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 | ||
c55e3d72 C |
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 | ||
06aad801 | 41 | export { |
42 | root, | |
43 | buildPath, | |
c55e3d72 | 44 | buildAbsoluteFixturePath, |
06aad801 | 45 | getLowercaseExtension |
46 | } |