-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
112 lines (94 loc) · 3.07 KB
/
Copy pathcli.js
File metadata and controls
112 lines (94 loc) · 3.07 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
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
#!/usr/bin/env node
const {
generateReleaseNotes,
parseReleaseNotes,
createCombinedReleaseNotes,
} = require("./index")
const readline = require("readline")
const fs = require("fs").promises
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
async function promptForInput() {
return new Promise((resolve) => {
console.log("\n--- Release Notes Generator CLI ---")
console.log("\nEnter release notes (type 'EOF' on a new line when done):")
let releaseNotesInput = ""
const collectReleaseNotes = (line) => {
if (line === "EOF") {
rl.removeListener("line", collectReleaseNotes)
rl.question(
"Languages (comma-separated, default: en,sv,fr): ",
(languagesInput) => {
const languages = languagesInput
? languagesInput.split(",").map((l) => l.trim().toLowerCase())
: ["en", "sv", "fr"]
rl.question("Max Length (default: 500): ", (maxLengthInput) => {
const maxLength = maxLengthInput ? parseInt(maxLengthInput) : 500
// Check for OpenAI API key in environment
const openaiApiKey = process.env.OPENAI_API_KEY
if (!openaiApiKey) {
console.error(
"Error: OPENAI_API_KEY environment variable is not set"
)
process.exit(1)
}
resolve({
originalReleaseNotes: releaseNotesInput,
maxLength,
openaiApiKey,
languages,
})
})
}
)
} else {
releaseNotesInput += line + "\n"
}
}
rl.on("line", collectReleaseNotes)
})
}
async function run() {
try {
const input = await promptForInput()
console.log("\nGenerating release notes...")
// Generate release notes directly
const assistantResponse = await generateReleaseNotes(
input.originalReleaseNotes,
input.maxLength,
input.openaiApiKey,
input.languages
)
// Parse the response
const releaseNotes = parseReleaseNotes(assistantResponse, input.languages)
// Display results for all languages
for (const [lang, notes] of Object.entries(releaseNotes)) {
console.log(`\n=== ${lang.toUpperCase()} Release Notes ===`)
console.log(notes || "No notes generated for this language.")
}
// Create and display combined release notes
const combinedNotes = createCombinedReleaseNotes(
releaseNotes,
input.languages
)
console.log("\n=== COMBINED RELEASE NOTES ===")
console.log(combinedNotes)
// Ask user if they want to save the output
rl.question(
"\nDo you want to save these release notes to a file? (y/n): ",
async (answer) => {
if (answer.toLowerCase() === "y") {
await fs.writeFile("release-notes.md", combinedNotes)
console.log("Release notes saved to release-notes.md")
}
rl.close()
}
)
} catch (error) {
console.error("Unexpected error:", error)
rl.close()
}
}
run()