Comparing version 0.1.0 to 0.2.0
@@ -14,2 +14,9 @@ // Generated by LiveScript 1.4.0 | ||
var path, conf, e; | ||
function reload(ev){ | ||
if (ev !== 'change') { | ||
return; | ||
} | ||
log("Reload " + path); | ||
return me.load(); | ||
} | ||
me.reset(); | ||
@@ -37,9 +44,6 @@ path = Args.configPath; | ||
validate(); | ||
fsw = Fs.watch(path, function(ev, fname){ | ||
if (ev !== 'change') { | ||
return; | ||
} | ||
log("Reload " + path); | ||
return me.load(); | ||
}); | ||
fsw = Fs.watch(path, _.debounce(reload, 500, { | ||
leading: false, | ||
trailing: true | ||
})); | ||
return me; | ||
@@ -56,4 +60,4 @@ }, | ||
var ref$, badKeys; | ||
if (!((ref$ = cfg.basePath) != null && ref$.length)) { | ||
throw new Error('basePath not found'); | ||
if (!((ref$ = cfg.basePaths) != null && ref$.length)) { | ||
throw new Error('basePaths not found'); | ||
} | ||
@@ -63,3 +67,3 @@ if (!(_.isArray(cfg.names) && cfg.names.length)) { | ||
} | ||
badKeys = _.without(_.keys(cfg), 'basePath', 'names', 'excludes', 'stylusPath'); | ||
badKeys = _.without(_.keys(cfg), 'basePaths', 'names', 'excludes', 'stylusPath'); | ||
if (!badKeys.length) { | ||
@@ -66,0 +70,0 @@ return; |
59
index.js
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
var Cp, Cfg, split$ = ''.split; | ||
var Cp, _, P, Cfg, split$ = ''.split; | ||
Cp = require('child_process'); | ||
_ = require('lodash'); | ||
P = require('path'); | ||
Cfg = require('./config'); | ||
module.exports = function(cb){ | ||
var basePath, cfg, names, n, excludes, p, cmd; | ||
basePath = (cfg = Cfg.get()).basePath; | ||
var basePaths, cfg, names, n, excludes, p, result; | ||
basePaths = (cfg = Cfg.get()).basePaths; | ||
names = (function(){ | ||
@@ -25,24 +27,37 @@ var i$, ref$, len$, results$ = []; | ||
}()).join(' '); | ||
log.debug(cmd = "find " + basePath + " -type f \\( " + names + " \\) " + excludes); | ||
return Cp.exec(cmd, function(err, stdout, stderr){ | ||
var paths, p; | ||
if (err) { | ||
return cb(err); | ||
result = []; | ||
find(); | ||
function find(){ | ||
var basePath, cmd; | ||
if (!(basePath = basePaths[result.length])) { | ||
return cb(null, result); | ||
} | ||
if (stderr.length) { | ||
return new Error(stderr); | ||
} | ||
log.debug(paths = (function(){ | ||
var i$, ref$, len$, results$ = []; | ||
for (i$ = 0, len$ = (ref$ = split$.call(stdout, '\n')).length; i$ < len$; ++i$) { | ||
p = ref$[i$]; | ||
if (p) { | ||
results$.push(p.replace(basePath + "/", '')); | ||
log.debug(cmd = "find " + basePath + " -type f \\( " + names + " \\) " + excludes); | ||
return Cp.exec(cmd, function(err, stdout, stderr){ | ||
var files, f; | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (stderr.length) { | ||
return new Error(stderr); | ||
} | ||
log.debug(files = (function(){ | ||
var i$, ref$, len$, results$ = []; | ||
for (i$ = 0, len$ = (ref$ = split$.call(stdout, '\n')).length; i$ < len$; ++i$) { | ||
f = ref$[i$]; | ||
if (f) { | ||
results$.push(P.relative(basePath, f)); | ||
} | ||
} | ||
} | ||
return results$; | ||
}()).sort()); | ||
return cb(null, paths); | ||
}); | ||
return results$; | ||
}()).sort()); | ||
result.push({ | ||
basePath: basePath, | ||
files: files | ||
}); | ||
return find(); | ||
}); | ||
} | ||
return find; | ||
}; | ||
}).call(this); |
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
var _, Fs, Path, Ws, Config, Transf; | ||
var Cp, Fs, _, Path, Ws, Config, Transf; | ||
Cp = require('child_process'); | ||
Fs = require('fs'); | ||
_ = require('lodash'); | ||
Fs = require('fs'); | ||
Path = require('path'); | ||
@@ -17,27 +18,61 @@ Ws = require('faye-websocket'); | ||
ws = new Ws(req, socket, body); | ||
ws.on('message', function(it){ | ||
var fname, path; | ||
function refreshClient(e){ | ||
log.debug('refresh-client', e, fname); | ||
return Transf(path, function(err, body){ | ||
return ws.on('message', function(it){ | ||
var fpath; | ||
fpath = it.data.replace(/^\/(\d)/, function(m, bidx){ | ||
return Config.get().basePaths[bidx]; | ||
}); | ||
return Cp.exec("stat -fc%T " + fpath, function(err, fsType, stderr){ | ||
var usePolling, refreshClientDebounced, fsw; | ||
if (err || stderr.length) { | ||
if (err) { | ||
return log(err); | ||
log(err); | ||
} | ||
return ws.send(body); | ||
if (stderr.length) { | ||
log(stderr); | ||
} | ||
log('unable to determine filesystem type -- fallback to use polling'); | ||
usePolling = true; | ||
} else { | ||
fsType = fsType.replace('\n', ''); | ||
log("filesystem type is " + fsType); | ||
usePolling = fsType === 'cifs' || fsType === 'nfs' || fsType === 'sshfs' || fsType === 'vboxsf'; | ||
} | ||
refreshClientDebounced = _.debounce(refreshClient, 100, { | ||
leading: false, | ||
trailing: true | ||
}); | ||
} | ||
fname = Path.join(Config.get().basePath, path = it.data); | ||
Fs.watch(fname, _.debounce(refreshClient, 100, { | ||
leading: false, | ||
trailing: true | ||
})); | ||
return refreshClient('init'); | ||
if (usePolling) { | ||
Fs.watchFile(fpath, { | ||
interval: 2000 | ||
}, refreshClientDebounced); | ||
log.debug("watching " + fpath + " using polling"); | ||
} else { | ||
fsw = Fs.watch(fpath, refreshClientDebounced); | ||
log.debug("watching " + fpath + " using inotify"); | ||
} | ||
ws.on('close', function(){ | ||
var ws; | ||
log.debug("stop watching " + fpath); | ||
if (usePolling) { | ||
Fs.unwatchFile(fpath); | ||
} else { | ||
fsw.close(); | ||
} | ||
return ws = void 8; | ||
}); | ||
refreshClient(); | ||
function refreshClient(){ | ||
log.debug('refresh-client', fpath); | ||
return Transf(fpath, function(err, body){ | ||
if (err) { | ||
return log(err); | ||
} | ||
return ws.send(body); | ||
}); | ||
} | ||
return refreshClient; | ||
}); | ||
}); | ||
return ws.on('close', function(){ | ||
var ws; | ||
log.debug('close'); | ||
return ws = void 8; | ||
}); | ||
}); | ||
}; | ||
}).call(this); |
{ | ||
"name": "markfound", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Index a nested directory of markdown files for live preview", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# markfound | ||
[![Build Status][travis-image]][travis-url] | ||
Index a nested directory of [markdown] files for live preview: | ||
Index one or more nested directories of [markdown] files for live preview: | ||
* configure the base-path and Linux-[find] patterns for include/exclude | ||
* styled for GitHub readme.md with option to add custom css | ||
* live refresh automatically updates the preview as you edit your markdown | ||
* configure recursive search paths and Linux-[find] patterns for include/exclude | ||
* styled for GitHub readme.md with option to add custom tweaks css | ||
* live refresh automatically updates the preview as you edit your markdown, even | ||
over nfs, cifs or vboxsf | ||
@@ -19,7 +20,7 @@ ## install globally and run | ||
![index screenshot](http://dizzib.github.io/markfound/index.png) | ||
![index screenshot](./readme/index.png) | ||
Follow a link for a preview which automatically updates as you edit the markdown: | ||
![index screenshot](http://dizzib.github.io/markfound/preview.png) | ||
![index screenshot](./readme/preview.png) | ||
@@ -34,5 +35,6 @@ | ||
* `basePath:` - (required) path to the directory containing the markdown files. | ||
Set to an absolute path to let markfound be run from anywhere. | ||
Default is the current directory. | ||
* `basePaths:` - (required) one or more directory paths to recursively search for markdown files. | ||
Place each path on its own line indented to the same level. | ||
Specify absolute paths to let markfound be run from anywhere. | ||
Default is the current directory only. | ||
@@ -39,0 +41,0 @@ * `names` - (required) a list of one or more wildcard patterns of form `*.ext` |
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
var Args, ErrHan, Express, Http, isDev, env, Morgan, Path, Config, CustCss, LiveRef, Index, x$, express, i$, ref$, len$, na, y$, http, port; | ||
var Args, ErrHan, Express, Http, isDev, env, Morgan, Path, Config, CustCss, LiveRef, Index, x$, express, i$, ref$, len$, na, bidx, bpath, y$, http, port; | ||
global.log = console.log; | ||
@@ -27,3 +27,3 @@ global.log.debug = (Args = require('./args')).verbose | ||
x$.get('/', function(arg$, res, next){ | ||
return Index(function(err, paths){ | ||
return Index(function(err, bases){ | ||
if (err) { | ||
@@ -38,3 +38,3 @@ return next(err); | ||
css: css, | ||
paths: paths | ||
bases: bases | ||
}); | ||
@@ -46,4 +46,9 @@ }); | ||
na = ref$[i$]; | ||
express.get(na, fn$); | ||
express.get("/:bidx/" + na, fn$); | ||
} | ||
for (i$ = 0, len$ = (ref$ = Config.basePaths).length; i$ < len$; ++i$) { | ||
bidx = i$; | ||
bpath = ref$[i$]; | ||
express.use("/" + bidx, Express['static'](bpath)); | ||
} | ||
y$ = express; | ||
@@ -70,8 +75,10 @@ y$.use(Express['static'](__dirname + "/client")); | ||
return CustCss(function(err, css){ | ||
var path; | ||
if (err) { | ||
return next(err); | ||
} | ||
path = req.originalUrl.replace("/" + req.params.bidx + "/", ''); | ||
return res.render('template/github', { | ||
css: css, | ||
title: req.originalUrl | ||
title: path | ||
}); | ||
@@ -78,0 +85,0 @@ }); |
@@ -8,6 +8,4 @@ // Generated by LiveScript 1.4.0 | ||
Cfg = require('./config'); | ||
module.exports = function(path, cb){ | ||
var fullPath; | ||
fullPath = Path.join(Cfg.get().basePath, path); | ||
return Fs.readFile(fullPath, { | ||
module.exports = function(fpath, cb){ | ||
return Fs.readFile(fpath, { | ||
encoding: 'utf8' | ||
@@ -14,0 +12,0 @@ }, function(err, md){ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54179
1016
97
3