1
- import 'dotenv/config'
1
+ import 'dotenv/config' ;
2
2
3
- import fsExtra from 'fs-extra'
4
- import { difference } from 'lodash-es'
5
- import { gt , compare as compareSemVers } from 'semver'
3
+ import fsExtra from 'fs-extra' ;
4
+ import { difference } from 'lodash-es' ;
5
+ import { gt , compare as compareSemVers } from 'semver' ;
6
6
7
- import algoliaDriver from './drivers/algolia.js'
8
- import jsonDriver from './drivers/json.js'
9
- import schemas from './schemas/index.js'
7
+ import algoliaDriver from './drivers/algolia.js' ;
8
+ import jsonDriver from './drivers/json.js' ;
9
+ import schemas from './schemas/index.js' ;
10
10
11
11
const { readJsonSync } = fsExtra ;
12
12
13
- const apiIndexes = [ 'modules' , 'classes' , 'methods' , 'versions' ]
13
+ const apiIndexes = [ 'modules' , 'classes' , 'methods' , 'versions' ] ;
14
14
15
15
export async function runApi ( clearIndex = false , useJsonDriver = false ) {
16
- let driver = useJsonDriver ? jsonDriver : algoliaDriver
16
+ let driver = useJsonDriver ? jsonDriver : algoliaDriver ;
17
17
18
- apiIndexes . map ( driver . init )
18
+ apiIndexes . map ( driver . init ) ;
19
19
20
20
if ( clearIndex ) {
21
- apiIndexes . map ( driver . clear )
21
+ apiIndexes . map ( driver . clear ) ;
22
22
}
23
23
24
- await Promise . all ( [
25
- processDocs ( driver , 'ember' ) ,
26
- processDocs ( driver , 'ember-data' ) ,
27
- ] )
24
+ await Promise . all ( [ processDocs ( driver , 'ember' ) , processDocs ( driver , 'ember-data' ) ] ) ;
28
25
}
29
26
30
27
async function processDocs ( driver , project ) {
31
- let prevIndexedVersions = await driver . getPreviouslyIndexedVersions ( project )
28
+ let prevIndexedVersions = await driver . getPreviouslyIndexedVersions ( project ) ;
32
29
33
30
const {
34
31
meta : { availableVersions } ,
35
- } = readJsonSync ( `../ember-api-docs-data/rev-index/${ project } .json` )
32
+ } = readJsonSync ( `../ember-api-docs-data/rev-index/${ project } .json` ) ;
36
33
37
- let versionsToProcess = difference ( availableVersions , prevIndexedVersions )
34
+ let versionsToProcess = difference ( availableVersions , prevIndexedVersions ) ;
38
35
39
36
if ( versionsToProcess . length === 0 ) {
40
- console . log ( `No new versions to process for ${ project } ` )
41
- return
37
+ console . log ( `No new versions to process for ${ project } ` ) ;
38
+ return ;
42
39
}
43
40
44
41
try {
45
42
// iterate versions and drop latest minor of each major in buckets
46
43
// make an array of the latest minors you get
47
44
let latestPatches = Object . values ( versionsToProcess . reduce ( addIfLatestPatch , { } ) ) ;
48
- console . log ( `Processing ${ project } for versions: ${ latestPatches } ` )
45
+ console . log ( `Processing ${ project } for versions: ${ latestPatches } ` ) ;
49
46
await latestPatches
50
- . filter ( version => filterMissingRevs ( version , project ) )
51
- . map ( version => readIndexFileForVersion ( version , project ) )
47
+ . filter ( ( version ) => filterMissingRevs ( version , project ) )
48
+ . map ( ( version ) => readIndexFileForVersion ( version , project ) )
52
49
// Fetch all public modules and public classes
53
- . map ( versionIndexObject =>
54
- fetchPublicModuleClassesForVersion ( versionIndexObject , project )
55
- )
50
+ . map ( ( versionIndexObject ) => fetchPublicModuleClassesForVersion ( versionIndexObject , project ) )
56
51
// Run the schema against all data stored
57
52
. map ( mapDataForVersion )
58
- . map ( content => writeToDriver ( driver , content ) )
59
- let versions = [ ...prevIndexedVersions , ...versionsToProcess ] . sort (
60
- compareSemVers
61
- )
53
+ . map ( ( content ) => writeToDriver ( driver , content ) ) ;
54
+ let versions = [ ...prevIndexedVersions , ...versionsToProcess ] . sort ( compareSemVers ) ;
62
55
63
56
await driver . write (
64
57
'versions' ,
65
- [ {
66
- id : project ,
67
- name : project ,
68
- index_date_timestamp : Date . now ( ) ,
69
- versions
70
- } ] ,
58
+ [
59
+ {
60
+ id : project ,
61
+ name : project ,
62
+ index_date_timestamp : Date . now ( ) ,
63
+ versions,
64
+ } ,
65
+ ] ,
71
66
project
72
- )
67
+ ) ;
73
68
} catch ( err ) {
74
- console . log ( 'Error:: ' , err )
69
+ console . log ( 'Error:: ' , err ) ;
75
70
}
76
71
}
77
72
78
73
function addIfLatestPatch ( latestPatches , version ) {
79
- let semvers = version . split ( '.' )
74
+ let semvers = version . split ( '.' ) ;
80
75
let major = semvers [ 0 ] ;
81
76
let minor = semvers [ 1 ] ;
82
77
let minorVersion = `${ major } .${ minor } ` ;
@@ -89,56 +84,52 @@ function addIfLatestPatch(latestPatches, version) {
89
84
}
90
85
91
86
function filterMissingRevs ( version , libName ) {
92
- const emberVersionJSONPath = `../ember-api-docs-data/rev-index/${ libName } -${ version } .json`
93
- let isIncluded = true
87
+ const emberVersionJSONPath = `../ember-api-docs-data/rev-index/${ libName } -${ version } .json` ;
88
+ let isIncluded = true ;
94
89
try {
95
- readJsonSync ( emberVersionJSONPath )
96
- } catch ( e ) {
97
- isIncluded = false
90
+ readJsonSync ( emberVersionJSONPath ) ;
91
+ } catch ( e ) {
92
+ isIncluded = false ;
98
93
}
99
- return isIncluded
94
+ return isIncluded ;
100
95
}
101
96
102
97
function readIndexFileForVersion ( version , libName ) {
103
- const emberVersionJSONPath = `../ember-api-docs-data/rev-index/${ libName } -${ version } .json`
104
- console . debug ( `OPENING:: ${ emberVersionJSONPath } ` )
105
- return readJsonSync ( emberVersionJSONPath )
98
+ const emberVersionJSONPath = `../ember-api-docs-data/rev-index/${ libName } -${ version } .json` ;
99
+ console . debug ( `OPENING:: ${ emberVersionJSONPath } ` ) ;
100
+ return readJsonSync ( emberVersionJSONPath ) ;
106
101
}
107
102
108
103
function fetchPublicModuleClassesForVersion ( versionIndexObject , libName ) {
109
- const publicModules = versionIndexObject . data . relationships [
110
- 'public-modules'
111
- ] . data . map ( module => {
112
- const id = module . id ;
113
- if ( ! versionIndexObject . meta . module [ id ] ) {
114
- console . warn ( `Skipping processing module ${ id } because it's missing a meta entry` ) ;
115
- return null ;
104
+ const publicModules = versionIndexObject . data . relationships [ 'public-modules' ] . data
105
+ . map ( ( module ) => {
106
+ const id = module . id ;
107
+ if ( ! versionIndexObject . meta . module [ id ] ) {
108
+ console . warn ( `Skipping processing module ${ id } because it's missing a meta entry` ) ;
109
+ return null ;
110
+ }
111
+ const modulePath = `../ember-api-docs-data/json-docs/${ libName } /${ versionIndexObject . data . attributes . version } /modules/${ versionIndexObject . meta . module [ id ] } .json` ;
112
+
113
+ console . debug ( `OPENING:: ${ modulePath } ` ) ;
114
+ return readJsonSync ( modulePath ) ;
115
+ } )
116
+ . filter ( Boolean ) ;
117
+
118
+ const publicClasses = versionIndexObject . data . relationships [ 'public-classes' ] . data . map (
119
+ ( classObj ) => {
120
+ const id = classObj . id ;
121
+ const classPath = `../ember-api-docs-data/json-docs/${ libName } /${ versionIndexObject . data . attributes . version } /classes/${ versionIndexObject . meta . class [ id ] } .json` ;
122
+
123
+ console . debug ( `OPENING:: ${ classPath } ` ) ;
124
+ return readJsonSync ( classPath ) ;
116
125
}
117
- const modulePath = `../ember-api-docs-data/json-docs/${ libName } /${
118
- versionIndexObject . data . attributes . version
119
- } /modules/${ versionIndexObject . meta . module [ id ] } .json`
120
-
121
- console . debug ( `OPENING:: ${ modulePath } ` )
122
- return readJsonSync ( modulePath )
123
- } ) . filter ( Boolean )
124
-
125
- const publicClasses = versionIndexObject . data . relationships [
126
- 'public-classes'
127
- ] . data . map ( classObj => {
128
- const id = classObj . id ;
129
- const classPath = `../ember-api-docs-data/json-docs/${ libName } /${
130
- versionIndexObject . data . attributes . version
131
- } /classes/${ versionIndexObject . meta . class [ id ] } .json`
132
-
133
- console . debug ( `OPENING:: ${ classPath } ` )
134
- return readJsonSync ( classPath )
135
- } )
126
+ ) ;
136
127
137
128
return {
138
129
version : versionIndexObject ,
139
130
publicModules,
140
131
publicClasses,
141
- }
132
+ } ;
142
133
}
143
134
144
135
/**
@@ -148,39 +139,33 @@ function fetchPublicModuleClassesForVersion(versionIndexObject, libName) {
148
139
* @returns {object } - Extended version object with methods & mapped schemas
149
140
*/
150
141
function mapDataForVersion ( versionObject ) {
151
- const staticFunctions = extractStaticFunctionsFromModules (
152
- versionObject . publicModules
153
- )
154
- const methods = extractMethodsFromClasses ( versionObject . publicClasses )
142
+ const staticFunctions = extractStaticFunctionsFromModules ( versionObject . publicModules ) ;
143
+ const methods = extractMethodsFromClasses ( versionObject . publicClasses ) ;
155
144
156
145
return {
157
146
...versionObject ,
158
147
methods : [ ...methods , ...staticFunctions ] ,
159
148
publicModules : versionObject . publicModules . map ( schemas . moduleSchema ) ,
160
149
publicClasses : versionObject . publicClasses . map ( schemas . classSchema ) ,
161
- }
150
+ } ;
162
151
}
163
152
164
153
function writeToDriver ( driver , versionObject ) {
165
- const { id } = versionObject . version . data
154
+ const { id } = versionObject . version . data ;
166
155
167
- let tokens = id . split ( '-' )
168
- let version = tokens . pop ( )
169
- let projectName = tokens . join ( '-' )
156
+ let tokens = id . split ( '-' ) ;
157
+ let version = tokens . pop ( ) ;
158
+ let projectName = tokens . join ( '-' ) ;
170
159
171
160
console . info (
172
- `version: ${ id } , public classes: ${
173
- versionObject . publicClasses . length
174
- } , public modules: ${ versionObject . publicModules . length } , methods: ${
175
- versionObject . methods . length
176
- } `
177
- )
161
+ `version: ${ id } , public classes: ${ versionObject . publicClasses . length } , public modules: ${ versionObject . publicModules . length } , methods: ${ versionObject . methods . length } `
162
+ ) ;
178
163
179
164
return Promise . all ( [
180
165
driver . write ( 'modules' , versionObject . publicModules , projectName , version ) ,
181
166
driver . write ( 'classes' , versionObject . publicClasses , projectName , version ) ,
182
167
driver . write ( 'methods' , versionObject . methods , projectName , version ) ,
183
- ] )
168
+ ] ) ;
184
169
}
185
170
186
171
/**
@@ -195,34 +180,34 @@ function extractMethodsFromClasses(classes) {
195
180
currentClass . data . attributes . methods
196
181
. reduce ( ( classMethods , currentMethod ) => {
197
182
// Transform the current method and push on to methods.
198
- classMethods . push ( schemas . methodSchema ( currentMethod , currentClass ) )
199
- return classMethods
183
+ classMethods . push ( schemas . methodSchema ( currentMethod , currentClass ) ) ;
184
+ return classMethods ;
200
185
} , [ ] )
201
186
// Merge all methods of all classes into a single array
202
187
. concat ( methods )
203
- )
204
- } , [ ] )
188
+ ) ;
189
+ } , [ ] ) ;
205
190
}
206
191
207
192
function extractStaticFunctionsFromModules ( modules ) {
208
193
return modules . reduce ( ( methods , currentModule ) => {
209
- const staticfunctionsObj = currentModule . data . attributes . staticfunctions
194
+ const staticfunctionsObj = currentModule . data . attributes . staticfunctions ;
210
195
211
196
// Guard against staticfunctions not existing.
212
- if ( ! staticfunctionsObj ) return methods
197
+ if ( ! staticfunctionsObj ) return methods ;
213
198
// Extract all the static functions from inside their sub-modules
214
199
const moduleStaticFunctions = Object . keys ( staticfunctionsObj ) . reduce (
215
200
( prevStaticFunctions , currModuleName ) => {
216
- return prevStaticFunctions . concat ( staticfunctionsObj [ currModuleName ] )
201
+ return prevStaticFunctions . concat ( staticfunctionsObj [ currModuleName ] ) ;
217
202
} ,
218
203
[ ]
219
- )
204
+ ) ;
220
205
221
206
return moduleStaticFunctions
222
207
. reduce ( ( moduleStaticFunctions , currentStaticFunction ) => {
223
- moduleStaticFunctions . push ( schemas . methodSchema ( currentStaticFunction , currentModule ) )
224
- return moduleStaticFunctions
208
+ moduleStaticFunctions . push ( schemas . methodSchema ( currentStaticFunction , currentModule ) ) ;
209
+ return moduleStaticFunctions ;
225
210
} , [ ] )
226
- . concat ( methods )
227
- } , [ ] )
211
+ . concat ( methods ) ;
212
+ } , [ ] ) ;
228
213
}
0 commit comments