Hi All:
With no experience on Node.js, I follow the official guide to start my TiddlyWiki Node.js instance.
I am doing that for one month since 5.0.16-beta.
While, working with more than one Node.js consoles sometimes makes me puzzle.
So I create an AutoHotKey script to help that (sorry, only for Windows).
Now I can have a central control as the screenshot below, to :The detection is done by adding special title to Node.js console with Windows command line
- have a ListView with summarized information
- port
- editions
- path
- console up-time
- choose to open different browser
- auto popup "central control" for new consoles
- open Node.js console from "central control"
- copy path / open in Explorer
(the first parameter of -- start "xxx" )start "%tw-path% * 127.0.0.1:%tw-port% * %tw-msg%" cmd /C node tiddlywiki.js ^
%tw-path% ^
--verbose ^
--server %tw-port% $:/core/save/all text/plain text/html %1 %2^
|| exit 1
Now, I am wondering if some of you will be interested in this AutoHotKey script.
Or, could this be implemented by Node.js to benefit more community members.
So far, I have collected some possible resource as below. But still have no idea if I have the ability to do this in Node.js.
https://github.com/oOthkOo/supervizer -- A NodeJS daemon process manager to spawn/start/stop node app
https://github.com/joyent/node/wiki/modules -- keyword "restarting"
https://www.npmjs.org/search?q=monitor%20console
https://www.npmjs.org/search?q=restart%20console
sorry for the broken image, please see below instead
https://www.dropbox.com/s/xjhf88wmgpah5tc/2014-10-04_115002.pngHi All:
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
Hi EucalyGood stuff, your console looks useful, and I'd encourage you to share your script so that others can try it out,Best wishesJeremy
{"pid":6112,"argv":["C:\\Program Files\\nodejs\\node.exe","D:\\Dropbox\\0U\\Data2014\\TiddlyWiki\\node-tw5100\\tiddlywiki.js","editions\\develop","--verbose","--server","10001","$:/core/save/all","text/plain","text/html","EucalyJ"],"initTime":"2014-10-05T10:37:40.739Z"}
var $tw = require("./boot/boot.js").TiddlyWiki();
// Pass the command line arguments to the boot kernel
$tw.boot.argv = Array.prototype.slice.call(process.argv,2);
// Save process info for central control
require("./hook.js").init();
// Boot the TW5 app
$tw.boot.boot();
(function(){
exports.init = function() {
var spy = {},
userHome = process.env.USERPROFILE || process.env.HOME || process.env.HOMEPATH,
fs = require("fs"),
path = require("path"),
fp, fn;
fp = path.join(userHome, "tiddlywiki", "hook");
mkdirSync_p(fp);
fn = path.join(fp, "pid" + process.pid);
spy.pid = process.pid;
spy.argv = process.argv;
spy.initTime = new Date();
fs.writeFileSync(fn, JSON.stringify(spy));
// source: https://github.com/bpedro/node-fs/blob/master/lib/fs.js
function mkdirSync_p(path, mode, position) {
var fs = require('fs');
var osSep = process.platform === 'win32' ? '\\' : '/';
var parts = require('path').normalize(path).split(osSep);
mode = mode || process.umask();
position = position || 0;
if (position >= parts.length) {
return true;
}
var directory = parts.slice(0, position + 1).join(osSep) || osSep;
try {
fs.statSync(directory);
mkdirSync_p(path, mode, position + 1);
} catch (e) {
try {
fs.mkdirSync(directory, mode);
mkdirSync_p(path, mode, position + 1);
} catch (e) {
if (e.code != 'EEXIST') {
throw e;
}
mkdirSync_p(path, mode, position + 1);
}
}
}
};
})();
In short, tiddlywiki.js will save a file in some folder for "central control".
for example: save C:\Users\username\tiddlywiki\hook\pidxxxx
other instances will have different pid in separate file.
function mkdirSync_p(path, mode, position) {
$tw.utils.createDirectory)exports.platforms = ["node"];
Would it be possible to save the central control file from a startup module? That would make it possible for your extension to reside in a plugin.
function mkdirSync_p(path, mode, position) {
If you were able to run as a startup module then you could use the core function `$tw.utils.createDirectory` instead.Best wishesJeremy
/*\
title: $:/plugins/eucaly/cchook/startup/afterCmd.js
type: application/javascript
module-type: startup
save central control hook after "command" module
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Export name and synchronous status
exports.name = "afterCmd";
exports.platforms = ["node"];
exports.before = [];
exports.after = ["command"];
exports.synchronous = false;
exports.startup = function(callback) {
var spy = {},
userHome = process.env.USERPROFILE || process.env.HOME || process.env.HOMEPATH,
fs = require("fs"),
path = require("path"),
fp, fn;
fp = path.join(userHome, "tiddlywiki", "hook");
$tw.utils.createDirectory(fp);
fn = path.join(fp, "pid" + process.pid + "OK");
spy.pid = process.pid;
spy.argv = process.argv;
spy.initTime = new Date();
fs.writeFileSync(fn, JSON.stringify(spy));
callback();
};
})();
While, afterCmd (code as below) is not called. Is this by design?
In addition, if assigned below, then the startup module is only for node.js ?exports.platforms = ["node"];