tiro-notes 0.27.13 → 0.27.14

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.
Files changed (2) hide show
  1. package/cli.js +55 -20
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -19,6 +19,7 @@ function execCmd (cmd, params, p) {
19
19
 
20
20
  child.stdout.on( 'data', data => {
21
21
  var str = `[${p.logName} ${cmd}] : ${data}`;
22
+ if (p && p.onLog) p.onLog(str)
22
23
  console.log( str );
23
24
  });
24
25
  child.stderr.on( 'data', data => {
@@ -55,36 +56,70 @@ function getCliArgs () {
55
56
  return argsObj;
56
57
  }
57
58
 
58
- // Main script
59
- function startTiroServerAsCli () {
60
- var argsObj = getCliArgs();
59
+ function startTiroServer (argsObj, cb) {
61
60
  console.log(`Starting Tiro-Notes from CLI with following arguments : ${JSON.stringify(argsObj)}`);
62
61
 
63
- // start tiro server
62
+ // start tiro server, detect success message and get server params
63
+ let hasStarted = false
64
64
  execCmd('node', [`${__dirname}/server/server.js`], {
65
65
  env: { TIRO_PORT: argsObj.port },
66
+ onLog: str => {
67
+ if ( !hasStarted) {
68
+ const successMessage = 'SERVER_LOAD_SUCCESS';
69
+ if (str.includes(successMessage)) {
70
+ hasStarted = true;
71
+ try {
72
+ let objStr = str.match(/\{.*\}/gm);
73
+ let configServerObj = JSON.parse(objStr)
74
+ console.log(`server config loaded successfully: ${JSON.stringify(configServerObj)}`);
75
+ if (cb) cb(configServerObj);
76
+ } catch(e){
77
+ console.log(`ERROR! could not get the server config ${JSON.stringify(e)}`)
78
+ }
79
+ }
80
+ }
81
+ }
66
82
  })
83
+ }
67
84
 
68
- // open in browser
69
- openInBrowser(`http://localhost:${argsObj.port}`);
85
+ const startSshTunnel = (argsObj) => {
86
+ if (argsObj.tunnel.enabled) {
87
+ // kill previous autossh processes
88
+ execCmd('killall', [`autossh`], {logName:'tunnel'})
70
89
 
71
- // start tunnel with autossh if asked
72
- if (argsObj.tunnel.enabled) {
73
- // kill previous autossh processes
74
- execCmd('killall', [`autossh`], {logName:'tunnel'})
90
+ // check if autossh is working
91
+ try {
92
+ execCmd('autossh', [`--help`], {logName:'tunnel'})
93
+ } catch (e) {
94
+ throw Error('autossh not installed on the system, please install it.')
95
+ }
75
96
 
76
- // check if autossh is working
77
- try {
78
- execCmd('autossh', [`--help`], {logName:'tunnel'})
79
- } catch (e) {
80
- throw Error('autossh not installed on the system, please install it.')
81
- }
97
+ // check if autossh enabled
98
+ execCmd('autossh', ['-M','20000','-f','-N',argsObj.tunnel.remoteUrl,`-R ${argsObj.tunnel.remotePort}:localhost:${argsObj.port}`,'-C'], {logName:'tunnel'})
99
+ }
100
+
101
+ }
102
+
103
+ // Main script
104
+ function main () {
105
+
106
+ var argsObj = getCliArgs();
107
+
108
+ startTiroServer(argsObj, (configServerObj) => {
82
109
 
83
- // check if autossh enabled
84
- execCmd('autossh', ['-M','20000','-f','-N',argsObj.tunnel.remoteUrl,`-R ${argsObj.tunnel.remotePort}:localhost:${argsObj.port}`,'-C'], {logName:'tunnel'})
85
- }
110
+ const c = configServerObj
111
+ const protocol = c.https ? 'https' : 'http'
112
+ const port = c.port
113
+
114
+ // open in browser
115
+ openInBrowser(`${protocol}://localhost:${port}`);
116
+
117
+ // start tunnel with autossh if asked
118
+ startSshTunnel(argsObj);
119
+
120
+ })
86
121
  }
87
122
 
88
123
  // start everything
89
- startTiroServerAsCli();
124
+ main();
90
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiro-notes",
3
- "version": "0.27.13",
3
+ "version": "0.27.14",
4
4
  "description": "Tiro Notes for CLI",
5
5
  "main": "index.js",
6
6
  "scripts": {