Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
88 lines (73 loc) · 2.48 KB
/
Copy pathindex.js
File metadata and controls
88 lines (73 loc) · 2.48 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
80
81
82
83
84
85
86
87
88
var fs = require('fs');
var path = require('path');
var merge = require('lodash/merge');
var spawn = require('child_process').spawn;
var fsExtra = require('fs-extra');
function Plugin(translationOptions) {
var defaultOptions = {
conf: './jsdoc.conf'
};
this.options = merge({}, defaultOptions, translationOptions);
}
Plugin.prototype.apply = function (compiler) {
var self = this;
var options = self.options;
compiler.plugin('watch-run', function (watching, callback) {
self.webpackIsWatching = true;
callback(null, null);
});
compiler.plugin('emit', function (compilation, callback) {
console.log('JSDOC Start generating');
fsExtra.readJson(path.resolve(process.cwd(), options.conf), function (err, obj) {
var files = [], jsdocErrors = [];
var jsdoc, cwd = process.cwd();
if(err) {
callback(err);
return;
}
if (obj.source && obj.source.include) {
console.log('Taking sources from config file');
} else {
compilation.chunks.forEach(function (chunk) {
chunk.modules.forEach(function (module) {
if (module.fileDependencies) {
module.fileDependencies.forEach(function (filepath) {
files.push(path.relative(process.cwd(), filepath));
});
}
});
});
merge(obj.source, { include: files });
}
var jsDocConfTmp = path.resolve(cwd, 'jsdoc.' + Date.now() + '.conf.tmp');
fs.writeFileSync(jsDocConfTmp, JSON.stringify(obj));
if(/^win/.test(process.platform))
jsdoc = spawn(__dirname + '/node_modules/.bin/jsdoc.cmd', ['-c', jsDocConfTmp]);
else
jsdoc = spawn(__dirname + '/node_modules/.bin/jsdoc', ['-c', jsDocConfTmp]);
jsdoc.stdout.on('data', function (data) {
console.log(data.toString());
});
jsdoc.stderr.on('data', function (data) {
jsdocErrors.push(data.toString());
});
jsdoc.on('close', function (data, code) {
if(jsdocErrors.length > 0) {
jsdocErrors.forEach(function (value) {
console.error(value);
});
} else {
console.log('JsDoc successful');
}
fs.unlink(jsDocConfTmp, function() {
callback();
});
});
});
});
compiler.plugin('done', function (stats) {
console.log('JSDOC Finished generating');
console.log('JSDOC TOTAL TIME:', stats.endTime - stats.startTime);
});
};
module.exports = Plugin;