1 | #!/usr/bin/env node
|
2 |
|
3 | (function () {
|
4 | 'use strict';
|
5 | var fs = require('fs');
|
6 | var fse = require('fs-extra');
|
7 | var child_process = require('child_process');
|
8 | var path = require('path');
|
9 |
|
10 | var jsdocConfigFilename = '_jsdocConfTemp.json';
|
11 | var jsdocToolPath = 'node_modules/jsdoc/jsdoc.js';
|
12 | var jsdocToolPathFallback = '../jsdoc/jsdoc.js';
|
13 | var jsdocPluginPath = 'jsdocs/plugins/yamlGenerator';
|
14 | var jsdocOutputPath = '_yamlGeneratorOutput/';
|
15 |
|
16 | if (process.argv.length < 3) {
|
17 | console.log('Usage: node node2docfx {conf.json}');
|
18 | }
|
19 | var node2docfxToolDir = path.dirname(process.argv[1]);
|
20 | var node2docfxConfigDir = path.dirname(process.argv[2]);
|
21 |
|
22 |
|
23 | var configPath = process.argv[2];
|
24 | var config = {};
|
25 | if (fs.existsSync(configPath)) {
|
26 | config = JSON.parse(fs.readFileSync(configPath));
|
27 | } else {
|
28 | console.error('Config file ' + configPath + ' doesn\'t exist.');
|
29 | process.exit(1);
|
30 | }
|
31 |
|
32 |
|
33 | var jsdocConfig = {
|
34 | source: config.source,
|
35 | destination: config.destination,
|
36 | plugins: [path.join(node2docfxToolDir, jsdocPluginPath)],
|
37 | package: config.package,
|
38 | readme: config.readme,
|
39 | recurseDepth: config.recurseDepth ? config.recurseDepth : 10
|
40 | };
|
41 | if (config.repo && config.repo.length > 0) {
|
42 | jsdocConfig.repo = config.repo[0];
|
43 | }
|
44 |
|
45 | var jsdocConfigPath = path.join(node2docfxConfigDir, jsdocConfigFilename);
|
46 | fs.writeFileSync(jsdocConfigPath, JSON.stringify(jsdocConfig));
|
47 |
|
48 |
|
49 | var toolPath = path.join(node2docfxToolDir, jsdocToolPath);
|
50 | if (!fs.existsSync(toolPath)) {
|
51 | toolPath = path.join(node2docfxToolDir, jsdocToolPathFallback);
|
52 | if (!fs.existsSync(toolPath)) {
|
53 | console.err('Can\'t find jsdoc.');
|
54 | }
|
55 | }
|
56 |
|
57 | if (process.execArgv.length > 0 && process.execArgv[0].indexOf('--inspect') >= 0) {
|
58 | child_process.execFileSync('node', ['--inspect-brk=5858', toolPath, '-c', jsdocConfigFilename, '-r'], { cwd: node2docfxConfigDir });
|
59 | } else {
|
60 | child_process.execFileSync('node', [toolPath, '-c', jsdocConfigFilename, '-r'], { cwd: node2docfxConfigDir });
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 | if (config.destination) {
|
66 | var source = path.join(node2docfxConfigDir, jsdocOutputPath);
|
67 | var dest = path.join(node2docfxConfigDir, config.destination);
|
68 | fse.ensureDirSync(path.dirname(dest));
|
69 | fs.renameSync(source, dest);
|
70 | }
|
71 | fs.unlinkSync(jsdocConfigPath);
|
72 | }());
|
73 |
|