-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (50 loc) · 1.46 KB
/
Copy pathindex.js
File metadata and controls
64 lines (50 loc) · 1.46 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
#!/usr/bin/env node
import fs from "fs";
import path from "path";
import chalk from "chalk";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
const args = yargs(hideBin(process.argv))
.command(
"postman-viewer <path>",
"watch your collection in a `Mr. Robot` way",
() => {},
(argv) => {
console.info(argv);
}
)
.demandCommand(1)
.parse();
const path_to_collection = args._[0];
const log = console.log;
const collection = JSON.parse(
fs.readFileSync(path.resolve(path.join(path_to_collection)), {
encoding: "utf-8",
})
);
const {
info: { name: collection_name },
item: collection_folder,
} = collection;
log(chalk.bgBlue(collection_name));
print(collection_folder, 2);
function print(list_of_items, space_count) {
list_of_items.forEach((item) => {
const item_type = item.request ? "file" : "folder";
const color = item_type === "file" ? "yellowBright" : "greenBright";
let info = chalk[color](item.name)
if(item.request?.url?.path) {
const url = item.request.url.path.join('/')
info += ' ' + chalk.blueBright(url)
}
log(` `.repeat(space_count) + info);
// item is either an item or item-group.
// item is a http request.
// item-group is a folder of item and another item-groups
// item.request is a must in http request (line 42)
// item.item is a must in item-group (line 54)
if (item.item) {
print(item.item, space_count + 2);
}
});
}