UNPKG

972 BJavaScriptView Raw
1const program = require("commander");
2const jsonfile = require("jsonfile");
3
4const helpers = require("../dist");
5const apis = require("../dist");
6
7program.parse(process.argv);
8
9const stderr = console.error.bind(console);
10
11async function exporting(name, dist) {
12 await helpers.checkApiKey();
13 if (typeof name === "undefined") {
14 stderr("collection name not given!");
15 process.exit(1);
16 }
17 const collections = await apis.listCollections();
18 const found = collections.find(c => c.name === name);
19
20 if (!found) {
21 stderr(`collection ${name} not found!`);
22 process.exit(1);
23 }
24
25 let file = dist;
26 if (typeof file === "undefined") {
27 file = `./${name}.postman_collection.json`;
28 }
29
30 const collection = await apis.singleCollection(found.id);
31 jsonfile.writeFileSync(file, collection, { spaces: 2 });
32}
33
34exporting(program.name, program.dist)
35 .then(() => console.log("exporting success."))
36 .catch(err => {
37 stderr(err);
38 process.exit(1);
39 });