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
|
|
|
} |