From ef400a9beda1c0f6d55cbb13553f69f64245406c Mon Sep 17 00:00:00 2001 From: Andi Neck Date: Thu, 2 Jun 2016 15:10:23 +0200 Subject: [PATCH 1/3] sort directory entries: first directories, then files --- lib/files.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/files.js b/lib/files.js index 9975de8..0e00af4 100644 --- a/lib/files.js +++ b/lib/files.js @@ -10,13 +10,30 @@ function ReadFile(filePath, filesJson) { try { // Synchronous readdir - files = fs.readdirSync(filePath); + files = fs.readdirSync(filePath) + // sort the files: directories first, afterwards files + .map(function(v) { + var stat = fs.statSync(path.resolve(filePath, v)); + return { + name: v, + isDirectory: stat.isDirectory() + }; + }) + .sort(function(a, b) { + if (a.isDirectory && !b.isDirectory) return -1; + if (!a.isDirectory && b.isDirectory) return 1; + return a.name.localeCompare(b.name); + }) + .map(function(v) { + return v.name; + }); + files.forEach(walk); - } catch (error) { - filesJson = null; //fixme + } catch (error) { + filesJson = null; //fixme console.log(color.red(error.message)); } - + function walk(file) { var newpath = path.join(filePath, file); if (typeof newpath !== 'undefined') { From be8358a465161f80cf5835e7c4ab0adf46579c3f Mon Sep 17 00:00:00 2001 From: Andi Neck Date: Thu, 2 Jun 2016 15:14:59 +0200 Subject: [PATCH 2/3] fix inconsistent indent between subfolders and files in the subfolder --- lib/summary/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/summary/index.js b/lib/summary/index.js index 4b88b2a..6c05d66 100644 --- a/lib/summary/index.js +++ b/lib/summary/index.js @@ -58,7 +58,7 @@ function Summary(options) { next(); }else{ next(color.red("Sorry, something is going wrong or no markdowns.")); - } + } }], parse: ['files', function(next) { @@ -88,7 +88,7 @@ function Summary(options) { // Mark it to skip skip = key; - } + } // The file is `readme.md` if (_.isString(n['readme']) || _.isString(n['Readme']) || _.isString(n['README'])) { @@ -108,7 +108,7 @@ function Summary(options) { return; } - desc += _.repeat(' ', step + 2) + formatCatalog(key) + n; + desc += _.repeat(' ', step) + formatCatalog(key) + n; } } }); @@ -121,11 +121,11 @@ function getFiles(root) { filesJson = {}; readFile(root, filesJson); - + if(filesJson){ result = _.pick(filesJson, filterRules); } - + return result; } @@ -143,7 +143,7 @@ function filterRules(n, key) { } else { result = _.includes(catalog, key) && !_.includes(ignores, key); } - + return result; } From 2568fdba5788e6a1a36f8b1d27c9097ad7518048 Mon Sep 17 00:00:00 2001 From: andineck Date: Fri, 3 Jun 2016 06:33:26 +0200 Subject: [PATCH 3/3] remove empty directories (without links) from summary --- lib/files.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/files.js b/lib/files.js index 0e00af4..ff83a8b 100644 --- a/lib/files.js +++ b/lib/files.js @@ -42,6 +42,10 @@ function ReadFile(filePath, filesJson) { if (state.isDirectory()) { filesJson[file] = {}; ReadFile(newpath, filesJson[file]); + // filter empty directories + if (Object.keys(filesJson[file]).length < 1) { + delete filesJson[file]; + } } else { // Parse the file. var obj = path.parse(newpath);