Passed
Pull Request — develop (#34)
by Bjarn
01:38
created

src/utils/jale.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 71
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 2
mnd 0
bc 0
fnc 2
bpm 0
cpm 1
noi 0
1
import * as fs from 'fs'
2
import {homedir} from 'os'
3
import {Config} from '../models/config'
4
import {ensureDirectoryExists} from './filesystem'
5
6
/**
7
 * Get the location of the home directory of Jale.
8
 */
9
const jaleHomeDir = `${homedir()}/.jale`
10
11
/**
12
 * Get the location of the Jale configuration.
13
 */
14
const jaleConfigPath = `${jaleHomeDir}/config.json`
15
16
/**
17
 * Get the location of the Jale log directory.
18
 */
19
const jaleLogsPath = `${jaleHomeDir}/log`
20
21
/**
22
 * Get the location of the Jale sites directory.
23
 */
24
const jaleSitesPath = `${jaleHomeDir}/sites`
25
26
/**
27
 * Get the location of the Jale certificates directory.
28
 */
29
const jaleSslPath = `${jaleHomeDir}/ssl`
30
31
/**
32
 * Get the location of the fallback server of Jale.
33
 */
34
const jaleFallbackServer = `${jaleHomeDir}/server/index.php`
35
36
/**
37
 * Get the location of the Nginx apps vhost directory.
38
 */
39
const jaleNginxAppsPath = '/usr/local/etc/nginx/jale/apps'
40
41
/**
42
 * Get the location of the Nginx app templates vhost directory.
43
 */
44
const jaleNginxAppTemplatesPath = '/usr/local/etc/nginx/jale/templates'
45
46
/**
47
 * Ensure the Jale home directory exists. If it does not exist, we'll create it.
48
 *
49
 * Returns the current location of the Jale home directory.
50
 */
51
async function ensureHomeDirExists(): Promise<false | string> {
52
    return ensureDirectoryExists(jaleHomeDir)
53
}
54
55
function getConfig(): Config {
56
    const rawConfig: string = fs.readFileSync(jaleConfigPath, 'utf-8')
57
    return JSON.parse(rawConfig)
58
}
59
60
export {
61
    jaleHomeDir,
62
    jaleConfigPath,
63
    jaleLogsPath,
64
    jaleSslPath,
65
    jaleSitesPath,
66
    jaleFallbackServer,
67
    jaleNginxAppsPath,
68
    jaleNginxAppTemplatesPath,
69
    ensureHomeDirExists,
70
    getConfig
71
}