tiro-notes 0.27.12 → 0.27.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +67 -24
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var spawn = require( 'child_process' ).spawn;
|
|
10
|
-
var child = spawn( cmd, params, {env: { ...process.env, ...p.env }});
|
|
11
|
-
|
|
12
|
-
child.stdout.on( 'data', data => {
|
|
13
|
-
var str = `[${cmd}] : ${data}`;
|
|
14
|
-
console.log( str );
|
|
15
|
-
});
|
|
16
|
-
child.stderr.on( 'data', data => {
|
|
17
|
-
var str = `[${cmd} ERROR!] : ${data}`;
|
|
18
|
-
console.log( str );
|
|
19
|
-
});
|
|
20
|
-
return child;
|
|
3
|
+
const tHelpers = require('../helpers/helpers.platforms.js');
|
|
4
|
+
|
|
5
|
+
// open frontend on default browser
|
|
6
|
+
const openInBrowser = (url) => {
|
|
7
|
+
var start = (process.platform == 'darwin'? 'open': process.platform == 'win32'? 'start': 'xdg-open');
|
|
8
|
+
require('child_process').exec(start + ' ' + url);
|
|
21
9
|
}
|
|
22
10
|
|
|
11
|
+
|
|
23
12
|
function getCliArgs () {
|
|
24
13
|
var args = process.argv;
|
|
25
14
|
var argsObj = {
|
|
26
|
-
port: 3023
|
|
15
|
+
port: 3023,
|
|
16
|
+
tunnel: {
|
|
17
|
+
enabled: false,
|
|
18
|
+
},
|
|
27
19
|
}
|
|
28
20
|
for (var i = 0; i < args.length; i++) {
|
|
29
21
|
if (i % 2 !== 0) continue
|
|
@@ -32,17 +24,68 @@ function getCliArgs () {
|
|
|
32
24
|
var argVal = args[i+1];
|
|
33
25
|
argName = argName.replace('--', '').replace('-','')
|
|
34
26
|
if (argName === 'p' || argName === 'port') argsObj.port = parseInt(argVal);
|
|
27
|
+
if (argName === 't' || argName === 'tunnel') {
|
|
28
|
+
const argsArr = argVal.split(':')
|
|
29
|
+
if (argsArr.length > 1) {
|
|
30
|
+
argsObj.tunnel.enabled = true
|
|
31
|
+
argsObj.tunnel.remoteUrl = argsArr[0]
|
|
32
|
+
argsObj.tunnel.remotePort = parseInt(argsArr[1])
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
return argsObj;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
function startTiroServerAsCli () {
|
|
41
|
-
var argsObj = getCliArgs();
|
|
39
|
+
function startTiroServer (argsObj, cb) {
|
|
42
40
|
console.log(`Starting Tiro-Notes from CLI with following arguments : ${JSON.stringify(argsObj)}`);
|
|
43
|
-
|
|
41
|
+
|
|
42
|
+
// start tiro server, detect success message and get server params
|
|
43
|
+
tHelpers.execCmd('node', [`${__dirname}/server/server.js`], {
|
|
44
44
|
env: { TIRO_PORT: argsObj.port },
|
|
45
|
+
onLog: str => {
|
|
46
|
+
tHelpers.checkAndGetTiroConfig({platform: 'cli'}, cb)
|
|
47
|
+
}
|
|
45
48
|
})
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
const startSshTunnel = (argsObj) => {
|
|
52
|
+
if (argsObj.tunnel.enabled) {
|
|
53
|
+
// kill previous autossh processes
|
|
54
|
+
tHelpers.execCmd('killall', [`autossh`], {logName:'tunnel'})
|
|
55
|
+
|
|
56
|
+
// check if autossh is working
|
|
57
|
+
try {
|
|
58
|
+
tHelpers.execCmd('autossh', [`--help`], {logName:'tunnel'})
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw Error('autossh not installed on the system, please install it.')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// check if autossh enabled
|
|
64
|
+
tHelpers.execCmd('autossh', ['-M','20000','-f','-N',argsObj.tunnel.remoteUrl,`-R ${argsObj.tunnel.remotePort}:localhost:${argsObj.port}`,'-C'], {logName:'tunnel'})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Main script
|
|
70
|
+
function main () {
|
|
71
|
+
|
|
72
|
+
var argsObj = getCliArgs();
|
|
73
|
+
|
|
74
|
+
startTiroServer(argsObj, (configServerObj) => {
|
|
75
|
+
|
|
76
|
+
const c = configServerObj
|
|
77
|
+
const protocol = c.https ? 'https' : 'http'
|
|
78
|
+
const port = c.port
|
|
79
|
+
|
|
80
|
+
// open in browser
|
|
81
|
+
openInBrowser(`${protocol}://localhost:${port}`);
|
|
82
|
+
|
|
83
|
+
// start tunnel with autossh if asked
|
|
84
|
+
startSshTunnel(argsObj);
|
|
85
|
+
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// start everything
|
|
90
|
+
main();
|
|
91
|
+
|