|
| 1 | +const fs = require('fs'); |
| 2 | +const api = require('../_data/api.json'); |
| 3 | +const Entry = require('./lib/entry'); |
| 4 | +const Parameter = require('./lib/parameter'); |
| 5 | + |
| 6 | +let data = []; |
| 7 | + |
| 8 | +api.forEach((e, i, arr)=> { |
| 9 | + let entry = new Entry(); |
| 10 | + // console.log(`\n# Title:\n${e.name}`); |
| 11 | + entry.name = e.name; |
| 12 | + // //console.log(`# ${JSON.stringify(e.description)}`); |
| 13 | + if(e.description instanceof Object) { |
| 14 | + let des = e.description.children[0].children[0].value; |
| 15 | + // console.log(`## Description:\n${des}`); |
| 16 | + entry.description = des; |
| 17 | + } |
| 18 | + |
| 19 | + if(Array.isArray(e.params)) { |
| 20 | + // console.log('\n### Parameters:'); |
| 21 | + e.params.forEach((ele, ndx, array)=> { |
| 22 | + let param = new Parameter(); |
| 23 | + param.name = ele.name; |
| 24 | + let descr = (ele.description instanceof Object) ? ele.description.children[0].children[0].value : ''; |
| 25 | + param.description = descr; |
| 26 | + entry.parameters.push(param); |
| 27 | + // console.log(`Argument ${ndx + 1}\nName: ${ele.name}\nDescription:\n ${descr}`); |
| 28 | + }); |
| 29 | + } |
| 30 | + if(Array.isArray(e.returns)) { |
| 31 | + // console.log('### Returns'); |
| 32 | + if(e.returns[0].description.children.length > 0) { |
| 33 | + let ret = e.returns[0].description.children[0].children[0].value; |
| 34 | + entry.returns = ret; |
| 35 | + // console.log(ret); |
| 36 | + |
| 37 | + } |
| 38 | + } |
| 39 | + if(Array.isArray(e.tags)) { |
| 40 | + e.tags.forEach((ele, ndx, array)=>{ |
| 41 | + if(ele.title === 'cat') { |
| 42 | + // //console.log(ele.title); |
| 43 | + // console.log(`\n### Category:\n${ele.description}`); |
| 44 | + entry.category = ele.description; |
| 45 | + } |
| 46 | + if(ele.title === 'subcat') { |
| 47 | + // //console.log(ele.title); |
| 48 | + // console.log(`\n### Sub Category:\n${ele.description}`); |
| 49 | + entry.subcategory = ele.description; |
| 50 | + } |
| 51 | + // let tag = _.find(ele, 'title'); |
| 52 | + // //console.log(tag); |
| 53 | + // let tag = _.find(ele, (o)=>{ |
| 54 | + // return o.title === 'cat'; |
| 55 | + // }); |
| 56 | + // //console.log(tag.description); |
| 57 | + }); |
| 58 | + } |
| 59 | + // for(let k in e) { |
| 60 | + // if(e.hasOwnProperty(k)) { |
| 61 | + // //console.log(`\t${k}`); |
| 62 | + // } |
| 63 | + // } |
| 64 | + data.push(entry); |
| 65 | + // console.log('-----------------\n'); |
| 66 | +}); |
| 67 | + |
| 68 | +// console.log(JSON.stringify(data, null, 2)); |
| 69 | + |
| 70 | +fs.writeFile('./_data/data.json', JSON.stringify(data), (err)=>{ |
| 71 | + if(err) { |
| 72 | + throw err; |
| 73 | + } |
| 74 | + // //console.log('saved'); |
| 75 | +}); |
0 commit comments