tiro-notes 0.27.14 → 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.
Files changed (2) hide show
  1. package/cli.js +7 -41
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -1,33 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const tHelpers = require('../helpers/helpers.platforms.js');
4
+
3
5
  // open frontend on default browser
4
6
  const openInBrowser = (url) => {
5
7
  var start = (process.platform == 'darwin'? 'open': process.platform == 'win32'? 'start': 'xdg-open');
6
8
  require('child_process').exec(start + ' ' + url);
7
9
  }
8
10
 
9
- // exec cmd
10
- function execCmd (cmd, params, p) {
11
- console.log(`ExecCMD ${JSON.stringify({cmd, params, p})}`);
12
- if (!p) p = {}
13
- if (!p.env) p.env = {}
14
- if (!p.onLog) p.onLog = () => {}
15
- if (!p.logName) p.logName = ''
16
-
17
- var spawn = require( 'child_process' ).spawn;
18
- var child = spawn( cmd, params, {env: { ...process.env, ...p.env }});
19
-
20
- child.stdout.on( 'data', data => {
21
- var str = `[${p.logName} ${cmd}] : ${data}`;
22
- if (p && p.onLog) p.onLog(str)
23
- console.log( str );
24
- });
25
- child.stderr.on( 'data', data => {
26
- var str = `[${p.logName} ${cmd} ERROR!] : ${data}`;
27
- console.log( str );
28
- });
29
- return child;
30
- }
31
11
 
32
12
  function getCliArgs () {
33
13
  var args = process.argv;
@@ -60,24 +40,10 @@ function startTiroServer (argsObj, cb) {
60
40
  console.log(`Starting Tiro-Notes from CLI with following arguments : ${JSON.stringify(argsObj)}`);
61
41
 
62
42
  // start tiro server, detect success message and get server params
63
- let hasStarted = false
64
- execCmd('node', [`${__dirname}/server/server.js`], {
43
+ tHelpers.execCmd('node', [`${__dirname}/server/server.js`], {
65
44
  env: { TIRO_PORT: argsObj.port },
66
45
  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
- }
46
+ tHelpers.checkAndGetTiroConfig({platform: 'cli'}, cb)
81
47
  }
82
48
  })
83
49
  }
@@ -85,17 +51,17 @@ function startTiroServer (argsObj, cb) {
85
51
  const startSshTunnel = (argsObj) => {
86
52
  if (argsObj.tunnel.enabled) {
87
53
  // kill previous autossh processes
88
- execCmd('killall', [`autossh`], {logName:'tunnel'})
54
+ tHelpers.execCmd('killall', [`autossh`], {logName:'tunnel'})
89
55
 
90
56
  // check if autossh is working
91
57
  try {
92
- execCmd('autossh', [`--help`], {logName:'tunnel'})
58
+ tHelpers.execCmd('autossh', [`--help`], {logName:'tunnel'})
93
59
  } catch (e) {
94
60
  throw Error('autossh not installed on the system, please install it.')
95
61
  }
96
62
 
97
63
  // check if autossh enabled
98
- execCmd('autossh', ['-M','20000','-f','-N',argsObj.tunnel.remoteUrl,`-R ${argsObj.tunnel.remotePort}:localhost:${argsObj.port}`,'-C'], {logName:'tunnel'})
64
+ tHelpers.execCmd('autossh', ['-M','20000','-f','-N',argsObj.tunnel.remoteUrl,`-R ${argsObj.tunnel.remotePort}:localhost:${argsObj.port}`,'-C'], {logName:'tunnel'})
99
65
  }
100
66
 
101
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiro-notes",
3
- "version": "0.27.14",
3
+ "version": "0.27.15",
4
4
  "description": "Tiro Notes for CLI",
5
5
  "main": "index.js",
6
6
  "scripts": {