1 | const program = require("commander");
|
2 | const jsonfile = require("jsonfile");
|
3 |
|
4 | const helpers = require("../dist");
|
5 | const apis = require("../dist");
|
6 |
|
7 | program.parse(process.argv);
|
8 |
|
9 | const stderr = console.error.bind(console);
|
10 |
|
11 | async 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 |
|
34 | exporting(program.name, program.dist)
|
35 | .then(() => console.log("exporting success."))
|
36 | .catch(err => {
|
37 | stderr(err);
|
38 | process.exit(1);
|
39 | });
|