tiro-notes 0.27.13 → 0.27.16

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 +43 -42
  2. package/package.json +3 -2
package/cli.js CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env node
2
+ //const tHelpers = require('../helpers/helpers.platforms.js'); // for dev purposes
3
+ const tHelpers = require('./helpers-build/helpers.platforms.js');
2
4
 
3
5
  // open frontend on default browser
4
6
  const openInBrowser = (url) => {
@@ -6,27 +8,6 @@ const openInBrowser = (url) => {
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
- console.log( str );
23
- });
24
- child.stderr.on( 'data', data => {
25
- var str = `[${p.logName} ${cmd} ERROR!] : ${data}`;
26
- console.log( str );
27
- });
28
- return child;
29
- }
30
11
 
31
12
  function getCliArgs () {
32
13
  var args = process.argv;
@@ -55,36 +36,56 @@ function getCliArgs () {
55
36
  return argsObj;
56
37
  }
57
38
 
58
- // Main script
59
- function startTiroServerAsCli () {
60
- var argsObj = getCliArgs();
39
+ function startTiroServer (argsObj, cb) {
61
40
  console.log(`Starting Tiro-Notes from CLI with following arguments : ${JSON.stringify(argsObj)}`);
62
41
 
63
- // start tiro server
64
- execCmd('node', [`${__dirname}/server/server.js`], {
42
+ // start tiro server, detect success message and get server params
43
+ tHelpers.execCmd('node', [`${__dirname}/server/server.js`], {
65
44
  env: { TIRO_PORT: argsObj.port },
45
+ onLog: str => {
46
+ tHelpers.checkAndGetTiroConfig({platform: 'cli'}, cb)
47
+ }
66
48
  })
49
+ }
67
50
 
68
- // open in browser
69
- openInBrowser(`http://localhost:${argsObj.port}`);
51
+ const startSshTunnel = (argsObj) => {
52
+ if (argsObj.tunnel.enabled) {
53
+ // kill previous autossh processes
54
+ tHelpers.execCmd('killall', [`autossh`], {logName:'tunnel'})
70
55
 
71
- // start tunnel with autossh if asked
72
- if (argsObj.tunnel.enabled) {
73
- // kill previous autossh processes
74
- execCmd('killall', [`autossh`], {logName:'tunnel'})
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
+ }
75
62
 
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
- }
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
+ }
82
68
 
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
- }
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
+ })
86
87
  }
87
88
 
88
89
  // start everything
89
- startTiroServerAsCli();
90
+ main();
90
91
 
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "tiro-notes",
3
- "version": "0.27.13",
3
+ "version": "0.27.16",
4
4
  "description": "Tiro Notes for CLI",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "clean-previous-build": "rm -r node-build",
8
+ "export-helpers": "rm -r helpers-build; cp -r ../helpers helpers-build",
8
9
  "export-cli-module": "cd ../..; cp -r build platforms/npm-cli-module/node-build; cd ./platforms/npm-cli-module; cp cli.js node-build/; cp package.json node-build/; ",
9
- "build-then-publish": "cd ../..; npm run build; cd ./platforms/npm-cli-module; npm run clean-previous-build; npm run export-cli-module; echo WARNING REQUIRES NPM LOGIN BEFORE PUBLISHING!; cd node-build; npm publish"
10
+ "build-then-publish": "cd ../..; npm run build; cd ./platforms/npm-cli-module; npm run clean-previous-build; npm export-helpers; npm run export-cli-module; echo WARNING REQUIRES NPM LOGIN BEFORE PUBLISHING!; cd node-build; npm publish"
10
11
  },
11
12
  "bin": "cli.js",
12
13
  "repository": {