tiro-notes 0.30.4211 → 0.30.4212

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
@@ -3,6 +3,7 @@
3
3
  // const isDev = false
4
4
  const isDev = process.env.ISDEV
5
5
  const tHelpers = isDev ? require('../shared.helpers.js') : require(`./shared.helpers.build.js`);
6
+ const pathServerJs = isDev ? `${__dirname}/node-build/server/tiro-server.js` : `${__dirname}/server/tiro-server.js`
6
7
 
7
8
 
8
9
  // CLI HELP MANUAL
@@ -22,7 +23,14 @@ ARGS:
22
23
 
23
24
  --https/-s : enable https ssl with self signed certificate (boolean, false by default)
24
25
  --port/-p : port to use (number, 3023 by default)
25
- --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)
26
+ --no-open/-no : do not open Tiro in browser when starting
27
+
28
+ --tunnel/-t : [require autossh] 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)
29
+
30
+ --backup/-b : [require tar] will incrementally backup changes in archives.
31
+ --backup-folder : modify backup folder destination. (default: "your/path/to/tiro/data_folder"+_backup
32
+ --backup-post-script : modify script to be executed after a backup finishes. Should be a ".txt" file with your OS commands. (default: "your/path/to/tiro/data_folder"+_backup/post_backup_script.txt
33
+
26
34
  --help/-h : help
27
35
 
28
36
  EXAMPLES:
@@ -48,6 +56,12 @@ function getCliArgs () {
48
56
  port: 3023,
49
57
  https: false,
50
58
  help: false,
59
+ open: true,
60
+ backup: {
61
+ enabled: false,
62
+ location: "default",
63
+ scriptLocation: "default"
64
+ },
51
65
  tunnel: {
52
66
  enabled: false,
53
67
  },
@@ -60,6 +74,12 @@ function getCliArgs () {
60
74
  if (argName === 'p' || argName === 'port') argsObj.port = parseInt(argVal);
61
75
  if (argName === 's' || argName === 'https') argsObj.https = true
62
76
  if (argName === 'h' || argName === 'help') argsObj.help = true
77
+ if (argName === 'no-open' || argName === 'no') argsObj.open = false
78
+
79
+ if (argName === 'b' || argName === 'backup') argsObj.backup.enabled = true
80
+ if (argName === 'backup-location') argsObj.backup.location = argVal
81
+ if (argName === 'backup-post-script') argsObj.backup.scriptLocation = argVal
82
+
63
83
  if (argName === 't' || argName === 'tunnel') {
64
84
  const argsArr = argVal.split(':')
65
85
  if (argsArr.length > 1) {
@@ -79,19 +99,83 @@ function startTiroServer (argsObj, cb) {
79
99
  tHelpers.killPreviousInstances(() => {
80
100
 
81
101
  // start tiro server, detect success message and get server params
82
- tHelpers.execCmd('node', [`${__dirname}/server/tiro-server.js`], {
102
+ tHelpers.execCmd('node', [pathServerJs], {
83
103
  env: {
84
104
  TIRO_PORT: argsObj.port,
85
105
  TIRO_HTTPS: argsObj.https
86
106
  },
87
107
  logName: 'tiroServer',
88
108
  onLog: str => {
109
+ // we get params like dataFolder from server.js directly
89
110
  tHelpers.checkAndGetTiroConfig(str, {platform: 'cli', cb})
90
111
  }
91
112
  })
92
113
  });
93
114
  }
94
115
 
116
+ const startBackupScript = async (argsObj, dataFolder) => {
117
+ if (argsObj.backup.enabled) return;
118
+ if (!dataFolder) return console.warn ("[BACKUP] no dataFolder detected!");
119
+
120
+ // get BACKUP_FOLDER path
121
+ const defaultBackupFolder = dataFolder + "_backup/"
122
+ const backupFolder = argsObj.backup.location !== "default" ? argsObj.backup.location : defaultBackupFolder
123
+ // if does not exists, create it
124
+ if (!tHelpers.fileExists(backupFolder)) await tHelpers.createDir(backupFolder)
125
+
126
+
127
+ // get POST_BACKUP_SCRIPT
128
+ const defaultPostBackupScript = backupFolder + "post_backup_script.txt"
129
+ const postBackupScriptFile = argsObj.backup.scriptLocation !== "default" ? argsObj.backup.scriptLocation : defaultPostBackupScript
130
+ // if does not exists, create it, empty
131
+ if (!tHelpers.fileExists(postBackupScriptFile)) await tHelpers.saveFile(postBackupScriptFile, "")
132
+ let postBackupScript = await tHelpers.openFile(postBackupScriptFile)
133
+ if (postBackupScript) postBackupScript += ";"
134
+
135
+
136
+ // get LAST_BACKUP_TIMESTAMP
137
+ const timestampFile = backupFolder + "last_backup_timestamp.txt"
138
+ const now = () => new Date().getTime()
139
+ // if does not exists, create it, then give a timestamp of 0
140
+ if (!tHelpers.fileExists(timestampFile)) await tHelpers.saveFile(timestampFile, "0")
141
+ let lastBackupTimestampRaw = await tHelpers.openFile(timestampFile);
142
+ let lastBackupTimestamp = parseInt(lastBackupTimestampRaw)
143
+ let replaceTimestampCli = () => `echo ${now()} > '${timestampFile}'`
144
+
145
+ // START INTERVAL
146
+ const timeInterval = 1000 * 60 * 60 // one hour
147
+ const backupInterval = 1000 * 60 * 60 * 24 // one day
148
+
149
+ const tarExec = process.platform === "darwin" ? "gtar" : "tar"
150
+
151
+ let backupCli = `mkdir '${backupFolder}'; mkdir '${backupFolder}/backups'; cd '${backupFolder}'; ${tarExec} --xz --verbose --create --file="backups/tiro.$(ls backups/ | wc -l | sed 's/^ *//;s/ *$//').tar.xz" '${dataFolder}' --listed-incremental='${backupFolder}metadata.snar'; ${replaceTimestampCli()}; ${postBackupScript}`
152
+
153
+
154
+
155
+ const debugBackupNow = isDev ? false : false
156
+ const processBackupEveryDay = () => {
157
+ // if > 1 day
158
+ console.log({backupFolder, postBackupScriptFile, postBackupScript, lastBackupTimestamp, timeInterval, backupCli});
159
+ const diff = backupInterval + lastBackupTimestamp - new Date().getTime()
160
+ const diffMin = Math.round(diff / (1000 * 60))
161
+ if (diff < 0 || debugBackupNow) {
162
+ console.log(`[BACKUP] time has come, BACKUP!`);
163
+ // append to backup CLI current timestamp to last_backup_timestamp
164
+ // execute cli
165
+ tHelpers.execCmdInFile(backupCli, backupFolder+"cli.sh")
166
+ } else {
167
+ console.log(`[BACKUP] time has no come... still waiting for ${diffMin} mins`);
168
+ }
169
+ }
170
+
171
+ // every hour
172
+ processBackupEveryDay();
173
+ let int = setInterval(() => {
174
+ processBackupEveryDay()
175
+ }, timeInterval)
176
+
177
+ }
178
+
95
179
  const startSshTunnel = (argsObj) => {
96
180
  if (argsObj.tunnel.enabled) {
97
181
  // kill previous autossh processes
@@ -135,12 +219,17 @@ function main () {
135
219
  const c = configServerObj
136
220
  const protocol = c.https ? 'https' : 'http'
137
221
  const port = c.port
222
+ const dataFolder = c.dataFolder
138
223
 
139
224
  // open in browser
140
- openInBrowser(`${protocol}://localhost:${port}`);
225
+ if (c.open) openInBrowser(`${protocol}://localhost:${port}`);
141
226
 
142
227
  // start tunnel with autossh if asked
143
228
  startSshTunnel(argsObj);
229
+
230
+ // start backup script
231
+ startBackupScript(argsObj, dataFolder);
232
+ // console.log(333333, dataFolder);
144
233
 
145
234
  })
146
235
  }
@@ -148,11 +237,14 @@ function main () {
148
237
 
149
238
  const test = () => {
150
239
  var argsObj = getCliArgs();
151
- startSshTunnel(argsObj);
240
+ // startSshTunnel(argsObj);
241
+ console.log(argsObj);
242
+ // startBackupScript(argsObj, "/Users/gregoirethiebault/Desktop/your markdown notes")
243
+ startBackupScript(argsObj, "/Users/gregoirethiebault/Desktop/nodal_ex")
152
244
  }
153
245
 
154
246
 
155
247
  // start everything
156
- // isDev ? test() : main();
157
- isDev ? main() : main();
248
+ isDev ? test() : main();
249
+ // isDev ? main() : main();
158
250
 
@@ -2,10 +2,10 @@
2
2
  "files": {
3
3
  "static/js/0.c490099b.chunk.js": "/static/js/0.c490099b.chunk.js",
4
4
  "static/js/1.d5c20c38.chunk.js": "/static/js/1.d5c20c38.chunk.js",
5
- "main.js": "/static/js/main.4186260d.chunk.js",
5
+ "main.js": "/static/js/main.06401a25.chunk.js",
6
6
  "runtime-main.js": "/static/js/runtime-main.8aa8b9eb.js",
7
7
  "static/css/4.992ae4ff.chunk.css": "/static/css/4.992ae4ff.chunk.css",
8
- "static/js/4.950dfeb6.chunk.js": "/static/js/4.950dfeb6.chunk.js",
8
+ "static/js/4.83d4d41c.chunk.js": "/static/js/4.83d4d41c.chunk.js",
9
9
  "static/js/5.7154c544.chunk.js": "/static/js/5.7154c544.chunk.js",
10
10
  "static/js/6.3b3ed6b3.chunk.js": "/static/js/6.3b3ed6b3.chunk.js",
11
11
  "static/js/7.05cc9dbd.chunk.js": "/static/js/7.05cc9dbd.chunk.js",
@@ -80,7 +80,7 @@
80
80
  "static/js/76.6e339e9f.chunk.js": "/static/js/76.6e339e9f.chunk.js",
81
81
  "static/js/77.46a6b6a0.chunk.js": "/static/js/77.46a6b6a0.chunk.js",
82
82
  "index.html": "/index.html",
83
- "static/js/4.950dfeb6.chunk.js.LICENSE.txt": "/static/js/4.950dfeb6.chunk.js.LICENSE.txt",
83
+ "static/js/4.83d4d41c.chunk.js.LICENSE.txt": "/static/js/4.83d4d41c.chunk.js.LICENSE.txt",
84
84
  "static/js/70.16aeae57.chunk.js.LICENSE.txt": "/static/js/70.16aeae57.chunk.js.LICENSE.txt",
85
85
  "static/media/book-solid.87f5b737.svg": "/static/media/book-solid.87f5b737.svg",
86
86
  "static/media/codicon.css": "/static/media/codicon.0e0f4555.ttf",
@@ -104,7 +104,7 @@
104
104
  "entrypoints": [
105
105
  "static/js/runtime-main.8aa8b9eb.js",
106
106
  "static/css/4.992ae4ff.chunk.css",
107
- "static/js/4.950dfeb6.chunk.js",
108
- "static/js/main.4186260d.chunk.js"
107
+ "static/js/4.83d4d41c.chunk.js",
108
+ "static/js/main.06401a25.chunk.js"
109
109
  ]
110
110
  }
package/client/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Tiro</title><link href="/static/css/4.992ae4ff.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function t(t){for(var n,o,f=t[0],u=t[1],i=t[2],l=0,b=[];l<f.length;l++)o=f[l],Object.prototype.hasOwnProperty.call(a,o)&&a[o]&&b.push(a[o][0]),a[o]=0;for(n in u)Object.prototype.hasOwnProperty.call(u,n)&&(e[n]=u[n]);for(d&&d(t);b.length;)b.shift()();return c.push.apply(c,i||[]),r()}function r(){for(var e,t=0;t<c.length;t++){for(var r=c[t],n=!0,f=1;f<r.length;f++){var u=r[f];0!==a[u]&&(n=!1)}n&&(c.splice(t--,1),e=o(o.s=r[0]))}return e}var n={},a={3:0},c=[];function o(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,o),r.l=!0,r.exports}o.e=function(e){var t=[],r=a[e];if(0!==r)if(r)t.push(r[2]);else{var n=new Promise((function(t,n){r=a[e]=[t,n]}));t.push(r[2]=n);var c,f=document.createElement("script");f.charset="utf-8",f.timeout=120,o.nc&&f.setAttribute("nonce",o.nc),f.src=function(e){return o.p+"static/js/"+({}[e]||e)+"."+{0:"c490099b",1:"d5c20c38",5:"7154c544",6:"3b3ed6b3",7:"05cc9dbd",8:"02f6f6d2",9:"0cb915ad",10:"95b2edda",11:"04e83a60",12:"23f17cae",13:"e2ce43ca",14:"d1f78332",15:"19558fb3",16:"9356c734",17:"249c76f1",18:"6f0a373c",19:"545642bc",20:"f8215841",21:"e5f7c151",22:"ed91e085",23:"7dadd977",24:"966c0e2e",25:"f5bf249a",26:"f1dbe9b2",27:"50ee22bc",28:"7a8292e6",29:"54345dda",30:"2ba035b4",31:"32245201",32:"5a19b5ee",33:"f99079cd",34:"a20b4464",35:"506e1750",36:"45194f2c",37:"6cacdf19",38:"26ac693b",39:"c4112562",40:"eeca90df",41:"7b68c511",42:"9c2c5e97",43:"5d7317a5",44:"fe9af4f2",45:"44342f11",46:"e98dbf2f",47:"7557c994",48:"6196bde4",49:"96931133",50:"4b6c4945",51:"a0453ca7",52:"02d806fa",53:"2eb3a4c2",54:"d45590e9",55:"7b65aff4",56:"aba293cf",57:"fe307fff",58:"9911af61",59:"3ece5218",60:"8022a138",61:"aa0a68a3",62:"5b759580",63:"3704ad94",64:"a56b476c",65:"5cb7a5a5",66:"c79fff81",67:"fbae1306",68:"7889a44c",69:"39edff23",70:"16aeae57",71:"a1d51cd4",72:"27125a85",73:"e79ee491",74:"17cd2084",75:"804c47a0",76:"6e339e9f",77:"46a6b6a0"}[e]+".chunk.js"}(e);var u=new Error;c=function(t){f.onerror=f.onload=null,clearTimeout(i);var r=a[e];if(0!==r){if(r){var n=t&&("load"===t.type?"missing":t.type),c=t&&t.target&&t.target.src;u.message="Loading chunk "+e+" failed.\n("+n+": "+c+")",u.name="ChunkLoadError",u.type=n,u.request=c,r[1](u)}a[e]=void 0}};var i=setTimeout((function(){c({type:"timeout",target:f})}),12e4);f.onerror=f.onload=c,document.head.appendChild(f)}return Promise.all(t)},o.m=e,o.c=n,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(r,n,function(t){return e[t]}.bind(null,n));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/",o.oe=function(e){throw console.error(e),e};var f=this["webpackJsonptiro-notes-client"]=this["webpackJsonptiro-notes-client"]||[],u=f.push.bind(f);f.push=t,f=f.slice();for(var i=0;i<f.length;i++)t(f[i]);var d=u;r()}([])</script><script src="/static/js/4.950dfeb6.chunk.js"></script><script src="/static/js/main.4186260d.chunk.js"></script></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Tiro</title><link href="/static/css/4.992ae4ff.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function t(t){for(var n,o,f=t[0],u=t[1],i=t[2],l=0,b=[];l<f.length;l++)o=f[l],Object.prototype.hasOwnProperty.call(a,o)&&a[o]&&b.push(a[o][0]),a[o]=0;for(n in u)Object.prototype.hasOwnProperty.call(u,n)&&(e[n]=u[n]);for(d&&d(t);b.length;)b.shift()();return c.push.apply(c,i||[]),r()}function r(){for(var e,t=0;t<c.length;t++){for(var r=c[t],n=!0,f=1;f<r.length;f++){var u=r[f];0!==a[u]&&(n=!1)}n&&(c.splice(t--,1),e=o(o.s=r[0]))}return e}var n={},a={3:0},c=[];function o(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,o),r.l=!0,r.exports}o.e=function(e){var t=[],r=a[e];if(0!==r)if(r)t.push(r[2]);else{var n=new Promise((function(t,n){r=a[e]=[t,n]}));t.push(r[2]=n);var c,f=document.createElement("script");f.charset="utf-8",f.timeout=120,o.nc&&f.setAttribute("nonce",o.nc),f.src=function(e){return o.p+"static/js/"+({}[e]||e)+"."+{0:"c490099b",1:"d5c20c38",5:"7154c544",6:"3b3ed6b3",7:"05cc9dbd",8:"02f6f6d2",9:"0cb915ad",10:"95b2edda",11:"04e83a60",12:"23f17cae",13:"e2ce43ca",14:"d1f78332",15:"19558fb3",16:"9356c734",17:"249c76f1",18:"6f0a373c",19:"545642bc",20:"f8215841",21:"e5f7c151",22:"ed91e085",23:"7dadd977",24:"966c0e2e",25:"f5bf249a",26:"f1dbe9b2",27:"50ee22bc",28:"7a8292e6",29:"54345dda",30:"2ba035b4",31:"32245201",32:"5a19b5ee",33:"f99079cd",34:"a20b4464",35:"506e1750",36:"45194f2c",37:"6cacdf19",38:"26ac693b",39:"c4112562",40:"eeca90df",41:"7b68c511",42:"9c2c5e97",43:"5d7317a5",44:"fe9af4f2",45:"44342f11",46:"e98dbf2f",47:"7557c994",48:"6196bde4",49:"96931133",50:"4b6c4945",51:"a0453ca7",52:"02d806fa",53:"2eb3a4c2",54:"d45590e9",55:"7b65aff4",56:"aba293cf",57:"fe307fff",58:"9911af61",59:"3ece5218",60:"8022a138",61:"aa0a68a3",62:"5b759580",63:"3704ad94",64:"a56b476c",65:"5cb7a5a5",66:"c79fff81",67:"fbae1306",68:"7889a44c",69:"39edff23",70:"16aeae57",71:"a1d51cd4",72:"27125a85",73:"e79ee491",74:"17cd2084",75:"804c47a0",76:"6e339e9f",77:"46a6b6a0"}[e]+".chunk.js"}(e);var u=new Error;c=function(t){f.onerror=f.onload=null,clearTimeout(i);var r=a[e];if(0!==r){if(r){var n=t&&("load"===t.type?"missing":t.type),c=t&&t.target&&t.target.src;u.message="Loading chunk "+e+" failed.\n("+n+": "+c+")",u.name="ChunkLoadError",u.type=n,u.request=c,r[1](u)}a[e]=void 0}};var i=setTimeout((function(){c({type:"timeout",target:f})}),12e4);f.onerror=f.onload=c,document.head.appendChild(f)}return Promise.all(t)},o.m=e,o.c=n,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(r,n,function(t){return e[t]}.bind(null,n));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/",o.oe=function(e){throw console.error(e),e};var f=this["webpackJsonptiro-notes-client"]=this["webpackJsonptiro-notes-client"]||[],u=f.push.bind(f);f.push=t,f=f.slice();for(var i=0;i<f.length;i++)t(f[i]);var d=u;r()}([])</script><script src="/static/js/4.83d4d41c.chunk.js"></script><script src="/static/js/main.06401a25.chunk.js"></script></body></html>