1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | const puppeteer = require('../..');
|
19 | const path = require('path');
|
20 | const SourceFactory = require('./SourceFactory');
|
21 |
|
22 | const PROJECT_DIR = path.join(__dirname, '..', '..');
|
23 |
|
24 | const RED_COLOR = '\x1b[31m';
|
25 | const YELLOW_COLOR = '\x1b[33m';
|
26 | const RESET_COLOR = '\x1b[0m';
|
27 |
|
28 | run();
|
29 |
|
30 | async function run() {
|
31 | const startTime = Date.now();
|
32 |
|
33 | const sourceFactory = new SourceFactory();
|
34 |
|
35 | const messages = [];
|
36 |
|
37 |
|
38 | {
|
39 | const apiSource = await sourceFactory.readFile(path.join(PROJECT_DIR, 'docs', 'api.md'));
|
40 | const mdSources = [apiSource];
|
41 |
|
42 | const toc = require('./toc');
|
43 | messages.push(...await toc(mdSources));
|
44 |
|
45 | const preprocessor = require('./preprocessor');
|
46 | messages.push(...await preprocessor(mdSources));
|
47 |
|
48 | const browser = await puppeteer.launch({args: ['--no-sandbox']});
|
49 | const page = await browser.newPage();
|
50 | const checkPublicAPI = require('./check_public_api');
|
51 | const jsSources = await sourceFactory.readdir(path.join(PROJECT_DIR, 'lib'), '.js');
|
52 | messages.push(...await checkPublicAPI(page, mdSources, jsSources));
|
53 | await browser.close();
|
54 | }
|
55 |
|
56 |
|
57 | const errors = messages.filter(message => message.type === 'error');
|
58 | if (errors.length) {
|
59 | console.log('DocLint Failures:');
|
60 | for (let i = 0; i < errors.length; ++i) {
|
61 | let error = errors[i].text;
|
62 | error = error.split('\n').join('\n ');
|
63 | console.log(` ${i + 1}) ${RED_COLOR}${error}${RESET_COLOR}`);
|
64 | }
|
65 | }
|
66 | const warnings = messages.filter(message => message.type === 'warning');
|
67 | if (warnings.length) {
|
68 | console.log('DocLint Warnings:');
|
69 | for (let i = 0; i < warnings.length; ++i) {
|
70 | let warning = warnings[i].text;
|
71 | warning = warning.split('\n').join('\n ');
|
72 | console.log(` ${i + 1}) ${YELLOW_COLOR}${warning}${RESET_COLOR}`);
|
73 | }
|
74 | }
|
75 | let clearExit = messages.length === 0;
|
76 | if (await sourceFactory.saveChangedSources()) {
|
77 | if (clearExit)
|
78 | console.log(`${YELLOW_COLOR}Some files were updated.${RESET_COLOR}`);
|
79 | clearExit = false;
|
80 | }
|
81 | console.log(`${errors.length} failures, ${warnings.length} warnings.`);
|
82 | const runningTime = Date.now() - startTime;
|
83 | console.log(`DocLint Finished in ${runningTime / 1000} seconds`);
|
84 | process.exit(clearExit ? 0 : 1);
|
85 | }
|