This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnode2docfx.js
74 lines (63 loc) · 2.38 KB
/
node2docfx.js
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
#!/usr/bin/env node
(function () {
'use strict';
var fs = require('fs');
var fse = require('fs-extra');
var child_process = require('child_process');
var path = require('path');
var jsdocConfigFilename = '_jsdocConfTemp.json';
var jsdocToolPath = 'node_modules/jsdoc/jsdoc.js';
var jsdocToolPathFallback = '../jsdoc/jsdoc.js';
var jsdocPluginPath = 'jsdocs/plugins/yamlGenerator';
var jsdocOutputPath = '_yamlGeneratorOutput/';
if (process.argv.length < 3) {
console.log('Usage: node node2docfx {conf.json}');
}
var node2docfxToolDir = path.dirname(process.argv[1]);
var node2docfxConfigDir = path.dirname(process.argv[2]);
// read node2docfx's config
var configPath = process.argv[2];
var config = {};
if (fs.existsSync(configPath)) {
config = JSON.parse(fs.readFileSync(configPath));
} else {
console.error('Config file ' + configPath + ' doesn\'t exist.');
process.exit(1);
}
// generate jsdoc's config
var jsdocConfig = {
source: config.source,
destination: config.destination,
plugins: [path.join(node2docfxToolDir, jsdocPluginPath)],
package: config.package,
readme: config.readme,
recurseDepth: config.recurseDepth ? config.recurseDepth : 10
};
if (config.repo && config.repo.length > 0) {
jsdocConfig.repo = config.repo[0];
}
var jsdocConfigPath = path.join(node2docfxConfigDir, jsdocConfigFilename);
fs.writeFileSync(jsdocConfigPath, JSON.stringify(jsdocConfig));
// run jsdoc
var toolPath = path.join(node2docfxToolDir, jsdocToolPath);
if (!fs.existsSync(toolPath)) {
toolPath = path.join(node2docfxToolDir, jsdocToolPathFallback);
if (!fs.existsSync(toolPath)) {
console.error('Can\'t find jsdoc.');
}
}
if (process.execArgv.length > 0 && process.execArgv[0].indexOf('--inspect') >= 0) {
child_process.execFileSync('node', ['--inspect-brk=5858', toolPath, '-c', jsdocConfigFilename, '-r'], { cwd: node2docfxConfigDir });
} else {
child_process.execFileSync('node', [toolPath, '-c', jsdocConfigFilename, '-r'], { cwd: node2docfxConfigDir });
}
// rename and clear
if (config.destination) {
var source = path.join(node2docfxConfigDir, jsdocOutputPath);
var dest = path.join(node2docfxConfigDir, config.destination);
fse.ensureDirSync(path.dirname(dest));
fse.removeSync(dest);
fs.renameSync(source, dest);
}
fs.unlinkSync(jsdocConfigPath);
}());