forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomments.js
More file actions
79 lines (64 loc) · 2.2 KB
/
Copy pathcomments.js
File metadata and controls
79 lines (64 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// https://github.com/jonschlinkert/extract-comments
// https://github.com/eslint/doctrine
// https://nodejs.org/api/fs.html
// https://github.com/jprichardson/node-fs-extra
var fs = require('fs-extra');
var extract = require('extract-comments');
var beautify = require('json-beautify');
var doctrine = require('doctrine');
var source = './src/gameobjects/GameObject.js';
var dest = './docs/comments.json';
var doctrineOptions = {
unwrap: true,
recoverable: true,
sloppy: true,
lineNumbers: true
};
fs.readFile(source, 'utf8', (err, data) => {
if (err)
{
throw err;
}
var comments = [];
var blocks = extract.block(data);
/*
// Example extracted docblock:
{
"type": "block",
"range": [ 1181, 1414 ],
"loc": { "start": { "line": 37, "column": 8 }, "end": { "line": 42, "column": 11 } },
"raw": "*\r\n * A textual representation of this Game Object, i.e. `sprite`.\r\n * Used internally by Phaser but is available for your own custom classes to populate.\r\n *\r\n * @property {string} type\r\n ",
"value": "\r\nA textual representation of this Game Object, i.e. `sprite`.\r\nUsed internally by Phaser but is available for your own custom classes to populate.\r\n\r\n@property {string} type",
"code": {
"context": {
"type": "property",
"receiver": "this",
"name": "type",
"value": "type",
"string": "this.type"
},
"value": "this.type = type;\r",
"line": 44,
"loc": { "start": { "line": 44, "column": 1424 }, "end": { "line": 44, "column": 1442 } }
}
},
*/
for (var i = 0; i < blocks.length; i++)
{
var block = blocks[i];
comments.push(doctrine.parse(block.value, doctrineOptions));
}
// comments = JSON.stringify(comments);
comments = beautify(comments, null, 2, 100); // just for debugging really
// comments = beautify(blocks, null, 2, 100); // just for debugging really
fs.writeFile(dest, comments, { encoding: 'utf8', flag: 'w' }, function (error) {
if (error)
{
throw error;
}
else
{
console.log('Comments written');
}
});
});