-
Notifications
You must be signed in to change notification settings - Fork 375
/
pathUtil.ts
112 lines (103 loc) · 3.1 KB
/
pathUtil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import * as fs from 'fs';
import * as path from 'path';
import * as Constants from './constants';
import { RemoteServerCode } from '../../index';
/**
* Get system remote service path
*
* @param {String} role server role: frontend, backend
* @return {String} path string if the path exist else null
*/
export function getSysRemotePath(role : string)
{
let p = path.join(__dirname, '/../common/remote/', role);
return fs.existsSync(p) ? p : null;
};
/**
* Get user remote service path
*
* @param {String} appBase application base path
* @param {String} serverType server type
* @return {String} path string if the path exist else null
*/
export function getUserRemotePath(appBase : string, serverType : string)
{
let p = path.join(appBase, '/app/servers/', serverType, Constants.DIR.REMOTE);
return fs.existsSync(p) ? p : null;
};
/**
* Get user remote cron path
*
* @param {String} appBase application base path
* @param {String} serverType server type
* @return {String} path string if the path exist else null
*/
export function getCronPath(appBase : string, serverType : string)
{
let p = path.join(appBase, '/app/servers/', serverType, Constants.DIR.CRON);
return fs.existsSync(p) ? p : null;
};
/**
* List all the subdirectory names of user remote directory
* which hold the codes for all the server types.
*
* @param {String} appBase application base path
* @return {Array} all the subdiretory name under servers/
*/
export function listUserRemoteDir(appBase : string)
{
let base = path.join(appBase, '/app/servers/');
let files = fs.readdirSync(base);
return files.filter(function (fn)
{
if (fn.charAt(0) === '.')
{
return false;
}
return fs.statSync(path.join(base, fn)).isDirectory();
});
};
/**
* Compose remote path record
*
* @param {String} namespace remote path namespace, such as: 'sys', 'user'
* @param {String} serverType
* @param {String} path remote service source path
* @return {Object} remote path record
*/
export function remotePathRecord(namespace : string, serverType : string, path : string) : RemoteServerCode
{
return { namespace: namespace, serverType: serverType, path: path };
};
/**
* Get handler path
*
* @param {String} appBase application base path
* @param {String} serverType server type
* @return {String} path string if the path exist else null
*/
export function getHandlerPath(appBase : string, serverType : string)
{
let p = path.join(appBase, '/app/servers/', serverType, Constants.DIR.HANDLER);
return fs.existsSync(p) ? p : null;
};
/**
* Get admin script root path.
*
* @param {String} appBase application base path
* @return {String} script path string
*/
export function getScriptPath(appBase : string)
{
return path.join(appBase, Constants.DIR.SCRIPT);
};
/**
* Get logs path.
*
* @param {String} appBase application base path
* @return {String} logs path string
*/
export function getLogPath(appBase : string)
{
return path.join(appBase, Constants.DIR.LOG);
};