chore: refactor internal cli commands to use commander (#12146)

This commit is contained in:
Dmitry Gozman 2022-02-16 09:54:12 -08:00 committed by GitHub
parent 7ee35ae30d
commit 47cc7c4ae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View file

@ -218,6 +218,33 @@ program
launchGridAgent(options.agentId, options.gridUrl);
});
program
.command('run-driver', { hidden: true })
.action(function(options) {
runDriver();
});
program
.command('run-server', { hidden: true })
.option('--port <port>', 'Server port')
.action(function(options) {
runServer(options.port ? +options.port : undefined).catch(logErrorAndExit);
});
program
.command('print-api-json', { hidden: true })
.action(function(options) {
printApiJson();
});
program
.command('launch-server', { hidden: true })
.requiredOption('--browser <browserName>', 'Browser name, one of "chromium", "firefox" or "webkit"')
.option('--config <path-to-config-file>', 'JSON file with launchServer options')
.action(function(options) {
launchBrowserServer(options.browserName, options.config);
});
program
.command('show-trace [trace...]')
.option('-b, --browser <browserType>', 'browser to use, one of cr, chromium, ff, firefox, wk, webkit', 'chromium')
@ -270,17 +297,7 @@ if (!process.env.PW_LANG_NAME) {
}
}
if (process.argv[2] === 'run-driver')
runDriver();
else if (process.argv[2] === 'run-server')
runServer(process.argv[3] ? +process.argv[3] : undefined).catch(logErrorAndExit);
else if (process.argv[2] === 'print-api-json')
printApiJson();
else if (process.argv[2] === 'launch-server')
launchBrowserServer(process.argv[3], process.argv[4]).catch(logErrorAndExit);
else
program.parse(process.argv);
program.parse(process.argv);
type Options = {
browser: string;

View file

@ -71,7 +71,7 @@ if (mode === 'service') {
if (mode === 'service2') {
config.webServer = {
command: 'npx playwright run-server 3333',
command: 'npx playwright run-server --port=3333',
port: 3333,
reuseExistingServer: true,
};

View file

@ -27,7 +27,7 @@ class OutOfProcessPlaywrightServer {
private _receivedPortPromise: Promise<string>;
constructor(port: number, proxyPort: number) {
this._driverProcess = childProcess.fork(path.join(__dirname, '..', 'packages', 'playwright-core', 'lib', 'cli', 'cli.js'), ['run-server', port.toString()], {
this._driverProcess = childProcess.fork(path.join(__dirname, '..', 'packages', 'playwright-core', 'lib', 'cli', 'cli.js'), ['run-server', '--port', port.toString()], {
stdio: 'pipe',
detached: true,
env: {