1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | 'use strict';
|
8 |
|
9 | var _ = require('underscore');
|
10 | var util = require('util');
|
11 |
|
12 | var conf = env.conf.eventDumper || {};
|
13 | var isRhino = require('jsdoc/util/runtime').isRhino();
|
14 |
|
15 |
|
16 | var events = conf.include || [
|
17 | 'parseBegin',
|
18 | 'fileBegin',
|
19 | 'beforeParse',
|
20 | 'jsdocCommentFound',
|
21 | 'symbolFound',
|
22 | 'newDoclet',
|
23 | 'fileComplete',
|
24 | 'parseComplete',
|
25 | 'processingComplete'
|
26 | ];
|
27 |
|
28 | if (conf.exclude) {
|
29 | events = _.difference(events, conf.exclude);
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | function isJavaNativeObject(o) {
|
39 | if (!isRhino) {
|
40 | return false;
|
41 | }
|
42 |
|
43 | return o && typeof o === 'object' && typeof o.getClass === 'function';
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | function replaceNodeObjects(o) {
|
53 | var doop = require('jsdoc/util/doop');
|
54 |
|
55 | var OBJECT_PLACEHOLDER = '<Object>';
|
56 |
|
57 | if (o.code && o.code.node) {
|
58 |
|
59 | o.code = doop(o.code);
|
60 | o.code.node = OBJECT_PLACEHOLDER;
|
61 | }
|
62 |
|
63 | if (o.doclet && o.doclet.meta && o.doclet.meta.code && o.doclet.meta.code.node) {
|
64 |
|
65 | o.doclet.meta.code = doop(o.doclet.meta.code);
|
66 | o.doclet.meta.code.node = OBJECT_PLACEHOLDER;
|
67 | }
|
68 |
|
69 | if (o.astnode) {
|
70 | o.astnode = OBJECT_PLACEHOLDER;
|
71 | }
|
72 |
|
73 | return o;
|
74 | }
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | function cleanse(e) {
|
83 | var result = {};
|
84 |
|
85 | Object.keys(e).forEach(function(prop) {
|
86 |
|
87 | if (!conf.includeFunctions && util.isArray(e[prop]) && e[prop][0] &&
|
88 | String(typeof e[prop][0]) === 'function') {
|
89 | result[prop] = 'function[' + e[prop].length + ']';
|
90 | }
|
91 |
|
92 | else if (typeof e[prop] !== 'function') {
|
93 |
|
94 | result[prop] = isJavaNativeObject(e[prop]) ? String(e[prop]) : e[prop];
|
95 | }
|
96 | });
|
97 |
|
98 |
|
99 | if (conf.omitNodes) {
|
100 | result = replaceNodeObjects(result);
|
101 | }
|
102 |
|
103 | return result;
|
104 | }
|
105 |
|
106 | exports.handlers = {};
|
107 |
|
108 | events.forEach(function(eventType) {
|
109 | exports.handlers[eventType] = function(e) {
|
110 | console.log( JSON.stringify({
|
111 | type: eventType,
|
112 | content: cleanse(e)
|
113 | }, null, 4) );
|
114 | };
|
115 | });
|