Skip to content

Commit 89655f1

Browse files
committed
Resolves #4 by actually sorting by file basename and not file path
1 parent 2391da6 commit 89655f1

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/kody.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,15 @@ processTasks = function processTasks(tasks) {
164164
/**
165165
* used to sort ordering of task files based on desire.
166166
*
167-
* @param {string} a - string representing task filename
168-
* @param {string} b - string representing task filename
167+
* @param {string} a - string representing task filepath
168+
* @param {string} b - string representing task filepath
169169
* @returns {bool} - used by Array.sort
170170
*/
171171
sortFiles = function sortFiles(a, b) {
172-
var aIndex = rc.order.indexOf(a),
173-
bIndex = rc.order.indexOf(b);
172+
var taskA = a.substring(a.lastIndexOf('/') + 1),
173+
taskB = b.substring(b.lastIndexOf('/') + 1),
174+
aIndex = rc.order.indexOf(taskA),
175+
bIndex = rc.order.indexOf(taskB);
174176
if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex) return -1;
175177
if (aIndex !== -1 || bIndex !== -1) return 1;
176178
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kody",
33
"description": ".files in node",
4-
"version": "1.0.1",
4+
"version": "1.1.1",
55
"main": "index.js",
66
"homepage": "https://github.com/jh3y/kody",
77
"author": {

src/lib/kody.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ const PROPS = {
9898
/**
9999
* used to sort ordering of task files based on desire.
100100
*
101-
* @param {string} a - string representing task filename
102-
* @param {string} b - string representing task filename
101+
* @param {string} a - string representing task filepath
102+
* @param {string} b - string representing task filepath
103103
* @returns {bool} - used by Array.sort
104104
*/
105105
sortFiles = function(a, b) {
106-
const aIndex = rc.order.indexOf(a),
107-
bIndex = rc.order.indexOf(b);
106+
const taskA = a.substring(a.lastIndexOf('/') + 1),
107+
taskB = b.substring(b.lastIndexOf('/') + 1),
108+
aIndex = rc.order.indexOf(taskA),
109+
bIndex = rc.order.indexOf(taskB);
108110
if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex)
109111
return -1;
110112
if (aIndex !== -1 || bIndex !== -1)

0 commit comments

Comments
 (0)