1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | var _ = require('underscore');
|
9 | var dump = require('jsdoc/util/dumper').dump;
|
10 | var env = require('jsdoc/env');
|
11 | var util = require('util');
|
12 |
|
13 | var conf = env.conf.eventDumper || {};
|
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 |
|
29 | if (conf.exclude) {
|
30 | events = _.difference(events, conf.exclude);
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function replaceNodeObjects(o) {
|
40 | var doop = require('jsdoc/util/doop');
|
41 |
|
42 | var OBJECT_PLACEHOLDER = '<Object>';
|
43 |
|
44 | if (o.code && o.code.node) {
|
45 |
|
46 | o.code = doop(o.code);
|
47 | o.code.node = OBJECT_PLACEHOLDER;
|
48 | }
|
49 |
|
50 | if (o.doclet && o.doclet.meta && o.doclet.meta.code && o.doclet.meta.code.node) {
|
51 |
|
52 | o.doclet.meta.code = doop(o.doclet.meta.code);
|
53 | o.doclet.meta.code.node = OBJECT_PLACEHOLDER;
|
54 | }
|
55 |
|
56 | if (o.astnode) {
|
57 | o.astnode = OBJECT_PLACEHOLDER;
|
58 | }
|
59 |
|
60 | return o;
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | function cleanse(e) {
|
70 | var result = {};
|
71 |
|
72 | Object.keys(e).forEach(function(prop) {
|
73 |
|
74 | if (!conf.includeFunctions && util.isArray(e[prop]) && e[prop][0] &&
|
75 | String(typeof e[prop][0]) === 'function') {
|
76 | result[prop] = 'function[' + e[prop].length + ']';
|
77 | }
|
78 |
|
79 | else if (typeof e[prop] !== 'function') {
|
80 | result[prop] = e[prop];
|
81 | }
|
82 | });
|
83 |
|
84 |
|
85 | if (conf.omitNodes) {
|
86 | result = replaceNodeObjects(result);
|
87 | }
|
88 |
|
89 | return result;
|
90 | }
|
91 |
|
92 | exports.handlers = {};
|
93 |
|
94 | events.forEach(function(eventType) {
|
95 | exports.handlers[eventType] = function(e) {
|
96 | console.log( dump({
|
97 | type: eventType,
|
98 | content: cleanse(e)
|
99 | }) );
|
100 | };
|
101 | });
|