-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse.js
62 lines (49 loc) · 1.75 KB
/
parse.js
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
var fs = require('fs'), // needed to read JSON file from disk
pretty = function (obj) { // function to neatly log the collection object to console
return require('util').inspect(obj, {colors: true});
},
Collection = require('postman-collection').Collection,
myCollection;
const repl = require('repl');
// Load a collection to memory from a JSON file on disk (say, sample-collection.json)
myCollection = new Collection(JSON.parse(fs.readFileSync('collection.json').toString()));
// log items at root level of the collection
myCollection.variables.each(function(variable) {
if(variable.value.length < 500) {
console.log(`@${variable.key} = ${variable.value}`);
}
else {
// TODO: load value from file?
}
})
console.log();
var cnt = 1;
myCollection.items.each(function(item) {
// console.log(item);
item.items.each(function(member) {
var request = member.request,
prerequest = member.events.members.find((event) => (event.listen == 'prerequest')),
test = member.events.members.find((event) => (event.listen == 'test'));
console.log(`### ${member.name}`);
console.log(`# @name request${cnt}`);
if(prerequest && prerequest.script.exec[0] != '') {
console.log(`{{\n${prerequest.script.exec.join("\n")}\n}}\n`);
}
console.log(`${request.method} ${request.url.toString()}`);
// if(request.headers) {
console.log(request.headers.toString());
// }
if(request.body) {
console.log(request.body.raw);
}
if(test && test.script.exec[0] != '') {
console.log(`{{\n${test.script.exec.join("\n")}\n}}\n`);
}
console.log();
cnt++;
// pry = require('pryjs')
// eval(pry.it)
// console.log(member);
// throw '';
})
})