-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
executable file
·70 lines (64 loc) · 1.42 KB
/
index.js
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
#!/usr/bin/env node
import Listr from "listr";
import yargs from "yargs/yargs";
import { Observable } from "rxjs";
import { getHTML, initialPrompt, start } from "./lib/prompts.js";
const result = yargs(process.argv.slice(2))
.options({
endpoint: {
alias: "e",
describe: "endpoint",
demandOption: true,
},
components: {
alias: "t",
describe: "tests",
default: "1",
},
model: {
alias: "m",
describe: "model",
default: "gpt4",
},
})
.help().argv;
process.endpoint = result.endpoint;
process.model = result.model || "gpt4";
const tasks = new Listr([
{
title: "Fetching endpoint...",
task: async (ctx) => {
const html = await getHTML(result.endpoint);
ctx.html = html;
return html;
},
},
{
title: `Connecting to AI (${process.model.toLocaleString()}) ...`,
task: async () => {
return await initialPrompt();
},
},
{
title: "Writing tests...",
task: async (ctx) => {
return new Observable((observer) => {
start(observer, ctx, result.endpoint, result.components);
});
},
},
]);
tasks
.run()
.then((ctx) => {
console.log(`Generated the following tests:`);
ctx.testsPassing.forEach((test) => {
console.log("✔", test);
});
ctx.testsFailed.forEach((test) => {
console.log("⚠️", test);
});
})
.catch((err) => {
console.error(err);
});