tiro-notes 0.27.16 → 0.27.20
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 +3 -3
- package/package.json +4 -5
- package/shared.helpers.build.js +75 -0
- package/#package.json# +0 -13
- package/cli.js~ +0 -51
package/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//const tHelpers = require('../helpers
|
|
3
|
-
const tHelpers = require(
|
|
2
|
+
//const tHelpers = require('../shared.helpers.js'); // for dev purposes
|
|
3
|
+
const tHelpers = require(`./shared.helpers.build.js`);
|
|
4
4
|
|
|
5
5
|
// open frontend on default browser
|
|
6
6
|
const openInBrowser = (url) => {
|
|
@@ -40,7 +40,7 @@ function startTiroServer (argsObj, cb) {
|
|
|
40
40
|
console.log(`Starting Tiro-Notes from CLI with following arguments : ${JSON.stringify(argsObj)}`);
|
|
41
41
|
|
|
42
42
|
// start tiro server, detect success message and get server params
|
|
43
|
-
tHelpers.execCmd('node', [`${__dirname}/server/server.js`], {
|
|
43
|
+
tHelpers.execCmd('node', [`${__dirname}/node-build/server/server.js`], {
|
|
44
44
|
env: { TIRO_PORT: argsObj.port },
|
|
45
45
|
onLog: str => {
|
|
46
46
|
tHelpers.checkAndGetTiroConfig({platform: 'cli'}, cb)
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiro-notes",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.20",
|
|
4
4
|
"description": "Tiro Notes for CLI",
|
|
5
|
-
"main": "index.js",
|
|
6
5
|
"scripts": {
|
|
7
6
|
"clean-previous-build": "rm -r node-build",
|
|
8
|
-
"export-
|
|
9
|
-
"export-
|
|
10
|
-
"build-then-publish": "cd ../..; npm run build; cd ./platforms/npm-cli-module; npm run clean-previous-build; npm export-
|
|
7
|
+
"export-cli-module": "cp -r ../../build node-build; cp cli.js node-build/; cp package.json node-build/; ",
|
|
8
|
+
"export-helpers": "cp ../shared.helpers.js ./node-build/shared.helpers.build.js",
|
|
9
|
+
"build-then-publish": "cd ../..; npm run build; cd ./platforms/npm-cli-module; npm run clean-previous-build; npm run export-cli-module; npm run export-helpers; echo WARNING REQUIRES NPM LOGIN BEFORE PUBLISHING!; cd node-build; npm publish"
|
|
11
10
|
},
|
|
12
11
|
"bin": "cli.js",
|
|
13
12
|
"repository": {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Logging
|
|
2
|
+
const homedir = require('os').homedir();
|
|
3
|
+
const electronLogFile = `${homedir}/.tiro-electron-log.txt`
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const cleanLog = () => {
|
|
6
|
+
fs.writeFile(electronLogFile, '', err => {})
|
|
7
|
+
}
|
|
8
|
+
const writeLog = (p) => (content) => {
|
|
9
|
+
content = `[ELECTRON] ${new Date().getTime()} => ${content} \n\r`
|
|
10
|
+
console.log(content);
|
|
11
|
+
fs.appendFile(electronLogFile, content, err => {})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const whichLog = (p) => p.platform === 'electron' ? writeLog : console.log
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
let hasStarted = false
|
|
18
|
+
const checkAndGetTiroConfig = (p, cb) => {
|
|
19
|
+
if (!p) p = {}
|
|
20
|
+
if (!p.platform) p.platform = false
|
|
21
|
+
const log = whichLog(p);
|
|
22
|
+
|
|
23
|
+
if ( !hasStarted) {
|
|
24
|
+
const successMessage = 'SERVER_LOAD_SUCCESS';
|
|
25
|
+
if (str.includes(successMessage)) {
|
|
26
|
+
hasStarted = true;
|
|
27
|
+
log(`-- ${str} --`);
|
|
28
|
+
try {
|
|
29
|
+
let objStr = str.match(/\{.*\}/gm);
|
|
30
|
+
let configServerObj = JSON.parse(objStr)
|
|
31
|
+
log(`server config loaded successfully: ${JSON.stringify(configServerObj)}`);
|
|
32
|
+
if (cb) cb(configServerObj);
|
|
33
|
+
} catch(e){
|
|
34
|
+
log(`ERROR! could not get the server config ${JSON.stringify(e)}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// more general exec func
|
|
42
|
+
const execCmd = (cmd, params, p) => {
|
|
43
|
+
if (!p) p = {}
|
|
44
|
+
if (!p.env) p.env = {}
|
|
45
|
+
if (!p.platform) p.platform = false
|
|
46
|
+
if (!p.logName) p.logName = ''
|
|
47
|
+
const log = whichLog(p);
|
|
48
|
+
|
|
49
|
+
log(`ExecCMD ${JSON.stringify({cmd, params, p})}`);
|
|
50
|
+
|
|
51
|
+
let child
|
|
52
|
+
let spawn = require( 'child_process' ).spawn;
|
|
53
|
+
child = spawn( cmd, params, {env: { ...process.env, ...p.env }});
|
|
54
|
+
|
|
55
|
+
// try {
|
|
56
|
+
child.stdout.on( 'data', data => {
|
|
57
|
+
const str = `[${p.logName} ${cmd}] : ${data}`;
|
|
58
|
+
console.log( str );
|
|
59
|
+
if (p && p.onLog) p.onLog(str)
|
|
60
|
+
});
|
|
61
|
+
child.stderr.on( 'data', data => {
|
|
62
|
+
const str = `[${p.logName} ${cmd} ERROR!] : ${data}`;
|
|
63
|
+
log( str );
|
|
64
|
+
});
|
|
65
|
+
log(`ExecCMD SUCCESS ${JSON.stringify({cmd, params, p})}`);
|
|
66
|
+
return child;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
const e = {
|
|
71
|
+
checkAndGetTiroConfig,
|
|
72
|
+
execCmd
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = e;
|
package/#package.json#
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tiro-notes",
|
|
3
|
-
"version": "0.27.",
|
|
4
|
-
"description": "Tiro Notes",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start": "node server/server.js",
|
|
8
|
-
"publish": "echo WARNING REQUIRES NPM LOGIN BEFORE PUBLISHING!; npm publish"
|
|
9
|
-
},
|
|
10
|
-
"bin": "cli.js",
|
|
11
|
-
"author": "thiebault.gregoire@gmail.com",
|
|
12
|
-
"license": "ISC"
|
|
13
|
-
}
|
package/cli.js~
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// EXEC Function
|
|
4
|
-
const execCmd = (cmd, params, p) => {
|
|
5
|
-
console.log(`ExecCMD ${JSON.stringify({cmd, params, p})}`);
|
|
6
|
-
if (!p) p = {}
|
|
7
|
-
if (!p.env) p.env = {}
|
|
8
|
-
if (!p.onLog) p.onLog = () => {}
|
|
9
|
-
|
|
10
|
-
let spawn = require( 'child_process' ).spawn;
|
|
11
|
-
let child = spawn( cmd, params, {env: { ...process.env, ...p.env }});
|
|
12
|
-
|
|
13
|
-
child.stdout.on( 'data', data => {
|
|
14
|
-
const str = `[${cmd}] : ${data}`;
|
|
15
|
-
console.log( str );
|
|
16
|
-
});
|
|
17
|
-
child.stderr.on( 'data', data => {
|
|
18
|
-
const str = `[${cmd} ERROR!] : ${data}`;
|
|
19
|
-
console.log( str );
|
|
20
|
-
});
|
|
21
|
-
return child;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const getCliArgs = () => {
|
|
25
|
-
const args = process.argv;
|
|
26
|
-
let argsObj = {
|
|
27
|
-
port: 3023
|
|
28
|
-
}
|
|
29
|
-
for (let i = 0; i < args.length; i++) {
|
|
30
|
-
if (i % 2 !== 0) continue
|
|
31
|
-
console.log(i);
|
|
32
|
-
let argName = args[i];
|
|
33
|
-
let argVal = args[i+1];
|
|
34
|
-
argName = argName.replace('--', '').replace('-','')
|
|
35
|
-
if (argName === 'p' || argName === 'port') argsObj.port = parseInt(argVal);
|
|
36
|
-
}
|
|
37
|
-
return argsObj;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Main script
|
|
41
|
-
function startTiroServerAsCli () {
|
|
42
|
-
const argsObj = getCliArgs();
|
|
43
|
-
console.log(`Starting Tiro-Notes from CLI with following arguments : ${JSON.stringify(argsObj)}`);
|
|
44
|
-
execCmd('node', ['./server/server.js'], {
|
|
45
|
-
env: { TIRO_PORT: argsObj.port },
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
module.exports = startTiroServerAsCli;
|
|
49
|
-
|
|
50
|
-
// for testing purposes
|
|
51
|
-
//startTiroServerAsCli();
|