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