change ref docs url format from 1_5 to v1.5
This commit is contained in:
+187
@@ -0,0 +1,187 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Marked CLI
|
||||
* Copyright (c) 2011-2013, Christopher Jeffrey (MIT License)
|
||||
*/
|
||||
|
||||
var fs = require('fs')
|
||||
, util = require('util')
|
||||
, marked = require('../');
|
||||
|
||||
/**
|
||||
* Man Page
|
||||
*/
|
||||
|
||||
function help() {
|
||||
var spawn = require('child_process').spawn;
|
||||
|
||||
var options = {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
setsid: false,
|
||||
customFds: [0, 1, 2]
|
||||
};
|
||||
|
||||
spawn('man',
|
||||
[__dirname + '/../man/marked.1'],
|
||||
options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main
|
||||
*/
|
||||
|
||||
function main(argv, callback) {
|
||||
var files = []
|
||||
, options = {}
|
||||
, input
|
||||
, output
|
||||
, arg
|
||||
, tokens
|
||||
, opt;
|
||||
|
||||
function getarg() {
|
||||
var arg = argv.shift();
|
||||
|
||||
if (arg.indexOf('--') === 0) {
|
||||
// e.g. --opt
|
||||
arg = arg.split('=');
|
||||
if (arg.length > 1) {
|
||||
// e.g. --opt=val
|
||||
argv.unshift(arg.slice(1).join('='));
|
||||
}
|
||||
arg = arg[0];
|
||||
} else if (arg[0] === '-') {
|
||||
if (arg.length > 2) {
|
||||
// e.g. -abc
|
||||
argv = arg.substring(1).split('').map(function(ch) {
|
||||
return '-' + ch;
|
||||
}).concat(argv);
|
||||
arg = argv.shift();
|
||||
} else {
|
||||
// e.g. -a
|
||||
}
|
||||
} else {
|
||||
// e.g. foo
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
while (argv.length) {
|
||||
arg = getarg();
|
||||
switch (arg) {
|
||||
case '--test':
|
||||
return require('../test').main(process.argv.slice());
|
||||
case '-o':
|
||||
case '--output':
|
||||
output = argv.shift();
|
||||
break;
|
||||
case '-i':
|
||||
case '--input':
|
||||
input = argv.shift();
|
||||
break;
|
||||
case '-t':
|
||||
case '--tokens':
|
||||
tokens = true;
|
||||
break;
|
||||
case '-h':
|
||||
case '--help':
|
||||
return help();
|
||||
default:
|
||||
if (arg.indexOf('--') === 0) {
|
||||
opt = camelize(arg.replace(/^--(no-)?/, ''));
|
||||
if (!marked.defaults.hasOwnProperty(opt)) {
|
||||
continue;
|
||||
}
|
||||
if (arg.indexOf('--no-') === 0) {
|
||||
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
||||
? null
|
||||
: false;
|
||||
} else {
|
||||
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
||||
? argv.shift()
|
||||
: true;
|
||||
}
|
||||
} else {
|
||||
files.push(arg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function getData(callback) {
|
||||
if (!input) {
|
||||
if (files.length <= 2) {
|
||||
return getStdin(callback);
|
||||
}
|
||||
input = files.pop();
|
||||
}
|
||||
return fs.readFile(input, 'utf8', callback);
|
||||
}
|
||||
|
||||
return getData(function(err, data) {
|
||||
if (err) return callback(err);
|
||||
|
||||
data = tokens
|
||||
? JSON.stringify(marked.lexer(data, options), null, 2)
|
||||
: marked(data, options);
|
||||
|
||||
if (!output) {
|
||||
process.stdout.write(data + '\n');
|
||||
return callback();
|
||||
}
|
||||
|
||||
return fs.writeFile(output, data, callback);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function getStdin(callback) {
|
||||
var stdin = process.stdin
|
||||
, buff = '';
|
||||
|
||||
stdin.setEncoding('utf8');
|
||||
|
||||
stdin.on('data', function(data) {
|
||||
buff += data;
|
||||
});
|
||||
|
||||
stdin.on('error', function(err) {
|
||||
return callback(err);
|
||||
});
|
||||
|
||||
stdin.on('end', function() {
|
||||
return callback(null, buff);
|
||||
});
|
||||
|
||||
try {
|
||||
stdin.resume();
|
||||
} catch (e) {
|
||||
callback(e);
|
||||
}
|
||||
}
|
||||
|
||||
function camelize(text) {
|
||||
return text.replace(/(\w)-(\w)/g, function(_, a, b) {
|
||||
return a + b.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose / Entry Point
|
||||
*/
|
||||
|
||||
if (!module.parent) {
|
||||
process.title = 'marked';
|
||||
main(process.argv.slice(), function(err, code) {
|
||||
if (err) throw err;
|
||||
return process.exit(code || 0);
|
||||
});
|
||||
} else {
|
||||
module.exports = main;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var mime = require('./mime.js');
|
||||
var file = process.argv[2];
|
||||
var type = mime.lookup(file);
|
||||
|
||||
process.stdout.write(type + '\n');
|
||||
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
tty = require('tty'),
|
||||
statik = require('./../lib/node-static');
|
||||
|
||||
var argv = require('optimist')
|
||||
.usage([
|
||||
'USAGE: $0 [-p <port>] [<directory>]',
|
||||
'simple, rfc 2616 compliant file streaming module for node']
|
||||
.join('\n\n'))
|
||||
.option('port', {
|
||||
alias: 'p',
|
||||
'default': 8080,
|
||||
description: 'TCP port at which the files will be served'
|
||||
})
|
||||
.option('host-address', {
|
||||
alias: 'a',
|
||||
'default': '127.0.0.1',
|
||||
description: 'the local network interface at which to listen'
|
||||
})
|
||||
.option('cache', {
|
||||
alias: 'c',
|
||||
description: '"Cache-Control" header setting, defaults to 3600'
|
||||
})
|
||||
.option('version', {
|
||||
alias: 'v',
|
||||
description: 'node-static version'
|
||||
})
|
||||
.option('headers', {
|
||||
alias: 'H',
|
||||
description: 'additional headers (in JSON format)'
|
||||
})
|
||||
.option('header-file', {
|
||||
alias: 'f',
|
||||
description: 'JSON file of additional headers'
|
||||
})
|
||||
.option('gzip', {
|
||||
alias: 'z',
|
||||
description: 'enable compression (tries to serve file of same name plus \'.gz\')'
|
||||
})
|
||||
.option('spa', {
|
||||
description: 'serve the content as a single page app by redirecting all non-file requests to the index html file'
|
||||
})
|
||||
.option('indexFile', {
|
||||
alias: 'i',
|
||||
'default': 'index.html',
|
||||
description: 'specify a custom index file when serving up directories'
|
||||
})
|
||||
.option('help', {
|
||||
alias: 'h',
|
||||
description: 'display this help message'
|
||||
})
|
||||
.argv;
|
||||
|
||||
var dir = argv._[0] || '.';
|
||||
|
||||
var colors = require('colors');
|
||||
|
||||
var log = function(request, response, statusCode) {
|
||||
var d = new Date();
|
||||
var seconds = d.getSeconds() < 10? '0'+d.getSeconds() : d.getSeconds(),
|
||||
datestr = d.getHours() + ':' + d.getMinutes() + ':' + seconds,
|
||||
line = datestr + ' [' + response.statusCode + ']: ' + request.url,
|
||||
colorized = line;
|
||||
if (tty.isatty(process.stdout.fd))
|
||||
colorized = (response.statusCode >= 500) ? line.red.bold :
|
||||
(response.statusCode >= 400) ? line.red :
|
||||
line;
|
||||
console.log(colorized);
|
||||
};
|
||||
|
||||
var file, options;
|
||||
|
||||
if (argv.help) {
|
||||
require('optimist').showHelp(console.log);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (argv.version) {
|
||||
console.log('node-static', statik.version.join('.'));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (argv.cache) {
|
||||
(options = options || {}).cache = argv.cache;
|
||||
}
|
||||
|
||||
if (argv.headers) {
|
||||
(options = options || {}).headers = JSON.parse(argv.headers);
|
||||
}
|
||||
|
||||
if (argv['header-file']) {
|
||||
(options = options || {}).headers =
|
||||
JSON.parse(fs.readFileSync(argv['header-file']));
|
||||
}
|
||||
|
||||
if (argv.gzip) {
|
||||
(options = options || {}).gzip = true;
|
||||
}
|
||||
|
||||
if (argv.indexFile) {
|
||||
(options = options || {}).indexFile = argv['indexFile'];
|
||||
}
|
||||
|
||||
file = new(statik.Server)(dir, options);
|
||||
|
||||
require('http').createServer(function (request, response) {
|
||||
request.addListener('end', function () {
|
||||
var callback = function(e, rsp) {
|
||||
if (e && e.status === 404) {
|
||||
response.writeHead(e.status, e.headers);
|
||||
response.end("Not Found");
|
||||
log(request, response);
|
||||
} else {
|
||||
log(request, response);
|
||||
}
|
||||
};
|
||||
|
||||
if (argv['spa'] && request.url.indexOf(".") == -1) {
|
||||
file.serveFile(argv['indexFile'], 500, {}, request, response);
|
||||
} else {
|
||||
file.serve(request, response, callback);
|
||||
}
|
||||
}).resume();
|
||||
}).listen(+argv.port, argv['host-address']);
|
||||
|
||||
console.log('serving "' + dir + '" at http://' + argv['host-address'] + ':' + argv.port);
|
||||
if (argv.spa) {
|
||||
console.log('serving as a single page app (all non-file requests redirect to ' + argv['indexFile'] +')');
|
||||
}
|
||||
Reference in New Issue
Block a user