From 89655f101a2add3e9dfd6ac01522e2d0739fb67e Mon Sep 17 00:00:00 2001 From: jh3y Date: Thu, 10 Mar 2016 19:35:04 +0000 Subject: [PATCH] Resolves #4 by actually sorting by file basename and not file path --- lib/kody.js | 10 ++++++---- package.json | 2 +- src/lib/kody.js | 10 ++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/kody.js b/lib/kody.js index 5f24b9f..c65286a 100644 --- a/lib/kody.js +++ b/lib/kody.js @@ -164,13 +164,15 @@ processTasks = function processTasks(tasks) { /** * used to sort ordering of task files based on desire. * - * @param {string} a - string representing task filename - * @param {string} b - string representing task filename + * @param {string} a - string representing task filepath + * @param {string} b - string representing task filepath * @returns {bool} - used by Array.sort */ sortFiles = function sortFiles(a, b) { - var aIndex = rc.order.indexOf(a), - bIndex = rc.order.indexOf(b); + var taskA = a.substring(a.lastIndexOf('/') + 1), + taskB = b.substring(b.lastIndexOf('/') + 1), + aIndex = rc.order.indexOf(taskA), + bIndex = rc.order.indexOf(taskB); if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex) return -1; if (aIndex !== -1 || bIndex !== -1) return 1; }, diff --git a/package.json b/package.json index 3fd57ba..7008180 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kody", "description": ".files in node", - "version": "1.0.1", + "version": "1.1.1", "main": "index.js", "homepage": "https://github.com/jh3y/kody", "author": { diff --git a/src/lib/kody.js b/src/lib/kody.js index 4ca5ab0..7bc321d 100644 --- a/src/lib/kody.js +++ b/src/lib/kody.js @@ -98,13 +98,15 @@ const PROPS = { /** * used to sort ordering of task files based on desire. * - * @param {string} a - string representing task filename - * @param {string} b - string representing task filename + * @param {string} a - string representing task filepath + * @param {string} b - string representing task filepath * @returns {bool} - used by Array.sort */ sortFiles = function(a, b) { - const aIndex = rc.order.indexOf(a), - bIndex = rc.order.indexOf(b); + const taskA = a.substring(a.lastIndexOf('/') + 1), + taskB = b.substring(b.lastIndexOf('/') + 1), + aIndex = rc.order.indexOf(taskA), + bIndex = rc.order.indexOf(taskB); if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex) return -1; if (aIndex !== -1 || bIndex !== -1)