6.7.0 - Alpha6 - Scrapers 工具打印日志内容兼容窗口宽度不足的情况

This commit is contained in:
SuperMonster003
2025-10-03 16:15:21 +08:00
parent 9b06086a55
commit 9dd55a063d
7 changed files with 217 additions and 45 deletions

161
.utils/package-lock.json generated
View File

@@ -9,7 +9,9 @@
"domhandler": "^5.0.3",
"dotenv": "^17.2.2",
"node-fetch": "^3.3.2",
"puppeteer": "^24.17.1"
"puppeteer": "^24.17.1",
"string-width": "^8.1.0",
"strip-ansi": "^7.1.2"
},
"devDependencies": {
"@octokit/types": "^14.1.0"
@@ -112,12 +114,15 @@
}
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"version": "6.2.2",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz",
"integrity": "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==",
"license": "MIT",
"engines": {
"node": ">=8"
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
}
},
"node_modules/ansi-styles": {
@@ -333,6 +338,41 @@
"node": ">=12"
}
},
"node_modules/cliui/node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/cliui/node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/cliui/node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@@ -716,6 +756,18 @@
"node": "6.* || 8.* || >= 10.*"
}
},
"node_modules/get-east-asian-width": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.4.0.tgz",
"integrity": "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/get-stream": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
@@ -1285,29 +1337,34 @@
}
},
"node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-8.1.0.tgz",
"integrity": "sha512-Kxl3KJGb/gxkaUMOjRsQ8IrXiGW75O4E3RPjFIINOVH8AMl2SQ/yWdTzWwF3FevIX9LcMAjJW+GRwAlAbTSXdg==",
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
"get-east-asian-width": "^1.3.0",
"strip-ansi": "^7.1.0"
},
"engines": {
"node": ">=8"
"node": ">=20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.2.tgz",
"integrity": "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
"ansi-regex": "^6.0.1"
},
"engines": {
"node": ">=8"
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
}
},
"node_modules/tar-fs": {
@@ -1419,6 +1476,41 @@
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
}
},
"node_modules/wrap-ansi/node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/wrap-ansi/node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/wrap-ansi/node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
@@ -1482,6 +1574,41 @@
"node": ">=12"
}
},
"node_modules/yargs/node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/yargs/node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/yargs/node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/yauzl": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",

View File

