1 | import * as fs from 'fs-extra';
|
2 | import * as path from 'path';
|
3 |
|
4 | import { ts } from 'ts-simple-ast';
|
5 |
|
6 | import { Application } from './app/application';
|
7 | import Configuration from './app/configuration';
|
8 | import FileEngine from './app/engines/file.engine';
|
9 | import I18nEngine from './app/engines/i18n.engine';
|
10 |
|
11 | import { ConfigurationFileInterface } from './app/interfaces/configuration-file.interface';
|
12 | import AngularVersionUtil from './utils/angular-version.util';
|
13 | import { COMPODOC_DEFAULTS } from './utils/defaults';
|
14 | import { logger } from './utils/logger';
|
15 | import { ParserUtil } from './utils/parser.util.class';
|
16 | import { handlePath, readConfig } from './utils/utils';
|
17 |
|
18 | const cosmiconfig = require('cosmiconfig');
|
19 | const os = require('os');
|
20 | const osName = require('os-name');
|
21 | const pkg = require('../package.json');
|
22 | const program = require('commander');
|
23 |
|
24 | const cosmiconfigModuleName = 'compodoc';
|
25 |
|
26 | let scannedFiles = [];
|
27 | let excludeFiles;
|
28 | let includeFiles;
|
29 | let cwd = process.cwd();
|
30 |
|
31 | process.setMaxListeners(0);
|
32 |
|
33 | export class CliApplication extends Application {
|
34 | |
35 |
|
36 |
|
37 | protected start(): any {
|
38 | function list(val) {
|
39 | return val.split(',');
|
40 | }
|
41 |
|
42 | program
|
43 | .version(pkg.version)
|
44 | .usage('<src> [options]')
|
45 | .option(
|
46 | '-c, --config [config]',
|
47 | 'A configuration file : .compodocrc, .compodocrc.json, .compodocrc.yaml or compodoc property in package.json'
|
48 | )
|
49 | .option('-p, --tsconfig [config]', 'A tsconfig.json file')
|
50 | .option(
|
51 | '-d, --output [folder]',
|
52 | 'Where to store the generated documentation',
|
53 | COMPODOC_DEFAULTS.folder
|
54 | )
|
55 | .option('-y, --extTheme [file]', 'External styling theme file')
|
56 | .option('-n, --name [name]', 'Title documentation', COMPODOC_DEFAULTS.title)
|
57 | .option(
|
58 | '-a, --assetsFolder [folder]',
|
59 | 'External assets folder to copy in generated documentation folder'
|
60 | )
|
61 | .option('-o, --open [value]', 'Open the generated documentation')
|
62 | .option(
|
63 | '-t, --silent',
|
64 | "In silent mode, log messages aren't logged in the console",
|
65 | false
|
66 | )
|
67 | .option(
|
68 | '-s, --serve',
|
69 | 'Serve generated documentation (default http://localhost:8080/)',
|
70 | false
|
71 | )
|
72 | .option('--host [host]', 'Change default host address')
|
73 | .option('-r, --port [port]', 'Change default serving port', COMPODOC_DEFAULTS.port)
|
74 | .option(
|
75 | '-w, --watch',
|
76 | 'Watch source files after serve and force documentation rebuild',
|
77 | false
|
78 | )
|
79 | .option(
|
80 | '-e, --exportFormat [format]',
|
81 | 'Export in specified format (json, html)',
|
82 | COMPODOC_DEFAULTS.exportFormat
|
83 | )
|
84 | .option('--files [files]', 'Files provided by external tool, used for coverage test')
|
85 | .option(
|
86 | '--language [language]',
|
87 | 'Language used for the generated documentation (de-DE, en-US, es-ES, fr-FR, hu-HU, it-IT, ja-JP, nl-NL, pt-BR, sk-SK, zh-CN)',
|
88 | COMPODOC_DEFAULTS.language
|
89 | )
|
90 | .option(
|
91 | '--theme [theme]',
|
92 | "Choose one of available themes, default is 'gitbook' (laravel, original, material, postmark, readthedocs, stripe, vagrant)"
|
93 | )
|
94 | .option(
|
95 | '--hideGenerator',
|
96 | 'Do not print the Compodoc link at the bottom of the page',
|
97 | false
|
98 | )
|
99 | .option(
|
100 | '--toggleMenuItems <items>',
|
101 | "Close by default items in the menu values : ['all'] or one of these ['modules','components','directives','controllers','classes','injectables','guards','interfaces','interceptors','pipes','miscellaneous','additionalPages']",
|
102 | list,
|
103 | COMPODOC_DEFAULTS.toggleMenuItems
|
104 | )
|
105 | .option(
|
106 | '--navTabConfig <tab configs>',
|
107 | `List navigation tab objects in the desired order with two string properties ("id" and "label"). \
|
108 | Double-quotes must be escaped with '\\'. \
|
109 | Available tab IDs are "info", "readme", "source", "templateData", "styleData", "tree", and "example". \
|
110 | Note: Certain tabs will only be shown if applicable to a given dependency`,
|
111 | list,
|
112 | JSON.stringify(COMPODOC_DEFAULTS.navTabConfig)
|
113 | )
|
114 | .option(
|
115 | '--templates [folder]',
|
116 | 'Path to directory of Handlebars templates to override built-in templates'
|
117 | )
|
118 | .option('--includes [path]', 'Path of external markdown files to include')
|
119 | .option(
|
120 | '--includesName [name]',
|
121 | 'Name of item menu of externals markdown files',
|
122 | COMPODOC_DEFAULTS.additionalEntryName
|
123 | )
|
124 | .option(
|
125 | '--coverageTest [threshold]',
|
126 | 'Test command of documentation coverage with a threshold (default 70)'
|
127 | )
|
128 | .option(
|
129 | '--coverageMinimumPerFile [minimum]',
|
130 | 'Test command of documentation coverage per file with a minimum (default 0)'
|
131 | )
|
132 | .option(
|
133 | '--coverageTestThresholdFail [true|false]',
|
134 | 'Test command of documentation coverage (global or per file) will fail with error or just warn user (true: error, false: warn)',
|
135 | COMPODOC_DEFAULTS.coverageTestThresholdFail
|
136 | )
|
137 | .option('--coverageTestShowOnlyFailed', 'Display only failed files for a coverage test')
|
138 | .option(
|
139 | '--unitTestCoverage [json-summary]',
|
140 | 'To include unit test coverage, specify istanbul JSON coverage summary file'
|
141 | )
|
142 | .option(
|
143 | '--disableSourceCode',
|
144 | 'Do not add source code tab and links to source code',
|
145 | false
|
146 | )
|
147 | .option('--disableDomTree', 'Do not add dom tree tab', false)
|
148 | .option('--disableTemplateTab', 'Do not add template tab', false)
|
149 | .option('--disableStyleTab', 'Do not add style tab', false)
|
150 | .option('--disableGraph', 'Do not add the dependency graph', false)
|
151 | .option('--disableCoverage', 'Do not add the documentation coverage report', false)
|
152 | .option('--disablePrivate', 'Do not show private in generated documentation', false)
|
153 | .option('--disableProtected', 'Do not show protected in generated documentation', false)
|
154 | .option('--disableInternal', 'Do not show @internal in generated documentation', false)
|
155 | .option(
|
156 | '--disableLifeCycleHooks',
|
157 | 'Do not show Angular lifecycle hooks in generated documentation',
|
158 | false
|
159 | )
|
160 | .option(
|
161 | '--disableRoutesGraph',
|
162 | 'Do not add the routes graph',
|
163 | COMPODOC_DEFAULTS.disableRoutesGraph
|
164 | )
|
165 | .option('--disableSearch', 'Do not add the search input', false)
|
166 | .option(
|
167 | '--disableDependencies',
|
168 | 'Do not add the dependencies list',
|
169 | COMPODOC_DEFAULTS.disableDependencies
|
170 | )
|
171 | .option(
|
172 | '--minimal',
|
173 | 'Minimal mode with only documentation. No search, no graph, no coverage.',
|
174 | false
|
175 | )
|
176 | .option('--customFavicon [path]', 'Use a custom favicon')
|
177 | .option('--customLogo [path]', 'Use a custom logo')
|
178 | .option('--gaID [id]', 'Google Analytics tracking ID')
|
179 | .option('--gaSite [site]', 'Google Analytics site name', COMPODOC_DEFAULTS.gaSite)
|
180 | .option(
|
181 | '--maxSearchResults [maxSearchResults]',
|
182 | 'Max search results on the results page. To show all results, set to 0',
|
183 | COMPODOC_DEFAULTS.maxSearchResults
|
184 | )
|
185 | .parse(process.argv);
|
186 |
|
187 | let outputHelp = () => {
|
188 | program.outputHelp();
|
189 | process.exit(1);
|
190 | };
|
191 |
|
192 | const configExplorer = cosmiconfig(cosmiconfigModuleName);
|
193 |
|
194 | let configExplorerResult;
|
195 |
|
196 | let configFile: ConfigurationFileInterface = {};
|
197 |
|
198 | if (program.config) {
|
199 | let configFilePath = program.config;
|
200 | let testConfigFilePath = configFilePath.match(process.cwd());
|
201 | if (testConfigFilePath && testConfigFilePath.length > 0) {
|
202 | configFilePath = configFilePath.replace(process.cwd() + path.sep, '');
|
203 | }
|
204 | configExplorerResult = configExplorer.loadSync(path.resolve(configFilePath));
|
205 | } else {
|
206 | configExplorerResult = configExplorer.searchSync();
|
207 | }
|
208 | if (configExplorerResult) {
|
209 | if (typeof configExplorerResult.config !== 'undefined') {
|
210 | configFile = configExplorerResult.config;
|
211 | }
|
212 | }
|
213 |
|
214 | if (configFile.output) {
|
215 | Configuration.mainData.output = configFile.output;
|
216 | }
|
217 | if (program.output && program.output !== COMPODOC_DEFAULTS.folder) {
|
218 | Configuration.mainData.output = program.output;
|
219 | }
|
220 |
|
221 | if (configFile.extTheme) {
|
222 | Configuration.mainData.extTheme = configFile.extTheme;
|
223 | }
|
224 | if (program.extTheme) {
|
225 | Configuration.mainData.extTheme = program.extTheme;
|
226 | }
|
227 |
|
228 | if (configFile.language) {
|
229 | Configuration.mainData.language = configFile.language;
|
230 | }
|
231 | if (program.language) {
|
232 | Configuration.mainData.language = program.language;
|
233 | }
|
234 |
|
235 | if (configFile.theme) {
|
236 | Configuration.mainData.theme = configFile.theme;
|
237 | }
|
238 | if (program.theme) {
|
239 | Configuration.mainData.theme = program.theme;
|
240 | }
|
241 |
|
242 | if (configFile.name) {
|
243 | Configuration.mainData.documentationMainName = configFile.name;
|
244 | }
|
245 | if (program.name && program.name !== COMPODOC_DEFAULTS.title) {
|
246 | Configuration.mainData.documentationMainName = program.name;
|
247 | }
|
248 |
|
249 | if (configFile.assetsFolder) {
|
250 | Configuration.mainData.assetsFolder = configFile.assetsFolder;
|
251 | }
|
252 | if (program.assetsFolder) {
|
253 | Configuration.mainData.assetsFolder = program.assetsFolder;
|
254 | }
|
255 |
|
256 | if (configFile.open) {
|
257 | Configuration.mainData.open = configFile.open;
|
258 | }
|
259 | if (program.open) {
|
260 | Configuration.mainData.open = program.open;
|
261 | }
|
262 |
|
263 | if (configFile.toggleMenuItems) {
|
264 | Configuration.mainData.toggleMenuItems = configFile.toggleMenuItems;
|
265 | }
|
266 | if (
|
267 | program.toggleMenuItems &&
|
268 | program.toggleMenuItems !== COMPODOC_DEFAULTS.toggleMenuItems
|
269 | ) {
|
270 | Configuration.mainData.toggleMenuItems = program.toggleMenuItems;
|
271 | }
|
272 |
|
273 | if (configFile.templates) {
|
274 | Configuration.mainData.templates = configFile.templates;
|
275 | }
|
276 | if (program.templates) {
|
277 | Configuration.mainData.templates = program.templates;
|
278 | }
|
279 |
|
280 | if (configFile.navTabConfig) {
|
281 | Configuration.mainData.navTabConfig = configFile.navTabConfig;
|
282 | }
|
283 | if (
|
284 | program.navTabConfig &&
|
285 | JSON.parse(program.navTabConfig).length !== COMPODOC_DEFAULTS.navTabConfig.length
|
286 | ) {
|
287 | Configuration.mainData.navTabConfig = JSON.parse(program.navTabConfig);
|
288 | }
|
289 |
|
290 | if (configFile.includes) {
|
291 | Configuration.mainData.includes = configFile.includes;
|
292 | }
|
293 | if (program.includes) {
|
294 | Configuration.mainData.includes = program.includes;
|
295 | }
|
296 |
|
297 | if (configFile.includesName) {
|
298 | Configuration.mainData.includesName = configFile.includesName;
|
299 | }
|
300 | if (
|
301 | program.includesName &&
|
302 | program.includesName !== COMPODOC_DEFAULTS.additionalEntryName
|
303 | ) {
|
304 | Configuration.mainData.includesName = program.includesName;
|
305 | }
|
306 |
|
307 | if (configFile.silent) {
|
308 | logger.silent = false;
|
309 | }
|
310 | if (program.silent) {
|
311 | logger.silent = false;
|
312 | }
|
313 |
|
314 | if (configFile.serve) {
|
315 | Configuration.mainData.serve = configFile.serve;
|
316 | }
|
317 | if (program.serve) {
|
318 | Configuration.mainData.serve = program.serve;
|
319 | }
|
320 |
|
321 | if (configFile.host) {
|
322 | Configuration.mainData.host = configFile.host;
|
323 | Configuration.mainData.hostname = configFile.host;
|
324 | }
|
325 | if (program.host) {
|
326 | Configuration.mainData.host = program.host;
|
327 | Configuration.mainData.hostname = program.host;
|
328 | }
|
329 |
|
330 | if (configFile.port) {
|
331 | Configuration.mainData.port = configFile.port;
|
332 | }
|
333 | if (program.port && program.port !== COMPODOC_DEFAULTS.port) {
|
334 | Configuration.mainData.port = program.port;
|
335 | }
|
336 |
|
337 | if (configFile.watch) {
|
338 | Configuration.mainData.watch = configFile.watch;
|
339 | }
|
340 | if (program.watch) {
|
341 | Configuration.mainData.watch = program.watch;
|
342 | }
|
343 |
|
344 | if (configFile.exportFormat) {
|
345 | Configuration.mainData.exportFormat = configFile.exportFormat;
|
346 | }
|
347 | if (program.exportFormat && program.exportFormat !== COMPODOC_DEFAULTS.exportFormat) {
|
348 | Configuration.mainData.exportFormat = program.exportFormat;
|
349 | }
|
350 |
|
351 | if (configFile.hideGenerator) {
|
352 | Configuration.mainData.hideGenerator = configFile.hideGenerator;
|
353 | }
|
354 | if (program.hideGenerator) {
|
355 | Configuration.mainData.hideGenerator = program.hideGenerator;
|
356 | }
|
357 |
|
358 | if (configFile.coverageTest) {
|
359 | Configuration.mainData.coverageTest = true;
|
360 | Configuration.mainData.coverageTestThreshold =
|
361 | typeof configFile.coverageTest === 'string'
|
362 | ? parseInt(configFile.coverageTest, 10)
|
363 | : COMPODOC_DEFAULTS.defaultCoverageThreshold;
|
364 | }
|
365 | if (program.coverageTest) {
|
366 | Configuration.mainData.coverageTest = true;
|
367 | Configuration.mainData.coverageTestThreshold =
|
368 | typeof program.coverageTest === 'string'
|
369 | ? parseInt(program.coverageTest, 10)
|
370 | : COMPODOC_DEFAULTS.defaultCoverageThreshold;
|
371 | }
|
372 |
|
373 | if (configFile.coverageMinimumPerFile) {
|
374 | Configuration.mainData.coverageTestPerFile = true;
|
375 | Configuration.mainData.coverageMinimumPerFile =
|
376 | typeof configFile.coverageMinimumPerFile === 'string'
|
377 | ? parseInt(configFile.coverageMinimumPerFile, 10)
|
378 | : COMPODOC_DEFAULTS.defaultCoverageMinimumPerFile;
|
379 | }
|
380 | if (program.coverageMinimumPerFile) {
|
381 | Configuration.mainData.coverageTestPerFile = true;
|
382 | Configuration.mainData.coverageMinimumPerFile =
|
383 | typeof program.coverageMinimumPerFile === 'string'
|
384 | ? parseInt(program.coverageMinimumPerFile, 10)
|
385 | : COMPODOC_DEFAULTS.defaultCoverageMinimumPerFile;
|
386 | }
|
387 |
|
388 | if (configFile.coverageTestThresholdFail) {
|
389 | Configuration.mainData.coverageTestThresholdFail =
|
390 | configFile.coverageTestThresholdFail === 'false' ? false : true;
|
391 | }
|
392 | if (program.coverageTestThresholdFail) {
|
393 | Configuration.mainData.coverageTestThresholdFail =
|
394 | program.coverageTestThresholdFail === 'false' ? false : true;
|
395 | }
|
396 |
|
397 | if (configFile.coverageTestShowOnlyFailed) {
|
398 | Configuration.mainData.coverageTestShowOnlyFailed =
|
399 | configFile.coverageTestShowOnlyFailed;
|
400 | }
|
401 | if (program.coverageTestShowOnlyFailed) {
|
402 | Configuration.mainData.coverageTestShowOnlyFailed = program.coverageTestShowOnlyFailed;
|
403 | }
|
404 |
|
405 | if (configFile.unitTestCoverage) {
|
406 | Configuration.mainData.unitTestCoverage = configFile.unitTestCoverage;
|
407 | }
|
408 | if (program.unitTestCoverage) {
|
409 | Configuration.mainData.unitTestCoverage = program.unitTestCoverage;
|
410 | }
|
411 |
|
412 | if (configFile.disableSourceCode) {
|
413 | Configuration.mainData.disableSourceCode = configFile.disableSourceCode;
|
414 | }
|
415 | if (program.disableSourceCode) {
|
416 | Configuration.mainData.disableSourceCode = program.disableSourceCode;
|
417 | }
|
418 |
|
419 | if (configFile.disableDomTree) {
|
420 | Configuration.mainData.disableDomTree = configFile.disableDomTree;
|
421 | }
|
422 | if (program.disableDomTree) {
|
423 | Configuration.mainData.disableDomTree = program.disableDomTree;
|
424 | }
|
425 |
|
426 | if (configFile.disableTemplateTab) {
|
427 | Configuration.mainData.disableTemplateTab = configFile.disableTemplateTab;
|
428 | }
|
429 | if (program.disableTemplateTab) {
|
430 | Configuration.mainData.disableTemplateTab = program.disableTemplateTab;
|
431 | }
|
432 |
|
433 | if (configFile.disableStyleTab) {
|
434 | Configuration.mainData.disableStyleTab = configFile.disableStyleTab;
|
435 | }
|
436 | if (program.disableStyleTab) {
|
437 | Configuration.mainData.disableStyleTab = program.disableStyleTab;
|
438 | }
|
439 |
|
440 | if (configFile.disableGraph) {
|
441 | Configuration.mainData.disableGraph = configFile.disableGraph;
|
442 | }
|
443 | if (program.disableGraph) {
|
444 | Configuration.mainData.disableGraph = program.disableGraph;
|
445 | }
|
446 |
|
447 | if (configFile.disableCoverage) {
|
448 | Configuration.mainData.disableCoverage = configFile.disableCoverage;
|
449 | }
|
450 | if (program.disableCoverage) {
|
451 | Configuration.mainData.disableCoverage = program.disableCoverage;
|
452 | }
|
453 |
|
454 | if (configFile.disablePrivate) {
|
455 | Configuration.mainData.disablePrivate = configFile.disablePrivate;
|
456 | }
|
457 | if (program.disablePrivate) {
|
458 | Configuration.mainData.disablePrivate = program.disablePrivate;
|
459 | }
|
460 |
|
461 | if (configFile.disableProtected) {
|
462 | Configuration.mainData.disableProtected = configFile.disableProtected;
|
463 | }
|
464 | if (program.disableProtected) {
|
465 | Configuration.mainData.disableProtected = program.disableProtected;
|
466 | }
|
467 |
|
468 | if (configFile.disableInternal) {
|
469 | Configuration.mainData.disableInternal = configFile.disableInternal;
|
470 | }
|
471 | if (program.disableInternal) {
|
472 | Configuration.mainData.disableInternal = program.disableInternal;
|
473 | }
|
474 |
|
475 | if (configFile.disableLifeCycleHooks) {
|
476 | Configuration.mainData.disableLifeCycleHooks = configFile.disableLifeCycleHooks;
|
477 | }
|
478 | if (program.disableLifeCycleHooks) {
|
479 | Configuration.mainData.disableLifeCycleHooks = program.disableLifeCycleHooks;
|
480 | }
|
481 |
|
482 | if (configFile.disableRoutesGraph) {
|
483 | Configuration.mainData.disableRoutesGraph = configFile.disableRoutesGraph;
|
484 | }
|
485 | if (program.disableRoutesGraph) {
|
486 | Configuration.mainData.disableRoutesGraph = program.disableRoutesGraph;
|
487 | }
|
488 |
|
489 | if (configFile.disableSearch) {
|
490 | Configuration.mainData.disableSearch = configFile.disableSearch;
|
491 | }
|
492 | if (program.disableSearch) {
|
493 | Configuration.mainData.disableSearch = program.disableSearch;
|
494 | }
|
495 |
|
496 | if (configFile.disableDependencies) {
|
497 | Configuration.mainData.disableDependencies = configFile.disableDependencies;
|
498 | }
|
499 | if (program.disableDependencies) {
|
500 | Configuration.mainData.disableDependencies = program.disableDependencies;
|
501 | }
|
502 |
|
503 | if (configFile.minimal) {
|
504 | Configuration.mainData.disableSearch = true;
|
505 | Configuration.mainData.disableRoutesGraph = true;
|
506 | Configuration.mainData.disableGraph = true;
|
507 | Configuration.mainData.disableCoverage = true;
|
508 | }
|
509 | if (program.minimal) {
|
510 | Configuration.mainData.disableSearch = true;
|
511 | Configuration.mainData.disableRoutesGraph = true;
|
512 | Configuration.mainData.disableGraph = true;
|
513 | Configuration.mainData.disableCoverage = true;
|
514 | }
|
515 |
|
516 | if (configFile.customFavicon) {
|
517 | Configuration.mainData.customFavicon = configFile.customFavicon;
|
518 | }
|
519 | if (program.customFavicon) {
|
520 | Configuration.mainData.customFavicon = program.customFavicon;
|
521 | }
|
522 |
|
523 | if (configFile.customLogo) {
|
524 | Configuration.mainData.customLogo = configFile.customLogo;
|
525 | }
|
526 | if (program.customLogo) {
|
527 | Configuration.mainData.customLogo = program.customLogo;
|
528 | }
|
529 |
|
530 | if (configFile.gaID) {
|
531 | Configuration.mainData.gaID = configFile.gaID;
|
532 | }
|
533 | if (program.gaID) {
|
534 | Configuration.mainData.gaID = program.gaID;
|
535 | }
|
536 |
|
537 | if (configFile.gaSite) {
|
538 | Configuration.mainData.gaSite = configFile.gaSite;
|
539 | }
|
540 | if (program.gaSite && program.gaSite !== COMPODOC_DEFAULTS.gaSite) {
|
541 | Configuration.mainData.gaSite = program.gaSite;
|
542 | }
|
543 |
|
544 | if (!this.isWatching) {
|
545 | if (!logger.silent) {
|
546 | console.log(`Compodoc v${pkg.version}`);
|
547 | } else {
|
548 | console.log(fs.readFileSync(path.join(__dirname, '../src/banner')).toString());
|
549 | console.log(pkg.version);
|
550 | console.log('');
|
551 | console.log(`TypeScript version used by Compodoc : ${ts.version}`);
|
552 | console.log('');
|
553 |
|
554 | if (FileEngine.existsSync(cwd + path.sep + 'package.json')) {
|
555 | const packageData = FileEngine.getSync(cwd + path.sep + 'package.json');
|
556 | if (packageData) {
|
557 | const parsedData = JSON.parse(packageData);
|
558 | const projectDevDependencies = parsedData.devDependencies;
|
559 | if (projectDevDependencies && projectDevDependencies.typescript) {
|
560 | const tsProjectVersion = AngularVersionUtil.cleanVersion(
|
561 | projectDevDependencies.typescript
|
562 | );
|
563 | console.log(
|
564 | `TypeScript version of current project : ${tsProjectVersion}`
|
565 | );
|
566 | console.log('');
|
567 | }
|
568 | }
|
569 | }
|
570 | console.log(`Node.js version : ${process.version}`);
|
571 | console.log('');
|
572 | console.log(`Operating system : ${osName(os.platform(), os.release())}`);
|
573 | console.log('');
|
574 | }
|
575 | }
|
576 |
|
577 | if (configExplorerResult) {
|
578 | if (typeof configExplorerResult.config !== 'undefined') {
|
579 | logger.info(`Using configuration file : ${configExplorerResult.filepath}`);
|
580 | }
|
581 | }
|
582 |
|
583 | if (!configExplorerResult) {
|
584 | logger.warn(`No configuration file found, switching to CLI flags.`);
|
585 | }
|
586 |
|
587 | if (program.language && !I18nEngine.supportLanguage(program.language)) {
|
588 | logger.warn(
|
589 | `The language ${program.language} is not available, falling back to ${I18nEngine.fallbackLanguage}`
|
590 | );
|
591 | }
|
592 |
|
593 | if (program.tsconfig && typeof program.tsconfig === 'boolean') {
|
594 | logger.error(`Please provide a tsconfig file.`);
|
595 | process.exit(1);
|
596 | }
|
597 |
|
598 | if (configFile.tsconfig) {
|
599 | Configuration.mainData.tsconfig = configFile.tsconfig;
|
600 | }
|
601 | if (program.tsconfig) {
|
602 | Configuration.mainData.tsconfig = program.tsconfig;
|
603 | }
|
604 |
|
605 | if (program.maxSearchResults) {
|
606 | Configuration.mainData.maxSearchResults = program.maxSearchResults;
|
607 | }
|
608 |
|
609 | if (configFile.files) {
|
610 | scannedFiles = configFile.files;
|
611 | }
|
612 | if (configFile.exclude) {
|
613 | excludeFiles = configFile.exclude;
|
614 | }
|
615 | if (configFile.include) {
|
616 | includeFiles = configFile.include;
|
617 | }
|
618 |
|
619 | |
620 |
|
621 |
|
622 | const argv = require('minimist')(process.argv.slice(2));
|
623 | if (argv && argv.files) {
|
624 | Configuration.mainData.hasFilesToCoverage = true;
|
625 | if (typeof argv.files === 'string') {
|
626 | super.setFiles([argv.files]);
|
627 | } else {
|
628 | super.setFiles(argv.files);
|
629 | }
|
630 | }
|
631 |
|
632 | if (program.serve && !Configuration.mainData.tsconfig && program.output) {
|
633 |
|
634 | if (!FileEngine.existsSync(Configuration.mainData.output)) {
|
635 | logger.error(`${Configuration.mainData.output} folder doesn't exist`);
|
636 | process.exit(1);
|
637 | } else {
|
638 | logger.info(
|
639 | `Serving documentation from ${Configuration.mainData.output} at http://${Configuration.mainData.hostname}:${program.port}`
|
640 | );
|
641 | super.runWebServer(Configuration.mainData.output);
|
642 | }
|
643 | } else if (program.serve && !Configuration.mainData.tsconfig && !program.output) {
|
644 |
|
645 | if (!FileEngine.existsSync(Configuration.mainData.output)) {
|
646 | logger.error('Provide output generated folder with -d flag');
|
647 | process.exit(1);
|
648 | } else {
|
649 | logger.info(
|
650 | `Serving documentation from ${Configuration.mainData.output} at http://${Configuration.mainData.hostname}:${program.port}`
|
651 | );
|
652 | super.runWebServer(Configuration.mainData.output);
|
653 | }
|
654 | } else if (Configuration.mainData.hasFilesToCoverage) {
|
655 | if (program.coverageMinimumPerFile) {
|
656 | logger.info('Run documentation coverage test for files');
|
657 | super.testCoverage();
|
658 | } else {
|
659 | logger.error('Missing coverage configuration');
|
660 | }
|
661 | } else {
|
662 | if (program.hideGenerator) {
|
663 | Configuration.mainData.hideGenerator = true;
|
664 | }
|
665 |
|
666 | if (Configuration.mainData.tsconfig && program.args.length === 0) {
|
667 | |
668 |
|
669 |
|
670 | let testTsConfigPath = Configuration.mainData.tsconfig.indexOf(process.cwd());
|
671 | if (testTsConfigPath !== -1) {
|
672 | Configuration.mainData.tsconfig = Configuration.mainData.tsconfig.replace(
|
673 | process.cwd() + path.sep,
|
674 | ''
|
675 | );
|
676 | }
|
677 |
|
678 | if (!FileEngine.existsSync(Configuration.mainData.tsconfig)) {
|
679 | logger.error(
|
680 | `"${Configuration.mainData.tsconfig}" file was not found in the current directory`
|
681 | );
|
682 | process.exit(1);
|
683 | } else {
|
684 | let _file = path.join(
|
685 | path.join(process.cwd(), path.dirname(Configuration.mainData.tsconfig)),
|
686 | path.basename(Configuration.mainData.tsconfig)
|
687 | );
|
688 |
|
689 | cwd = _file
|
690 | .split(path.sep)
|
691 | .slice(0, -1)
|
692 | .join(path.sep);
|
693 | logger.info('Using tsconfig file ', _file);
|
694 |
|
695 | let tsConfigFile = readConfig(_file);
|
696 | scannedFiles = tsConfigFile.files;
|
697 | if (scannedFiles) {
|
698 | scannedFiles = handlePath(scannedFiles, cwd);
|
699 | }
|
700 |
|
701 | if (typeof scannedFiles === 'undefined') {
|
702 | excludeFiles = tsConfigFile.exclude || [];
|
703 | includeFiles = tsConfigFile.include || [];
|
704 | scannedFiles = [];
|
705 |
|
706 | let excludeParser = new ParserUtil(),
|
707 | includeParser = new ParserUtil();
|
708 |
|
709 | excludeParser.init(excludeFiles, cwd);
|
710 | includeParser.init(includeFiles, cwd);
|
711 |
|
712 | let startCwd = cwd;
|
713 |
|
714 | let excludeParserTestFilesWithCwdDepth = excludeParser.testFilesWithCwdDepth();
|
715 | if (!excludeParserTestFilesWithCwdDepth.status) {
|
716 | startCwd = excludeParser.updateCwd(
|
717 | cwd,
|
718 | excludeParserTestFilesWithCwdDepth.level
|
719 | );
|
720 | }
|
721 | let includeParserTestFilesWithCwdDepth = includeParser.testFilesWithCwdDepth();
|
722 | if (!includeParser.testFilesWithCwdDepth().status) {
|
723 | startCwd = includeParser.updateCwd(
|
724 | cwd,
|
725 | includeParserTestFilesWithCwdDepth.level
|
726 | );
|
727 | }
|
728 |
|
729 | let finder = require('findit2')(startCwd || '.');
|
730 |
|
731 | finder.on('directory', function(dir, stat, stop) {
|
732 | let base = path.basename(dir);
|
733 | if (base === '.git' || base === 'node_modules') {
|
734 | stop();
|
735 | }
|
736 | });
|
737 |
|
738 | finder.on('file', (file, stat) => {
|
739 | if (/(spec|\.d)\.ts/.test(file)) {
|
740 | logger.warn('Ignoring', file);
|
741 | } else if (
|
742 | excludeParser.testFile(file) &&
|
743 | path.extname(file) === '.ts'
|
744 | ) {
|
745 | logger.warn('Excluding', file);
|
746 | } else if (includeFiles.length > 0) {
|
747 | |
748 |
|
749 |
|
750 |
|
751 | if (path.extname(file) === '.ts' && includeParser.testFile(file)) {
|
752 | logger.debug('Including', file);
|
753 | scannedFiles.push(file);
|
754 | } else {
|
755 | if (path.extname(file) === '.ts') {
|
756 | logger.warn('Excluding', file);
|
757 | }
|
758 | }
|
759 | } else {
|
760 | logger.debug('Including', file);
|
761 | scannedFiles.push(file);
|
762 | }
|
763 | });
|
764 |
|
765 | finder.on('end', () => {
|
766 | super.setFiles(scannedFiles);
|
767 | if (program.coverageTest || program.coverageTestPerFile) {
|
768 | logger.info('Run documentation coverage test');
|
769 | super.testCoverage();
|
770 | } else {
|
771 | super.generate();
|
772 | }
|
773 | });
|
774 | } else {
|
775 | super.setFiles(scannedFiles);
|
776 | if (program.coverageTest || program.coverageTestPerFile) {
|
777 | logger.info('Run documentation coverage test');
|
778 | super.testCoverage();
|
779 | } else {
|
780 | super.generate();
|
781 | }
|
782 | }
|
783 | }
|
784 | } else if (Configuration.mainData.tsconfig && program.args.length > 0) {
|
785 | |
786 |
|
787 |
|
788 | let testTsConfigPath = Configuration.mainData.tsconfig.indexOf(process.cwd());
|
789 | if (testTsConfigPath !== -1) {
|
790 | Configuration.mainData.tsconfig = Configuration.mainData.tsconfig.replace(
|
791 | process.cwd() + path.sep,
|
792 | ''
|
793 | );
|
794 | }
|
795 |
|
796 | let sourceFolder = program.args[0];
|
797 | if (!FileEngine.existsSync(sourceFolder)) {
|
798 | logger.error(
|
799 | `Provided source folder ${sourceFolder} was not found in the current directory`
|
800 | );
|
801 | process.exit(1);
|
802 | } else {
|
803 | logger.info('Using provided source folder');
|
804 |
|
805 | if (!FileEngine.existsSync(Configuration.mainData.tsconfig)) {
|
806 | logger.error(
|
807 | `"${Configuration.mainData.tsconfig}" file was not found in the current directory`
|
808 | );
|
809 | process.exit(1);
|
810 | } else {
|
811 | let _file = path.join(
|
812 | path.join(process.cwd(), path.dirname(Configuration.mainData.tsconfig)),
|
813 | path.basename(Configuration.mainData.tsconfig)
|
814 | );
|
815 |
|
816 | cwd = _file
|
817 | .split(path.sep)
|
818 | .slice(0, -1)
|
819 | .join(path.sep);
|
820 | logger.info('Using tsconfig file ', _file);
|
821 |
|
822 | let tsConfigFile = readConfig(_file);
|
823 | scannedFiles = tsConfigFile.files;
|
824 | if (scannedFiles) {
|
825 | scannedFiles = handlePath(scannedFiles, cwd);
|
826 | }
|
827 |
|
828 | if (typeof scannedFiles === 'undefined') {
|
829 | excludeFiles = tsConfigFile.exclude || [];
|
830 | includeFiles = tsConfigFile.include || [];
|
831 | scannedFiles = [];
|
832 |
|
833 | let excludeParser = new ParserUtil(),
|
834 | includeParser = new ParserUtil();
|
835 |
|
836 | excludeParser.init(excludeFiles, cwd);
|
837 | includeParser.init(includeFiles, cwd);
|
838 |
|
839 | let startCwd = sourceFolder;
|
840 |
|
841 | let excludeParserTestFilesWithCwdDepth = excludeParser.testFilesWithCwdDepth();
|
842 | if (!excludeParserTestFilesWithCwdDepth.status) {
|
843 | startCwd = excludeParser.updateCwd(
|
844 | cwd,
|
845 | excludeParserTestFilesWithCwdDepth.level
|
846 | );
|
847 | }
|
848 | let includeParserTestFilesWithCwdDepth = includeParser.testFilesWithCwdDepth();
|
849 | if (!includeParser.testFilesWithCwdDepth().status) {
|
850 | startCwd = includeParser.updateCwd(
|
851 | cwd,
|
852 | includeParserTestFilesWithCwdDepth.level
|
853 | );
|
854 | }
|
855 |
|
856 | let finder = require('findit2')(path.resolve(startCwd));
|
857 |
|
858 | finder.on('directory', function(dir, stat, stop) {
|
859 | let base = path.basename(dir);
|
860 | if (base === '.git' || base === 'node_modules') {
|
861 | stop();
|
862 | }
|
863 | });
|
864 |
|
865 | finder.on('file', (file, stat) => {
|
866 | if (/(spec|\.d)\.ts/.test(file)) {
|
867 | logger.warn('Ignoring', file);
|
868 | } else if (excludeParser.testFile(file)) {
|
869 | logger.warn('Excluding', file);
|
870 | } else if (includeFiles.length > 0) {
|
871 | |
872 |
|
873 |
|
874 |
|
875 | if (
|
876 | path.extname(file) === '.ts' &&
|
877 | includeParser.testFile(file)
|
878 | ) {
|
879 | logger.debug('Including', file);
|
880 | scannedFiles.push(file);
|
881 | } else {
|
882 | if (path.extname(file) === '.ts') {
|
883 | logger.warn('Excluding', file);
|
884 | }
|
885 | }
|
886 | } else {
|
887 | logger.debug('Including', file);
|
888 | scannedFiles.push(file);
|
889 | }
|
890 | });
|
891 |
|
892 | finder.on('end', () => {
|
893 | super.setFiles(scannedFiles);
|
894 | if (program.coverageTest || program.coverageTestPerFile) {
|
895 | logger.info('Run documentation coverage test');
|
896 | super.testCoverage();
|
897 | } else {
|
898 | super.generate();
|
899 | }
|
900 | });
|
901 | } else {
|
902 | super.setFiles(scannedFiles);
|
903 | if (program.coverageTest || program.coverageTestPerFile) {
|
904 | logger.info('Run documentation coverage test');
|
905 | super.testCoverage();
|
906 | } else {
|
907 | super.generate();
|
908 | }
|
909 | }
|
910 | }
|
911 | }
|
912 | } else {
|
913 | logger.error('tsconfig.json file was not found, please use -p flag');
|
914 | outputHelp();
|
915 | }
|
916 | }
|
917 | }
|
918 | }
|