tiro-notes 0.27.27 → 0.27.31

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 CHANGED
@@ -1,6 +1,40 @@
1
1
  #!/usr/bin/env node
2
- //const tHelpers = require('../shared.helpers.js'); // for dev purposes
3
- const tHelpers = require(`./shared.helpers.build.js`);
2
+
3
+ // const isDev = false
4
+ const isDev = true
5
+
6
+ const tHelpers = isDev ? require('../shared.helpers.js') : require(`./shared.helpers.build.js`);
7
+
8
+
9
+ // CLI HELP MANUAL
10
+ const outputHelp = () => {
11
+ var p = require('./package.json');
12
+ const tiroHelpString = `
13
+ VERSION:
14
+ ===
15
+ ${p.name.toUpperCase()} v.${p.version}
16
+
17
+ DESCRIPTION:
18
+ ===
19
+ ${p.description}
20
+
21
+ ARGS:
22
+ ====
23
+
24
+ --https/-s : enable https ssl with self signed certificate (boolean, false by default)
25
+ --port/-p : port to use (number, 3023 by default)
26
+ --tunnel/-t : uses autossh to "publish" the app on the web, requires a server you can access with ssh and autossh installed on that device. (ex:npx tiro-notes@latest -t REMOTE_USER@REMOTE_URL:REMOTE_PORT)
27
+ --help/-h : help
28
+
29
+ EXAMPLES:
30
+ ====
31
+ - npx tiro-notes
32
+ - npx tiro-notes --tunnel ubuntu@myserver.com:3023 --port 3033 --https true
33
+ - npx tiro-notes -t ubuntu@myserver.com:3023 -p 3033 -s true
34
+ `;
35
+ console.log(tiroHelpString);
36
+
37
+ }
4
38
 
5
39
  // open frontend on default browser
6
40
  const openInBrowser = (url) => {
@@ -13,17 +47,20 @@ function getCliArgs () {
13
47
  var args = process.argv;
14
48
  var argsObj = {
15
49
  port: 3023,
50
+ https: false,
51
+ help: false,
16
52
  tunnel: {
17
53
  enabled: false,
18
54
  },
19
55
  }
20
56
  for (var i = 0; i < args.length; i++) {
21
57
  if (i % 2 !== 0) continue
22
- console.log(i);
23
58
  var argName = args[i];
24
59
  var argVal = args[i+1];
25
60
  argName = argName.replace('--', '').replace('-','')
26
61
  if (argName === 'p' || argName === 'port') argsObj.port = parseInt(argVal);
62
+ if (argName === 's' || argName === 'https') argsObj.https = true
63
+ if (argName === 'h' || argName === 'help') argsObj.help = true
27
64
  if (argName === 't' || argName === 'tunnel') {
28
65
  const argsArr = argVal.split(':')
29
66
  if (argsArr.length > 1) {
@@ -41,7 +78,10 @@ function startTiroServer (argsObj, cb) {
41
78
 
42
79
  // start tiro server, detect success message and get server params
43
80
  tHelpers.execCmd('node', [`${__dirname}/server/server.js`], {
44
- env: { TIRO_PORT: argsObj.port },
81
+ env: {
82
+ TIRO_PORT: argsObj.port,
83
+ TIRO_HTTPS: argsObj.https
84
+ },
45
85
  logName: 'tiroServer',
46
86
  onLog: str => {
47
87
  tHelpers.checkAndGetTiroConfig(str, {platform: 'cli', cb})
@@ -52,12 +92,15 @@ function startTiroServer (argsObj, cb) {
52
92
  const startSshTunnel = (argsObj) => {
53
93
  if (argsObj.tunnel.enabled) {
54
94
  // kill previous autossh processes
95
+ let cb2 = true
55
96
  let cb1 = true
56
97
  tHelpers.execCmd('killall', [`autossh`], {
57
98
  logName:'tunnel 1/3',
58
- onDone: () => {
99
+ onLog: () => {
100
+ if (!cb2) return
101
+ cb2 = false
59
102
  // check if autossh is working
60
- tHelpers.execCmd('autossh', [`--help`], {
103
+ tHelpers.execCmd('autossh', [`-V`], {
61
104
  logName:'tunnel 2/3',
62
105
  onLog: str => {
63
106
  if (!cb1) return
@@ -78,21 +121,35 @@ function main () {
78
121
 
79
122
  var argsObj = getCliArgs();
80
123
 
81
- startTiroServer(argsObj, (configServerObj) => {
124
+ if (argsObj.help) {
82
125
 
83
- const c = configServerObj
84
- const protocol = c.https ? 'https' : 'http'
85
- const port = c.port
126
+ outputHelp();
86
127
 
87
- // open in browser
88
- openInBrowser(`${protocol}://localhost:${port}`);
128
+ } else {
89
129
 
90
- // start tunnel with autossh if asked
91
- startSshTunnel(argsObj);
92
-
93
- })
130
+ startTiroServer(argsObj, (configServerObj) => {
131
+
132
+ const c = configServerObj
133
+ const protocol = c.https ? 'https' : 'http'
134
+ const port = c.port
135
+
136
+ // open in browser
137
+ openInBrowser(`${protocol}://localhost:${port}`);
138
+
139
+ // start tunnel with autossh if asked
140
+ startSshTunnel(argsObj);
141
+
142
+ })
143
+ }
94
144
  }
95
145
 
146
+ const test = () => {
147
+ var argsObj = getCliArgs();
148
+ startSshTunnel(argsObj);
149
+ }
150
+
151
+
96
152
  // start everything
97
- main();
153
+ // isDev ? test() : main();
154
+ isDev ? main() : main();
98
155
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tiro-notes",
3
- "version": "0.27.27",
4
- "description": "Tiro Notes for CLI",
3
+ "version": "0.27.31",
4
+ "description": "Tiro Notes CLI to start Tiro Notes from the command line!",
5
5
  "scripts": {
6
6
  "clean-previous-build": "rm -r node-build",
7
7
  "export-cli-module": "cp -r ../../build node-build; cp cli.js node-build/; cp package.json node-build/; ",