Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
{
"name": "webkit",
"revision": "2249",
"revision": "2250",
"installByDefault": true,
"revisionOverrides": {
"debian11-x64": "2105",
Expand Down
39 changes: 37 additions & 2 deletions packages/playwright/src/mcp/terminal/helpGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const categories: { name: Category, title: string }[] = [
function generateHelp() {
const lines: string[] = [];
lines.push('Usage: playwright-cli <command> [args] [options]');

const commandsByCategory = new Map<string, AnyCommandSchema[]>();
for (const c of categories)
commandsByCategory.set(c.name, []);
Expand All @@ -97,30 +98,64 @@ function generateHelp() {
return lines.join('\n');
}


function generateReadme() {
const lines: string[] = [];
lines.push('\n## Commands');

const commandsByCategory = new Map<string, AnyCommandSchema[]>();
for (const c of categories)
commandsByCategory.set(c.name, []);
for (const command of Object.values(commands))
commandsByCategory.get(command.category)!.push(command);

for (const c of categories) {
const cc = commandsByCategory.get(c.name)!;
if (!cc.length)
continue;
lines.push(`\n### ${c.title}\n`);
lines.push('```bash');
for (const command of cc)
lines.push(generateReadmeEntry(command));
lines.push('```');
}
return lines.join('\n');
}

function generateHelpEntry(command: AnyCommandSchema): string {
const args = commandArgs(command);
const prefix = ` ${command.name} ${commandArgsText(args)}`;
const suffix = command.description.toLowerCase();
return formatWithGap(prefix, suffix);
}

function generateReadmeEntry(command: AnyCommandSchema): string {
const args = commandArgs(command);
const prefix = `playwright-cli ${command.name} ${commandArgsText(args)}`;
const suffix = '# ' + command.description.toLowerCase();
return formatWithGap(prefix, suffix, 40);
}

async function main() {
const help = {
global: generateHelp(),
commands: Object.fromEntries(
Object.entries(commands).map(([name, command]) => [name, generateCommandHelp(command)])
),
};
const readme = generateReadme();
const fileName = path.resolve(__dirname, 'help.json').replace('lib', 'src');
// eslint-disable-next-line no-console
console.log('Writing ', path.relative(process.cwd(), fileName));
await fs.promises.writeFile(fileName, JSON.stringify(help, null, 2));
// eslint-disable-next-line no-console
console.log(help.global);
// eslint-disable-next-line no-console
console.log(readme);
}

function formatWithGap(prefix: string, text: string) {
const indent = Math.max(1, 30 - prefix.length);
function formatWithGap(prefix: string, text: string, threshold: number = 30) {
const indent = Math.max(1, threshold - prefix.length);
return prefix + ' '.repeat(indent) + text;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/playwright/src/mcp/terminal/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async function handleSessionCommand(sessionManager: SessionManager, args: any):
const socketDirHash = (() => {
const hash = crypto.createHash('sha1');
hash.update(require.resolve('../../../package.json'));
return hash.digest('hex');
return hash.digest('hex').substring(0, 16);
})();

const daemonSocketDir = (() => {
Expand All @@ -304,7 +304,7 @@ const daemonSocketDir = (() => {
localCacheDir = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
if (!localCacheDir)
throw new Error('Unsupported platform: ' + process.platform);
return path.join(localCacheDir, 'ms-playwright', 'daemon', 'daemon', socketDirHash);
return path.join(localCacheDir, 'ms-playwright', 'daemon', socketDirHash);
})();

function spawnDaemon(socketPath: string, userDataDir: string, options: SpawnOptions) {
Expand Down
Loading