Skip to content

Commit

Permalink
chore: simplify and remove some scripts (#4838)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Dec 29, 2020
1 parent 068d861 commit a1232b6
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 165 deletions.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
"tsc": "tsc -p .",
"tsc-installer": "tsc -p ./src/install/tsconfig.json",
"doc": "node utils/doclint/cli.js",
"test-infra": "folio utils/doclint/check_public_api/test/testMissingDocs.js && folio utils/doclint/preprocessor/test.js",
"lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && npm run generate-channels && node utils/generate_types/ --check-clean && npm run test-types && npm run test-infra",
"clean": "rimraf lib && rimraf types",
"lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && npm run generate-channels && node utils/generate_types/ --check-clean && npm run test-types && folio utils/doclint/test/",
"clean": "rimraf lib",
"prepare": "node install-from-github.js",
"build": "node utils/runWebpack.js --mode='development' && tsc -p . && npm run generate-api-json",
"watch": "node utils/watch.js",
"test-types": "node utils/generate_types/ && npx -p [email protected] tsc -p utils/generate_types/test/tsconfig.json && npm run typecheck-tests",
"test-types": "node utils/generate_types/ && npx -p [email protected] tsc -p utils/generate_types/test/tsconfig.json && tsc -p ./test/",
"generate-channels": "node utils/generate_channels.js",
"generate-api-json": "node utils/doclint/generateApiJson.js > docs/api.json",
"typecheck-tests": "tsc -p ./test/",
"roll-browser": "node utils/roll_browser.js",
"coverage": "node test/checkCoverage.js",
"check-deps": "node utils/check_deps.js",
Expand Down
1 change: 0 additions & 1 deletion utils/doclint/.gitignore

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// @ts-check

const { parseArgument, renderMd, clone } = require('../../parse_md');
const { parseArgument, renderMd, clone } = require('../parse_md');
const Documentation = require('./Documentation');

/** @typedef {import('./Documentation').MarkdownNode} MarkdownNode */
Expand Down Expand Up @@ -159,7 +159,7 @@ function patchSignatures(spec, signatures) {
}

/**
* @param {string} text
* @param {string} text
* @returns {string}
*/
function createLink(text) {
Expand Down
44 changes: 0 additions & 44 deletions utils/doclint/Message.js

This file was deleted.

30 changes: 0 additions & 30 deletions utils/doclint/README.md

This file was deleted.

39 changes: 13 additions & 26 deletions utils/doclint/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ const playwright = require('../../');
const fs = require('fs');
const path = require('path');
const Source = require('./Source');
const Message = require('./Message');
const { parseMd, renderMd, applyTemplates, clone } = require('./../parse_md');
const { spawnSync } = require('child_process');
const preprocessor = require('./preprocessor');
const mdBuilder = require('./check_public_api/MDBuilder');
const mdBuilder = require('./MDBuilder');

/** @typedef {import('./check_public_api/Documentation').MarkdownNode} MarkdownNode */
/** @typedef {import('./check_public_api/Documentation').Type} Type */
/** @typedef {import('./Documentation').MarkdownNode} MarkdownNode */
/** @typedef {import('./Documentation').Type} Type */

const PROJECT_DIR = path.join(__dirname, '..', '..');
const VERSION = require(path.join(PROJECT_DIR, 'package.json')).version;
Expand All @@ -52,8 +51,8 @@ async function run() {
const docs = await Source.readdir(path.join(PROJECT_DIR, 'docs'), '.md');
const mdSources = [readme, binReadme, api, contributing, ...docs];

/** @type {!Array<!Message>} */
const messages = [];
/** @type {!Array<string>} */
const errors = [];
let changedFiles = false;

const header = fs.readFileSync(path.join(PROJECT_DIR, 'docs-src', 'api-header.md')).toString();
Expand Down Expand Up @@ -128,20 +127,20 @@ async function run() {
// Documentation checks.
{
const browserVersions = await getBrowserVersions();
messages.push(...(await preprocessor.runCommands(mdSources, {
errors.push(...(await preprocessor.runCommands(mdSources, {
libversion: VERSION,
chromiumVersion: browserVersions.chromium,
firefoxVersion: browserVersions.firefox,
webkitVersion: browserVersions.webkit,
})));

messages.push(...preprocessor.autocorrectInvalidLinks(PROJECT_DIR, mdSources, getRepositoryFiles()));
errors.push(...preprocessor.autocorrectInvalidLinks(PROJECT_DIR, mdSources, getRepositoryFiles()));
for (const source of mdSources.filter(source => source.hasUpdatedText()))
messages.push(Message.warning(`WARN: updated ${source.projectPath()}`));
errors.push(`WARN: updated ${source.projectPath()}`);

const jsSources = await Source.readdir(path.join(PROJECT_DIR, 'src', 'client'), '', []);
const missingDocs = require('./check_public_api/missingDocs.js');
messages.push(...missingDocs(apiSpec, jsSources, path.join(PROJECT_DIR, 'src', 'client', 'api.ts')));
const missingDocs = require('./missingDocs.js');
errors.push(...missingDocs(apiSpec, jsSources, path.join(PROJECT_DIR, 'src', 'client', 'api.ts')));

for (const source of mdSources) {
if (!source.hasUpdatedText())
Expand All @@ -152,31 +151,19 @@ async function run() {
}

// Report results.
const errors = messages.filter(message => message.type === 'error');
if (errors.length) {
console.log('DocLint Failures:');
for (let i = 0; i < errors.length; ++i) {
let error = errors[i].text;
error = error.split('\n').join('\n ');
const error = errors[i].split('\n').join('\n ');
console.log(` ${i + 1}) ${RED_COLOR}${error}${RESET_COLOR}`);
}
}
const warnings = messages.filter(message => message.type === 'warning');
if (warnings.length) {
console.log('DocLint Warnings:');
for (let i = 0; i < warnings.length; ++i) {
let warning = warnings[i].text;
warning = warning.split('\n').join('\n ');
console.log(` ${i + 1}) ${YELLOW_COLOR}${warning}${RESET_COLOR}`);
}
}
let clearExit = messages.length === 0;
let clearExit = errors.length === 0;
if (changedFiles) {
if (clearExit)
console.log(`${YELLOW_COLOR}Some files were updated.${RESET_COLOR}`);
clearExit = false;
}
console.log(`${errors.length} failures, ${warnings.length} warnings.`);
console.log(`${errors.length} failures.`);
const runningTime = Date.now() - startTime;
console.log(`DocLint Finished in ${runningTime / 1000} seconds`);
process.exit(clearExit ? 0 : 1);
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/generateApiJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
const fs = require('fs');
const path = require('path');
const { parseMd, applyTemplates } = require('../parse_md');
const mdBuilder = require('./check_public_api/MDBuilder');
const mdBuilder = require('./MDBuilder');
const PROJECT_DIR = path.join(__dirname, '..', '..');

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/

const mdBuilder = require('./MDBuilder');
const Message = require('../Message');
const ts = require('typescript');
const EventEmitter = require('events');
const Documentation = require('./Documentation');

/**
* @return {!Array<!Message>}
* @return {!Array<string>}
*/
module.exports = function lint(api, jsSources, apiFileName) {
const documentation = mdBuilder(api, true).documentation;
Expand All @@ -31,40 +30,40 @@ module.exports = function lint(api, jsSources, apiFileName) {
for (const [className, methods] of apiMethods) {
const docClass = documentation.classes.get(className);
if (!docClass) {
errors.push(Message.error(`Missing documentation for "${className}"`));
errors.push(`Missing documentation for "${className}"`);
continue;
}
for (const [methodName, params] of methods) {
const member = docClass.members.get(methodName);
if (!member) {
errors.push(Message.error(`Missing documentation for "${className}.${methodName}"`));
errors.push(`Missing documentation for "${className}.${methodName}"`);
continue;
}
const memberParams = paramsForMember(member);
for (const paramName of params) {
if (!memberParams.has(paramName))
errors.push(Message.error(`Missing documentation for "${className}.${methodName}.${paramName}"`));
errors.push(`Missing documentation for "${className}.${methodName}.${paramName}"`);
}
}
}
for (const cls of documentation.classesArray) {
const methods = apiMethods.get(cls.name);
if (!methods) {
errors.push(Message.error(`Documented "${cls.name}" not found in sources`));
errors.push(`Documented "${cls.name}" not found in sources`);
continue;
}
for (const member of cls.membersArray) {
if (member.kind === 'event')
continue;
const params = methods.get(member.name);
if (!params) {
errors.push(Message.error(`Documented "${cls.name}.${member.name}" not found is sources`));
errors.push(`Documented "${cls.name}.${member.name}" not found is sources`);
continue;
}
const memberParams = paramsForMember(member);
for (const paramName of memberParams) {
if (!params.has(paramName))
errors.push(Message.error(`Documented "${cls.name}.${member.name}.${paramName}" not found is sources`));
errors.push(`Documented "${cls.name}.${member.name}.${paramName}" not found is sources`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/

const path = require('path');
const Message = require('../Message');

function runCommands(sources, {libversion, chromiumVersion, firefoxVersion, webkitVersion}) {
// Release version is everything that doesn't include "-".
const isReleaseVersion = !libversion.includes('-');

const messages = [];
const errors = [];
for (const source of sources) {
const text = source.text();
const commandStartRegex = /<!--\s*gen:([a-z-]+)\s*-->/ig;
Expand All @@ -34,8 +33,8 @@ function runCommands(sources, {libversion, chromiumVersion, firefoxVersion, webk
commandEndRegex.lastIndex = commandStartRegex.lastIndex;
const end = commandEndRegex.exec(text);
if (!end) {
messages.push(Message.error(`Failed to find 'gen:stop' for command ${start[0]}`));
return messages;
errors.push(`Failed to find 'gen:stop' for command ${start[0]}`);
return errors;
}
const commandName = start[1];
const from = commandStartRegex.lastIndex;
Expand Down Expand Up @@ -63,13 +62,13 @@ function runCommands(sources, {libversion, chromiumVersion, firefoxVersion, webk
newText = generateTableOfContentsForSuperclass(source.text(), 'class: ' + commandName.substring('toc-extends-'.length));

if (newText === null)
messages.push(Message.error(`Unknown command 'gen:${commandName}'`));
errors.push(`Unknown command 'gen:${commandName}'`);
else
sourceEdits.edit(from, to, newText);
}
sourceEdits.commit(messages);
sourceEdits.commit(errors);
}
return messages;
return errors;
};

function getTOCEntriesForText(text) {
Expand Down Expand Up @@ -117,7 +116,7 @@ function autocorrectInvalidLinks(projectRoot, sources, allowedFilePaths) {
pathToHashLinks.set(source.filePath(), hashLinks);
}

const messages = [];
const errors = [];
for (const source of sources) {
const allRelativePaths = [];
for (const filepath of allowedFilePaths) {
Expand Down Expand Up @@ -146,7 +145,7 @@ function autocorrectInvalidLinks(projectRoot, sources, allowedFilePaths) {
// Attempt to autocorrect
const newRelativePath = autocorrectText(relativePath, allRelativePaths);
if (!newRelativePath) {
messages.push(Message.error(`Bad link in ${source.projectPath()}:${lineNumber + 1}: file ${relativePath} does not exist`));
errors.push(`Bad link in ${source.projectPath()}:${lineNumber + 1}: file ${relativePath} does not exist`);
continue;
}
resolvedPath = resolveLinkPath(source, newRelativePath);
Expand All @@ -161,15 +160,15 @@ function autocorrectInvalidLinks(projectRoot, sources, allowedFilePaths) {
if (newHashLink) {
sourceEdits.edit(hashOffset, hashOffset + hash.length, newHashLink);
} else {
messages.push(Message.error(`Bad link in ${source.projectPath()}:${lineNumber + 1}: hash "#${hash}" does not exist in "${path.relative(projectRoot, resolvedPath)}"`));
errors.push(`Bad link in ${source.projectPath()}:${lineNumber + 1}: hash "#${hash}" does not exist in "${path.relative(projectRoot, resolvedPath)}"`);
}
}
offset += line.length;
});

sourceEdits.commit(messages);
sourceEdits.commit(errors);
}
return messages;
return errors;

function resolveLinkPath(source, relativePath) {
if (!relativePath)
Expand All @@ -190,19 +189,19 @@ class SourceEdits {
this._edits.push({from, to, newText});
}

commit(messages = []) {
commit(errors = []) {
if (!this._edits.length)
return;
this._edits.sort((a, b) => a.from - b.from);
for (const edit of this._edits) {
if (edit.from > edit.to) {
messages.push(Message.error('INTERNAL ERROR: incorrect edit!'));
errors.push('INTERNAL ERROR: incorrect edit!');
return;
}
}
for (let i = 0; i < this._edits.length - 1; ++i) {
if (this._edits[i].to > this._edits[i + 1].from) {
messages.push(Message.error('INTERNAL ERROR: edits are overlapping!'));
errors.push('INTERNAL ERROR: edits are overlapping!');
return;
}
}
Expand Down
Loading

0 comments on commit a1232b6

Please sign in to comment.