diff options
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r-- | server/tools/cli.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts new file mode 100644 index 000000000..9a170d4da --- /dev/null +++ b/server/tools/cli.ts | |||
@@ -0,0 +1,63 @@ | |||
1 | const config = require('application-config')('PeerTube/CLI') | ||
2 | const netrc = require('netrc-parser').default | ||
3 | |||
4 | const version = () => { | ||
5 | const tag = require('child_process') | ||
6 | .execSync('[[ ! -d .git ]] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', { stdio: [0,1,2] }) | ||
7 | if (tag) return tag | ||
8 | |||
9 | const version = require('child_process') | ||
10 | .execSync('[[ ! -d .git ]] || git rev-parse --short HEAD').toString().trim() | ||
11 | if (version) return version | ||
12 | |||
13 | return require('../../../package.json').version | ||
14 | } | ||
15 | |||
16 | let settings = { | ||
17 | remotes: [], | ||
18 | default: 0 | ||
19 | } | ||
20 | |||
21 | interface Settings { | ||
22 | remotes: any[], | ||
23 | default: number | ||
24 | } | ||
25 | |||
26 | async function getSettings () { | ||
27 | return new Promise<Settings>((res, rej) => { | ||
28 | let settings = { | ||
29 | remotes: [], | ||
30 | default: 0 | ||
31 | } as Settings | ||
32 | config.read((err, data) => { | ||
33 | if (err) { | ||
34 | return rej(err) | ||
35 | } | ||
36 | return res(data || settings) | ||
37 | }) | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | async function writeSettings (settings) { | ||
42 | return new Promise((res, rej) => { | ||
43 | config.write(settings, function (err) { | ||
44 | if (err) { | ||
45 | return rej(err) | ||
46 | } | ||
47 | return res() | ||
48 | }) | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | netrc.loadSync() | ||
53 | |||
54 | // --------------------------------------------------------------------------- | ||
55 | |||
56 | export { | ||
57 | version, | ||
58 | config, | ||
59 | settings, | ||
60 | getSettings, | ||
61 | writeSettings, | ||
62 | netrc | ||
63 | } | ||