-
Notifications
You must be signed in to change notification settings - Fork 133
/
index.ts
116 lines (99 loc) 路 2.76 KB
/
index.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
import { logger } from "@qawolf/logger";
import program from "commander";
import { red, yellow } from "kleur";
import { camelCase } from "lodash";
import updateNotifier from "update-notifier";
import { saveCiTemplate } from "./ci";
import { create } from "./create";
import { howl } from "./howl";
import { runJest } from "./runJest";
import { omitArgs, parseUrl } from "./utils";
const pkg = require("../package");
updateNotifier({ pkg }).notify();
program.usage("<command> [options]").version(pkg.version);
program
.command("create <url> [name]")
// XXX remove in v1.0.0
.alias("record")
.option("--debug", "save events and workflow json for debugging")
.option("-d, --device <device>", "emulate using a puppeteer.device")
.option("-p, --path <path>", "path to save the file")
.option("-s, --script", "create a script instead of a test")
.description("create a test from browser actions")
.action(async (urlArgument, optionalName, cmd) => {
if (process.argv[2] === "record") {
console.log(
red(
`"qawolf record" will be removed in v1.0.0\nPlease use "qawolf create" instead`
)
);
}
const url = parseUrl(urlArgument);
logger.verbose(`create "${url.href}"`);
const name = camelCase(optionalName || url.hostname!.replace(/\..*/g, ""));
await create({
debug: cmd.debug,
device: cmd.device,
name,
path: cmd.path,
test: !cmd.script,
url
});
});
program
.command("test")
.option("-p, --path <path>", "path to test code")
.description("run a test with Jest")
.allowUnknownOption(true)
.action(cmd => {
const args = omitArgs(process.argv.slice(3), ["-p", "--path"]);
const code = runJest(args, {
path: cmd.path
});
process.exit(code);
});
program
.command("azure")
.description("set up an Azure Pipeline")
.action(async () => {
await saveCiTemplate("azure");
});
program
.command("circleci")
.description("set up CircleCI")
.action(async () => {
await saveCiTemplate("circleci");
});
program
.command("github")
.description("set up a GitHub Action")
.action(async () => {
await saveCiTemplate("github");
});
program
.command("gitlab")
.description("set up GitLab CI/CD")
.action(async () => {
await saveCiTemplate("gitlab");
});
program
.command("howl")
.description("馃惡")
.action(howl);
program
.command("jenkins")
.description("set up Jenkins")
.action(async () => {
await saveCiTemplate("jenkins");
});
program.arguments("<command>").action(cmd => {
console.log(yellow(`Invalid command "${cmd}"\n`));
program.help();
});
program.allowUnknownOption(false);
program.parse(process.argv);
if (!process.argv.slice(2).length) {
console.log("\n");
program.outputHelp();
}