-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.mjs
executable file
·44 lines (37 loc) · 1.26 KB
/
index.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
#!/usr/bin/env node
import fs from "fs";
import { program } from "commander";
import { discoverEndpoints, generatePostmanCollection } from "./lib/index.mjs";
// Load configuration based on provided config file
program
.option("-c, --config <configPath>", "Specify config file path")
.parse(process.argv);
// Extract configPath from command-line arguments or fallback to default
const configPath = program.config || "./config.json";
// Read and parse the configuration file
let config;
try {
config = JSON.parse(fs.readFileSync(configPath, "utf8"));
} catch (err) {
console.error("Error reading or parsing configuration file:", err);
process.exit(1);
}
// Function to run API discovery and collection generation
async function runTool(writeCollection = false) {
try {
const endpoints = await discoverEndpoints(config);
await generatePostmanCollection(
endpoints,
config.baseUrl,
config.postmanKey,
config.workspaceId,
config.collectionName,
writeCollection
);
console.log("Postman collection generated successfully!");
} catch (error) {
console.error("Error generating Postman collection:", error.message);
}
}
// Run the tool based on command-line arguments
runTool(true); // Always write collection in CLI mode