/**
* Created by littledu on 15/5/16.
*/
var fs = require('fs'),
path = require('path'),
localIp = require('quick-local-ip');
module.exports = function (config) {
var html = [
'',
'
',
'',
'',
'',
'',
'',
'',
'',
'
',
' ',
'
',
'
文件名
',
'
二维码
',
'
',
' ',
' '
].join(''),
tmpHtml = '',
length = '/dev/html/'.length,
collector = listdir('./dev/html'),
ip = localIp.getLocalIP4();
showdir(collector, 0);
function listdir(dir) {
var collector = {
'name': dir,
'type': 'dir',
'url': '',
'child': []
};
files = fs.readdirSync(dir);
files.forEach(function (file) {
var absolutePath = dir + '/' + file,
stats = fs.statSync(absolutePath);
var url = absolutePath.substring(absolutePath.indexOf('./dev/html/') + length + 1);
if (stats.isDirectory() && (stats.isDirectory() !== '.' || stats.isDirectory() !== '..')) {
collector['child'].push(listdir(absolutePath));
} else {
collector['child'].push({
'name': path.basename(absolutePath),
'type': 'file',
'url': url
});
}
});
return collector;
}
function showdir(collector, level) {
var file = collector['name'],
basename = path.basename(file);
var indent = 25 * (level - 1);
if (indent <= 0) {
indent = 10;
}
if (collector['type'] == 'dir') {
if (level != 0) {
html += '