Repository navigation
Expand file tree
/
Copy pathcli.ts
More file actions
64 lines (59 loc) · 2.63 KB
/
Copy pathcli.ts
File metadata and controls
64 lines (59 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright (c) Microsoft Corporation.
*
* 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.
*/
import path from 'path';
import { Command } from 'commander';
import { CliOptions, Generator } from './generator';
import { parseBrowsers, parseLanguage } from './utils';
const program = new Command();
program
.name('create-playwright')
.description('Getting started with writing end-to-end tests with Playwright.')
.argument('[rootDir]', 'Target directory for the Playwright project', '.')
.option('--browser <browser...>', `browsers to use in default config (default: 'chromium,firefox,webkit')`, parseBrowsers)
.option('--no-browsers', 'do not download browsers (can be done manually via \'npx playwright install\')')
.option('--no-examples', 'do not create example test files')
.option('--install-deps', 'install dependencies')
.option('--next', 'install @next version of Playwright')
.option('--beta', 'install @beta version of Playwright')
.option('--quiet', 'do not ask for interactive input prompts')
.option('--gha', 'install GitHub Actions')
.option('--no-gha', 'do not install GitHub Actions')
.option('--lang <language>', 'language to use (js, TypeScript)', parseLanguage)
.option('--test-dir <directory>', 'directory for test files (default: "tests" if it does not exist, otherwise "e2e")')
.option('--force', 'override existing files without asking')
.action(async (rootDir, options) => {
const cliOptions: CliOptions = {
browser: options.browser,
noBrowsers: !options.browsers,
noExamples: !options.examples,
installDeps: options.installDeps,
next: options.next,
beta: options.beta,
// Prompts cannot be answered without a TTY, fall back to the --quiet defaults.
quiet: options.quiet || !process.stdin.isTTY,
gha: options.gha,
lang: options.lang,
testDir: options.testDir,
force: options.force,
};
const resolvedRootDir = path.resolve(process.cwd(), rootDir || '.');
const generator = new Generator(resolvedRootDir, cliOptions);
await generator.run();
});
program.parseAsync().catch(error => {
console.error(error);
process.exit(1);
});