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 | };
|
40 | if (config.repo && config.repo.length > 0) {
|
41 | jsdocConfig.repo = config.repo[0];
|
42 | }
|
43 |
|
44 | var jsdocConfigPath = path.join(node2docfxConfigDir, jsdocConfigFilename);
|
45 | fs.writeFileSync(jsdocConfigPath, JSON.stringify(jsdocConfig));
|
46 |
|
47 |
|
48 | var toolPath = path.join(node2docfxToolDir, jsdocToolPath);
|
49 | if (!fs.existsSync(toolPath)) {
|
50 | toolPath = path.join(node2docfxToolDir, jsdocToolPathFallback);
|
51 | if (!fs.existsSync(toolPath)) {
|
52 | console.err('Can\'t find jsdoc.');
|
53 | }
|
54 | }
|
55 |
|
56 | if (process.execArgv.length > 0 && process.execArgv[0].indexOf('--inspect') >= 0) {
|
57 | child_process.execFileSync('node', ['--inspect-brk=5858', toolPath, '-c', jsdocConfigFilename, '-r'], { cwd: node2docfxConfigDir });
|
58 | } else {
|
59 | child_process.execFileSync('node', [toolPath, '-c', jsdocConfigFilename, '-r'], { cwd: node2docfxConfigDir });
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 | if (config.destination) {
|
65 | var source = path.join(node2docfxConfigDir, jsdocOutputPath);
|
66 | var dest = path.join(node2docfxConfigDir, config.destination);
|
67 | fse.ensureDirSync(path.dirname(dest));
|
68 | fs.renameSync(source, dest);
|
69 | }
|
70 | fs.unlinkSync(jsdocConfigPath);
|
71 | }());
|
72 |
|