@@ -2,10 +2,12 @@
"type": "module",
"dependencies": {
"cheerio": "^1.1.2",
"domhandler": "^5.0.3",
"dotenv": "^17.2.2",
"node-fetch": "^3.3.2",
"puppeteer": "^24.17.1",
"domhandler": "^5.0.3",
"dotenv": "^17.2.2"
"string-width": "^8.1.0",
"strip-ansi": "^7.1.2"
},
"devDependencies": {
"@octokit/types": "^14.1.0"

View File

@@ -3,14 +3,29 @@
node "run-scrapers.mjs"
ECHO.
ECHO Press [R] to rerun the scrapers, or [ESC]/[Enter]/[Space] to exit...
powershell -NoLogo -NoProfile -Command "$ErrorActionPreference='Stop'; while($true){ $k=$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); if($k.VirtualKeyCode -eq 27 -or $k.VirtualKeyCode -eq 13 -or $k.Character -eq ' '){ exit 1 } elseif($k.Character -match '^[Rr]$'){ exit 0 } }"
ECHO Press [R] to rerun, [Shift+R] to clear screen then rerun, or [ESC]/[Enter]/[Space] to exit...
powershell -NoLogo -NoProfile -Command ^
"$ErrorActionPreference='Stop';" ^
"while($true){" ^
" $k=$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');" ^
" if($k.VirtualKeyCode -eq 27 -or $k.VirtualKeyCode -eq 13 -or $k.Character -eq ' '){ exit 1 }" ^
" elseif($k.VirtualKeyCode -eq 82){" ^
" $isShift = ($k.ControlKeyState -band 0x0010) -ne 0 -or ($k.ControlKeyState -band 0x0080) -ne 0;" ^
" if($isShift){ exit 2 } else { exit 0 }" ^
" }" ^
"}"
IF ERRORLEVEL 2 GOTO SHIFT_R
IF ERRORLEVEL 1 GOTO EXIT
ECHO.
GOTO RUN
:SHIFT_R
CLS
ECHO.
GOTO RUN
:EXIT
ECHO.
EXIT /B

View File

@@ -2,13 +2,14 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as process from 'node:process';
import * as readline from 'node:readline';
import stringWidth from 'string-width';
import stripAnsi from 'strip-ansi';
import { fileURLToPath } from 'node:url';
import { spawn } from 'node:child_process';
const SCRIPT_LIST = [
'scrape-and-update-readme-template-contributors-table.mjs',
'scrape-and-update-foojay-resolver-version.mjs',
'scrape-and-inject-rhino-engine-data.mjs',
'scrape-and-inject-latest-gradle-wrapper.mjs',
'scrape-and-inject-gradle-kotlin-compatibility-map.mjs',
@@ -18,19 +19,13 @@ const SCRIPT_LIST = [
'scrape-and-inject-agp-gradle-compatibility-map.mjs',
'scrape-and-inject-agp-releases-list.mjs',
'scrape-and-inject-ksp-releases-map.mjs',
'scrape-and-update-foojay-resolver-version.mjs',
'scrape-and-update-readme-template-contributors-table.mjs',
];
const childProcessOutput = [];
/**
* @param {ScriptItem[]} scripts
* @param {number} idx
* @returns {string}
*/
function getScriptProgressMessage(scripts, idx) {
const order = `${idx + 1}`.padStart(`${scripts.length}`.length, '0');
return `[${order}/${scripts.length}] ${scripts[idx].name}`;
}
const cols = () => process.stdout.columns || 80;
/**
* Parse CLI arguments.<br>
@@ -77,6 +72,36 @@ function ensureExists(filePath) {
}
}
/**
* @param {ScriptItem[]} scripts
* @param {number} idx
* @param {string} [extra='']
* @returns {string}
*/
function oneLineHeader(scripts, idx, extra = '') {
const total = scripts.length;
const order = `${idx + 1}`.padStart(`${total}`.length, '0');
const base = scripts[idx].name;
const suffix = extra ? ` (${extra})` : '';
const core = `[${order}/${total}] ${base}${suffix}`;
const width = cols();
if (core.length <= width) return core;
const ellipsis = ' ... ';
const keep = Math.max(4, width - ellipsis.length);
const left = Math.ceil(keep / 2);
const right = Math.floor(keep / 2);
return core.slice(0, left) + ellipsis + core.slice(core.length - right);
}
/**
* @param {string} text
* @returns {number}
*/
function visualRowsOf(text) {
const width = stringWidth(stripAnsi(text).replace(/\r?\n$/, ''));
return Math.max(1, Math.ceil(width / Math.max(1, cols())));
}
/**
* @param {Object} options
* @param {string} options.nodePath
@@ -141,7 +166,7 @@ async function main() {
const lineLength = Math.min(Math.max(
title.length,
...exhibitionItems.map(s => s.length - 1),
) + 2, process.stdout.columns || 80);
) + 2, cols());
const lineDouble = '='.repeat(lineLength);
const lineSingle = '-'.repeat(lineLength);
@@ -161,14 +186,16 @@ async function main() {
const results = [];
for (let i = 0; i < scripts.length; i++) {
const script = scripts[i];
const startLine = getScriptProgressMessage(scripts, i);
const startLine = oneLineHeader(scripts, i);
process.stdout.write(`\r${startLine}\n`);
const res = await runOne({ nodePath: opts.nodePath, scriptPath: script.abs, cwd: utilsDir });
const endLine = `${startLine} (${formatDuration(res.ms)})`;
const endLine = oneLineHeader(scripts, i, formatDuration(res.ms));
const lineCountToMove = childProcessOutput.map(chunk => `${chunk}`).join('').split('\n').length;
const lineCountToMove = childProcessOutput.map(chunk => `${chunk}`).join('').split('\n').reduce((acc, line) => {
return acc + visualRowsOf(line)
}, 0);
if (res.code === 0) {
childProcessOutput.forEach((chunk) => {
@@ -177,10 +204,10 @@ async function main() {
readline.moveCursor(process.stdout, 0, -lineCountToMove);
readline.clearLine(process.stdout, 0);
process.stdout.write(`\r${endLine}`);
readline.moveCursor(process.stdout, 0, lineCountToMove + 1);
process.stdout.write('\r');
readline.moveCursor(process.stdout, 0, lineCountToMove);
process.stdout.write('\n');
results.push({ ...res, name: script.name });
childProcessOutput.splice(0, childProcessOutput.length);
childProcessOutput.splice(0);
} else {
// readline.moveCursor(process.stdout, 0, -childProcessOutput.length - 1);
// process.stdout.write(`\r${endLine} [code: ${res.code}]`);
@@ -195,7 +222,7 @@ async function main() {
const failed = results.filter(r => r.code !== 0);
if (failed.length === 0) {
const title = 'All tasks completed successfully';
const lineLength = Math.min(Math.max(title.length) + 1, process.stdout.columns || 80);
const lineLength = Math.min(Math.max(title.length) + 1, cols());
const line = '='.repeat(lineLength);
console.log(line);
console.log(` ${title}`);
@@ -210,7 +237,7 @@ async function main() {
const lineLength = Math.min(Math.max(
title.length,
...messages.map(s => s.length - 1),
) + 2, process.stdout.columns || 80);
) + 2, cols());
const lineDouble = '='.repeat(lineLength);
const lineSingle = '-'.repeat(lineLength);
console.log(lineDouble);

View File

@@ -157,4 +157,4 @@ export function printListDiffs(src, other) {
*/
function mapToLines(map) {
return Array.from(map.entries()).map(([ k, v ]) => `"${k}" to "${v}"`).join('\n');
}
}