2017-07-21 17:27:53 +00:00
|
|
|
#!/usr/bin/env node
|
2017-07-28 08:09:26 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-07-21 17:27:53 +00:00
|
|
|
|
2017-08-15 01:08:06 +00:00
|
|
|
const puppeteer = require('../..');
|
2017-07-21 17:27:53 +00:00
|
|
|
const path = require('path');
|
2017-07-31 04:49:04 +00:00
|
|
|
const SourceFactory = require('./SourceFactory');
|
2017-07-21 17:27:53 +00:00
|
|
|
|
|
|
|
const PROJECT_DIR = path.join(__dirname, '..', '..');
|
|
|
|
|
|
|
|
const RED_COLOR = '\x1b[31m';
|
|
|
|
const YELLOW_COLOR = '\x1b[33m';
|
|
|
|
const RESET_COLOR = '\x1b[0m';
|
|
|
|
|
2017-07-31 04:49:04 +00:00
|
|
|
run();
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
|
|
const sourceFactory = new SourceFactory();
|
|
|
|
/** @type {!Array<!Message>} */
|
|
|
|
const messages = [];
|
|
|
|
|
|
|
|
// Documentation checks.
|
|
|
|
{
|
|
|
|
const mdSources = await sourceFactory.readdir(path.join(PROJECT_DIR, 'docs'), '.md');
|
2017-07-31 08:14:19 +00:00
|
|
|
|
2017-07-31 04:49:04 +00:00
|
|
|
const toc = require('./toc');
|
|
|
|
messages.push(...await toc(mdSources));
|
|
|
|
|
2017-07-31 08:14:19 +00:00
|
|
|
const preprocessor = require('./preprocessor');
|
|
|
|
messages.push(...await preprocessor(mdSources));
|
|
|
|
|
2017-08-15 01:08:06 +00:00
|
|
|
const browser = await puppeteer.launch({args: ['--no-sandbox']});
|
2017-07-31 04:49:04 +00:00
|
|
|
const page = await browser.newPage();
|
|
|
|
const checkPublicAPI = require('./check_public_api');
|
2017-07-31 08:14:19 +00:00
|
|
|
const jsSources = await sourceFactory.readdir(path.join(PROJECT_DIR, 'lib'), '.js');
|
2017-07-31 04:49:04 +00:00
|
|
|
messages.push(...await checkPublicAPI(page, mdSources, jsSources));
|
|
|
|
await browser.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report results.
|
|
|
|
const errors = messages.filter(message => message.type === 'error');
|
2017-07-21 17:27:53 +00:00
|
|
|
if (errors.length) {
|
2017-07-31 04:49:04 +00:00
|
|
|
console.log('DocLint Failures:');
|
2017-07-21 17:27:53 +00:00
|
|
|
for (let i = 0; i < errors.length; ++i) {
|
2017-07-31 04:49:04 +00:00
|
|
|
let error = errors[i].text;
|
2017-07-21 17:27:53 +00:00
|
|
|
error = error.split('\n').join('\n ');
|
|
|
|
console.log(` ${i + 1}) ${RED_COLOR}${error}${RESET_COLOR}`);
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 04:49:04 +00:00
|
|
|
const warnings = messages.filter(message => message.type === 'warning');
|
2017-07-21 17:27:53 +00:00
|
|
|
if (warnings.length) {
|
2017-07-31 04:49:04 +00:00
|
|
|
console.log('DocLint Warnings:');
|
2017-07-21 17:27:53 +00:00
|
|
|
for (let i = 0; i < warnings.length; ++i) {
|
2017-07-31 04:49:04 +00:00
|
|
|
let warning = warnings[i].text;
|
2017-07-21 17:27:53 +00:00
|
|
|
warning = warning.split('\n').join('\n ');
|
|
|
|
console.log(` ${i + 1}) ${YELLOW_COLOR}${warning}${RESET_COLOR}`);
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 08:14:19 +00:00
|
|
|
let clearExit = messages.length === 0;
|
|
|
|
if (await sourceFactory.saveChangedSources()) {
|
|
|
|
if (clearExit)
|
|
|
|
console.log(`${YELLOW_COLOR}Some files were updated.${RESET_COLOR}`);
|
|
|
|
clearExit = false;
|
|
|
|
}
|
2017-07-21 17:27:53 +00:00
|
|
|
console.log(`${errors.length} failures, ${warnings.length} warnings.`);
|
|
|
|
const runningTime = Date.now() - startTime;
|
2017-07-31 04:49:04 +00:00
|
|
|
console.log(`DocLint Finished in ${runningTime / 1000} seconds`);
|
2017-07-31 08:14:19 +00:00
|
|
|
process.exit(clearExit ? 0 : 1);
|
2017-07-21 17:27:53 +00:00
|
|
|
}
|