Skip to content

Commit

Permalink
Resolves #4 by actually sorting by file basename and not file path
Browse files Browse the repository at this point in the history
  • Loading branch information
jh3y committed Mar 10, 2016
1 parent 2391da6 commit 89655f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions lib/kody.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
10 changes: 6 additions & 4 deletions src/lib/kody.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 89655f1

Please sign in to comment.