@@ -2,76 +2,55 @@ const fs = require('fs');
2
2
const api = require ( '../_data/api.json' ) ;
3
3
const Entry = require ( './lib/entry' ) ;
4
4
const Parameter = require ( './lib/parameter' ) ;
5
+ const Tag = require ( './lib/tag' ) ;
5
6
const Category = require ( './lib/category' ) ;
6
7
const _ = require ( 'lodash' ) ;
7
8
8
9
9
10
let data = [ ] ;
10
-
11
11
api . forEach ( ( e , i , arr ) => {
12
12
let entry = new Entry ( ) ;
13
- // console.log(`\n# Title:\n${e.name}`);
14
13
entry . name = e . name ;
15
- // //console.log(`# ${JSON.stringify(e.description)}`);
16
14
if ( e . description instanceof Object ) {
17
15
let des = e . description . children [ 0 ] . children [ 0 ] . value ;
18
- // console.log(`## Description:\n${des}`);
19
16
entry . description = des ;
20
17
}
21
18
if ( e . hasOwnProperty ( 'kind' ) === true ) {
22
19
entry . kind = e . kind ;
23
20
}
24
-
25
21
if ( Array . isArray ( e . params ) ) {
26
- // console.log('\n### Parameters:');
27
22
e . params . forEach ( ( ele , ndx , array ) => {
28
23
let param = new Parameter ( ) ;
29
24
param . name = ele . name ;
30
25
let descr = ( ele . description instanceof Object ) ? ele . description . children [ 0 ] . children [ 0 ] . value : '' ;
31
26
param . description = descr ;
32
27
entry . parameters . push ( param ) ;
33
- // console.log(`Argument ${ndx + 1}\nName: ${ele.name}\nDescription:\n ${descr}`);
34
28
} ) ;
35
29
}
36
30
if ( Array . isArray ( e . returns ) ) {
37
- // console.log('### Returns');
38
31
if ( e . returns [ 0 ] . description . children . length > 0 ) {
39
32
let ret = e . returns [ 0 ] . description . children [ 0 ] . children [ 0 ] . value ;
40
33
entry . returns = ret ;
41
- // console.log(ret);
42
-
43
34
}
44
35
}
45
36
if ( Array . isArray ( e . tags ) ) {
46
37
e . tags . forEach ( ( ele , ndx , array ) => {
47
38
if ( ele . title === 'cat' ) {
48
- // //console.log(ele.title);
49
- // console.log(`\n### Category:\n${ele.description}`);
50
39
entry . category = ele . description ;
51
- }
52
- if ( ele . title === 'subcat' ) {
53
- // //console.log(ele.title);
54
- // console.log(`\n### Sub Category:\n${ele.description}`);
40
+ } else if ( ele . title === 'subcat' ) {
55
41
entry . subcategory = ele . description ;
42
+ } else {
43
+ var tag = new Tag ( ) ;
44
+ tag . name = ele . name ;
45
+ tag . title = ele . title ;
46
+ tag . description = ele . description ;
47
+ tag . type = ele . type !== null ? ele . type : null ;
48
+ entry . tags . push ( tag ) ;
56
49
}
57
- // let tag = _.find(ele, 'title');
58
- // //console.log(tag);
59
- // let tag = _.find(ele, (o)=>{
60
- // return o.title === 'cat';
61
- // });
62
- // //console.log(tag.description);
63
50
} ) ;
64
51
}
65
- // for(let k in e) {
66
- // if(e.hasOwnProperty(k)) {
67
- // //console.log(`\t${k}`);
68
- // }
69
- // }
70
52
data . push ( entry ) ;
71
- // console.log('-----------------\n');
72
53
} ) ;
73
-
74
- // console.log(JSON.stringify(data, null, 2));
75
54
// taken from here
76
55
// http://stackoverflow.com/questions/23600897/using-lodash-groupby-how-to-add-your-own-keys-for-grouped-output
77
56
let sortedByCategory = _ . chain ( data )
@@ -93,19 +72,16 @@ let sortedBySubCategory = _.chain(data)
93
72
} ) . value ( ) ;
94
73
95
74
96
- // console.log(JSON.stringify(sortedBySubCategory, null, 2));
97
-
98
-
99
75
fs . writeFile ( './_data/categories.json' , JSON . stringify ( sortedByCategory , null , 2 ) , ( err ) => {
100
76
if ( err ) {
101
77
throw err ;
102
78
}
103
- // //console.log('saved');
79
+
104
80
} ) ;
105
81
106
82
fs . writeFile ( './_data/sub-categories.json' , JSON . stringify ( sortedBySubCategory , null , 2 ) , ( err ) => {
107
83
if ( err ) {
108
84
throw err ;
109
85
}
110
- // //console.log('saved');
86
+
111
87
} ) ;
0 commit comments