-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (42 loc) · 1.85 KB
/
index.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
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('Welcome to the Postman API documentation generator. This requires Postman collections with version of 2.1 with a filename format "*.postman_collection.json"');
// read out the files in our input directory and figure out which ones are actually postman
let inputFileList = fs.readdirSync('./input');
let postmanInputFiles = [];
inputFileList.forEach(function(item) {
if (item.search(/.+(.postman_collection.json)/g) >= 0)
postmanInputFiles.push(item);
});
if (postmanInputFiles.length == 0) return console.log('No files with the correct name structure found in the input folder. Exiting.');
console.log('Select the input file you want to create API Docs for from the following list:');
for (i = 0; i < postmanInputFiles.length; i++) {
console.log(i + '. ' + postmanInputFiles[i]);
};
rl.question('Selection? ', (selectedFile) => {
rl.close();
let postmanCollection = JSON.parse(fs.readFileSync('./input/' + postmanInputFiles[selectedFile]).toString());
let thisLevel = postmanCollection;
let parseLevel = null;
parseAndAsk(thisLevel);
function parseAndAsk(level) {
console.log('Select a tree to navigate into or press enter to make documentation recursively from this level')
let items = level['item'];
for (i = 0; i < items.length; i++) {
console.log(i + '. ' + items[i].name);
}
rl.question('Selection?', (selectedLevel) => {
rl.close();
if (selectedLevel = "\n")
parseLevel = level;
else {
thisLevel = level[items[selectedLevel]];
process.nextTick(parseAndAsk, level[items[selectedLevel]]);
}
});
}
});