-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodegen.mjs
59 lines (50 loc) · 1.35 KB
/
codegen.mjs
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
import path from "path";
import fsp from "fs/promises";
import { fileURLToPath } from "url";
import { execa } from "execa";
import chalk from "chalk";
import inquirer from "inquirer";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const TYPES_FILE = path.resolve(path.join(__dirname, "src", "types.ts"));
const runOpenApiGenerator = async (branchName) => {
try {
await execa("npx", [
"openapi-typescript",
`https://raw.githubusercontent.com/uselotus/lotus/${branchName}/docs/openapi.yaml`,
"--output",
TYPES_FILE,
]);
console.log(chalk.green("Generated typescript types"));
} catch (err) {
console.error("[runOpenApiGenerator]: ", err);
process.exit(1);
}
};
const bumpVersion = async (bump) => {
try {
await execa("npx", ["npm-bump", bump]);
} catch (err) {
console.error("[bumpVersion]: ", err);
process.exit(1);
}
};
inquirer
.prompt([
{
type: "input",
name: "branchName",
message: "Specify the branch name:",
},
{
type: "list",
name: "bump",
message: "Specify the type of version bump:",
choices: ["patch", "minor", "major"],
},
])
.then(async (answers) => {
const { branchName, bump } = answers;
await runOpenApiGenerator(branchName);
await bumpVersion(bump);
console.log(chalk.green("Done!"));
});