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
|
|
|
|
2022-02-09 14:49:25 +00:00
|
|
|
// eslint-disable-next-line import/extensions
|
2017-08-15 01:08:06 +00:00
|
|
|
const puppeteer = require('../..');
|
2017-07-21 17:27:53 +00:00
|
|
|
const path = require('path');
|
2022-02-09 14:49:25 +00:00
|
|
|
const Source = require('./Source.js');
|
2017-07-21 17:27:53 +00:00
|
|
|
|
|
|
|
const PROJECT_DIR = path.join(__dirname, '..', '..');
|
2018-04-26 00:11:45 +00:00
|
|
|
const VERSION = require(path.join(PROJECT_DIR, 'package.json')).version;
|
2017-07-21 17:27:53 +00:00
|
|
|
|
|
|
|
const RED_COLOR = '\x1b[31m';
|
2022-05-20 05:13:06 +00:00
|
|
|
const BLUE_COLOR = '\x1b[34m';
|
2017-07-21 17:27:53 +00:00
|
|
|
const YELLOW_COLOR = '\x1b[33m';
|
|
|
|
const RESET_COLOR = '\x1b[0m';
|
|
|
|
|
2020-11-26 10:38:24 +00:00
|
|
|
const IS_RELEASE = Boolean(process.env.IS_RELEASE);
|
|
|
|
|
2017-07-31 04:49:04 +00:00
|
|
|
run();
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
|
|
/** @type {!Array<!Message>} */
|
|
|
|
const messages = [];
|
2018-04-26 01:07:20 +00:00
|
|
|
let changedFiles = false;
|
2017-07-31 04:49:04 +00:00
|
|
|
|
2022-05-31 13:38:20 +00:00
|
|
|
if (IS_RELEASE) {
|
2022-01-28 12:01:12 +00:00
|
|
|
const versions = await Source.readFile(
|
2020-10-29 21:24:35 +00:00
|
|
|
path.join(PROJECT_DIR, 'versions.js')
|
|
|
|
);
|
2021-02-02 12:32:13 +00:00
|
|
|
versions.setText(
|
|
|
|
versions.text().replace(`, 'NEXT'],`, `, 'v${VERSION}'],`)
|
|
|
|
);
|
2020-10-29 21:24:35 +00:00
|
|
|
await versions.save();
|
|
|
|
}
|
|
|
|
|
2017-07-31 04:49:04 +00:00
|
|
|
// Documentation checks.
|
2020-04-14 09:55:29 +00:00
|
|
|
const readme = await Source.readFile(path.join(PROJECT_DIR, 'README.md'));
|
2020-05-07 10:54:55 +00:00
|
|
|
const contributing = await Source.readFile(
|
|
|
|
path.join(PROJECT_DIR, 'CONTRIBUTING.md')
|
|
|
|
);
|
2020-04-14 09:55:29 +00:00
|
|
|
const api = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'api.md'));
|
2020-05-07 10:54:55 +00:00
|
|
|
const troubleshooting = await Source.readFile(
|
|
|
|
path.join(PROJECT_DIR, 'docs', 'troubleshooting.md')
|
|
|
|
);
|
2020-04-14 09:55:29 +00:00
|
|
|
const mdSources = [readme, api, troubleshooting, contributing];
|
2017-07-31 08:14:19 +00:00
|
|
|
|
2022-02-09 14:49:25 +00:00
|
|
|
const preprocessor = require('./preprocessor/index.js');
|
2020-05-07 10:54:55 +00:00
|
|
|
messages.push(
|
2022-05-30 19:50:34 +00:00
|
|
|
...(await preprocessor.runCommands(mdSources, VERSION, IS_RELEASE))
|
|
|
|
);
|
|
|
|
messages.push(
|
|
|
|
...(await preprocessor.ensureReleasedAPILinks(
|
|
|
|
[readme],
|
|
|
|
VERSION,
|
|
|
|
IS_RELEASE
|
|
|
|
))
|
2020-05-07 10:54:55 +00:00
|
|
|
);
|
2017-07-31 08:14:19 +00:00
|
|
|
|
2020-04-14 09:55:29 +00:00
|
|
|
const browser = await puppeteer.launch();
|
|
|
|
const page = await browser.newPage();
|
2022-02-09 14:49:25 +00:00
|
|
|
const checkPublicAPI = require('./check_public_api/index.js');
|
2020-05-12 15:30:13 +00:00
|
|
|
const tsSources = [
|
|
|
|
/* Source.readdir doesn't deal with nested directories well.
|
|
|
|
* Rather than invest time here when we're going to remove this Doc tooling soon
|
|
|
|
* we'll just list the directories manually.
|
|
|
|
*/
|
|
|
|
...(await Source.readdir(path.join(PROJECT_DIR, 'src'), 'ts')),
|
2020-06-18 14:53:23 +00:00
|
|
|
...(await Source.readdir(path.join(PROJECT_DIR, 'src', 'common'), 'ts')),
|
2020-06-18 12:49:59 +00:00
|
|
|
...(await Source.readdir(path.join(PROJECT_DIR, 'src', 'node'), 'ts')),
|
2020-05-12 15:30:13 +00:00
|
|
|
];
|
2020-04-16 13:59:28 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
const tsSourcesNoDefinitions = tsSources.filter(
|
|
|
|
(source) => !source.filePath().endsWith('.d.ts')
|
|
|
|
);
|
2020-04-16 13:59:28 +00:00
|
|
|
|
2020-06-18 14:53:23 +00:00
|
|
|
const jsSources = [
|
|
|
|
...(await Source.readdir(path.join(PROJECT_DIR, 'lib'))),
|
2020-06-25 13:24:46 +00:00
|
|
|
...(await Source.readdir(path.join(PROJECT_DIR, 'lib', 'cjs'))),
|
2020-07-14 15:57:29 +00:00
|
|
|
...(await Source.readdir(
|
|
|
|
path.join(PROJECT_DIR, 'lib', 'cjs', 'puppeteer', 'common')
|
|
|
|
)),
|
|
|
|
...(await Source.readdir(
|
|
|
|
path.join(PROJECT_DIR, 'lib', 'cjs', 'puppeteer', 'node')
|
|
|
|
)),
|
2020-06-18 14:53:23 +00:00
|
|
|
];
|
2020-04-16 13:59:28 +00:00
|
|
|
const allSrcCode = [...jsSources, ...tsSourcesNoDefinitions];
|
2020-05-07 10:54:55 +00:00
|
|
|
messages.push(...(await checkPublicAPI(page, mdSources, allSrcCode)));
|
2018-11-21 22:49:08 +00:00
|
|
|
|
2020-04-14 09:55:29 +00:00
|
|
|
await browser.close();
|
2018-04-26 01:07:20 +00:00
|
|
|
|
2020-04-14 09:55:29 +00:00
|
|
|
for (const source of mdSources) {
|
2020-05-07 10:54:55 +00:00
|
|
|
if (!source.hasUpdatedText()) continue;
|
2020-04-14 09:55:29 +00:00
|
|
|
await source.save();
|
|
|
|
changedFiles = true;
|
2017-07-31 04:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Report results.
|
2020-05-07 10:54:55 +00:00
|
|
|
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) {
|
2022-05-20 05:13:06 +00:00
|
|
|
const text = errors[i].text.split('\n').join('\n ');
|
|
|
|
console.log(` ${i + 1}) ${RED_COLOR}${text}${RESET_COLOR}`);
|
2017-07-21 17:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-07 10:54:55 +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) {
|
2022-05-20 05:13:06 +00:00
|
|
|
const text = warnings[i].text.split('\n').join('\n ');
|
|
|
|
console.log(` ${i + 1}) ${YELLOW_COLOR}${text}${RESET_COLOR}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const info = messages.filter((message) => message.type === 'info');
|
|
|
|
if (info.length) {
|
|
|
|
console.log('DocLint Info:');
|
|
|
|
for (let i = 0; i < info.length; i++) {
|
|
|
|
const text = info[i].text.split('\n').join('\n ');
|
|
|
|
console.log(` ${i + 1}) ${BLUE_COLOR}${text}${RESET_COLOR}`);
|
2017-07-21 17:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-26 01:07:20 +00:00
|
|
|
if (changedFiles) {
|
2022-05-20 05:13:06 +00:00
|
|
|
console.log(`${BLUE_COLOR}Some files were updated.${RESET_COLOR}`);
|
2017-07-31 08:14:19 +00:00
|
|
|
}
|
2020-04-16 13:40:04 +00:00
|
|
|
|
2022-05-20 05:13:06 +00:00
|
|
|
console.log(
|
|
|
|
`${info.length} info, ${errors.length} failures, ${warnings.length} warnings.`
|
|
|
|
);
|
|
|
|
|
|
|
|
const clearExit = errors.length + warnings.length === 0;
|
|
|
|
if (!clearExit && !process.env.GITHUB_ACTIONS) {
|
2020-05-07 10:54:55 +00:00
|
|
|
console.log(
|
2022-06-10 09:55:53 +00:00
|
|
|
'\nIs your lib/ directory up to date? You might need to `npm run build:tsc`.\n'
|
2020-05-07 10:54:55 +00:00
|
|
|
);
|
2022-05-20 05:13:06 +00:00
|
|
|
}
|
2020-04-16 13:40:04 +00:00
|
|
|
|
2017-07-21 17:27:53 +00:00
|
|
|
const runningTime = Date.now() - startTime;
|
2017-07-31 04:49:04 +00:00
|
|
|
console.log(`DocLint Finished in ${runningTime / 1000} seconds`);
|
2020-11-26 10:38:24 +00:00
|
|
|
process.exit(clearExit || IS_RELEASE ? 0 : 1);
|
2017-07-21 17:27:53 +00:00
|
|
|
}
|