Skip to content

Commit e7a8c23

Browse files
committed
Merge pull request #408 from documentationjs/file-order
Sort documentation in code order.
2 parents ade4f34 + 89895a7 commit e7a8c23

32 files changed

+6531
-6513
lines changed

lib/git/url_prefix.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,22 @@ function getGithubURLPrefix(root) {
1616
var head = fs.readFileSync(path.join(root, '.git', 'HEAD'), 'utf8');
1717
var branch = head.match(/ref\: (.*)/);
1818
if (branch) {
19-
var sha = fs.readFileSync(path.join(root, '.git', branch[1]), 'utf8');
19+
var branchFileName = path.join(root, '.git', branch[1]);
20+
var packedRefsName = path.join(root, '.git', 'packed-refs');
21+
var sha;
22+
if (fs.existsSync(branchFileName)) {
23+
sha = fs.readFileSync(branchFileName, 'utf8');
24+
} else if (fs.existsSync(packedRefsName)) {
25+
sha = fs.readFileSync(packedRefsName, 'utf8')
26+
.split(/\n/)
27+
.filter(function (line) {
28+
return line[0] !== '#' && line[0] !== '^';
29+
})
30+
.reduce(function (memo, line) {
31+
memo[line.split(' ')[1]] = line.split(' ')[0];
32+
return memo;
33+
}, {})[branch[1]];
34+
}
2035
} else {
2136
sha = head;
2237
}

lib/sort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @private
1212
*/
1313
function getSortKey(comment, order) {
14-
var key = comment.name || comment.context.file;
14+
var key = comment.context.file + ':' + comment.context.loc.start.line || comment.name;
1515

1616
if (order && order.indexOf(key) !== -1) {
1717
return order.indexOf(key);

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"eslint": "^2.0.0",
5757
"fs-extra": "^0.26.2",
5858
"glob": "^7.0.0",
59-
"lodash": "^4.3.0",
6059
"mock-fs": "^3.5.0",
6160
"tap": "^5.4.4",
6261
"tmp": "0.0.28",

test/fixture/_external-deps-included.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
},
177177
"tags": [
178178
{
179-
"title": "return",
179+
"title": "returns",
180180
"description": "numberone",
181181
"lineNumber": 2,
182182
"type": {
@@ -187,26 +187,26 @@
187187
],
188188
"loc": {
189189
"start": {
190-
"line": 1,
190+
"line": 5,
191191
"column": 0
192192
},
193193
"end": {
194-
"line": 4,
194+
"line": 8,
195195
"column": 3
196196
}
197197
},
198198
"context": {
199199
"loc": {
200200
"start": {
201-
"line": 5,
201+
"line": 9,
202202
"column": 0
203203
},
204204
"end": {
205-
"line": 8,
205+
"line": 12,
206206
"column": 2
207207
}
208208
},
209-
"code": "/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n"
209+
"code": "'use strict';\n\nvar otherDep = require('external2');\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return otherDep() - 1;\n};\n"
210210
},
211211
"errors": [],
212212
"returns": [
@@ -269,14 +269,14 @@
269269
}
270270
}
271271
],
272-
"name": "index",
272+
"name": "main",
273273
"kind": "function",
274274
"members": {
275275
"instance": [],
276276
"static": []
277277
},
278278
"path": [
279-
"index"
279+
"main"
280280
]
281281
},
282282
{
@@ -334,7 +334,7 @@
334334
},
335335
"tags": [
336336
{
337-
"title": "returns",
337+
"title": "return",
338338
"description": "numberone",
339339
"lineNumber": 2,
340340
"type": {
@@ -345,26 +345,26 @@
345345
],
346346
"loc": {
347347
"start": {
348-
"line": 5,
348+
"line": 1,
349349
"column": 0
350350
},
351351
"end": {
352-
"line": 8,
352+
"line": 4,
353353
"column": 3
354354
}
355355
},
356356
"context": {
357357
"loc": {
358358
"start": {
359-
"line": 9,
359+
"line": 5,
360360
"column": 0
361361
},
362362
"end": {
363-
"line": 12,
363+
"line": 8,
364364
"column": 2
365365
}
366366
},
367-
"code": "'use strict';\n\nvar otherDep = require('external2');\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return otherDep() - 1;\n};\n"
367+
"code": "/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n"
368368
},
369369
"errors": [],
370370
"returns": [
@@ -427,14 +427,14 @@
427427
}
428428
}
429429
],
430-
"name": "main",
430+
"name": "index",
431431
"kind": "function",
432432
"members": {
433433
"instance": [],
434434
"static": []
435435
},
436436
"path": [
437-
"main"
437+
"index"
438438
]
439439
}
440440
]

0 commit comments

Comments
 (0)