1
1
const { readdirSync } = require ( 'fs' ) ;
2
+ const cmp = require ( 'semver-compare' ) ;
3
+ const semver = require ( 'semver' ) ;
2
4
3
5
module . exports = function ( ) {
4
6
const projects = readdirSync ( 'ember-api-docs-data/json-docs' ) ;
@@ -9,16 +11,43 @@ module.exports = function () {
9
11
// add release for each of the projects
10
12
urls . push ( `/${ p } /release` ) ;
11
13
14
+ const fullProjectVersions = readdirSync (
15
+ `ember-api-docs-data/json-docs/${ p } `
16
+ ) . filter ( ( v ) => v . match ( / \d + \. \d + \. \d + / ) ) ;
17
+
12
18
// add landing page for each of the projects versions
13
- const projectVersions = readdirSync ( `ember-api-docs-data/json-docs/${ p } ` )
14
- . filter ( ( v ) => v . match ( / \d + \. \d + \. \d + / ) )
15
- . map ( ( v ) => {
16
- let [ , major , minor ] = v . match ( / ( \d + ) \. ( \d + ) \. \d + / ) ;
17
- return `${ major } .${ minor } ` ;
18
- } ) ; // uniq
19
-
20
- [ ...new Set ( projectVersions ) ] . forEach ( ( v ) => {
21
- urls . push ( `/${ p } /${ v } ` ) ;
19
+ const projectVersions = fullProjectVersions . map ( ( v ) => {
20
+ let [ , major , minor ] = v . match ( / ( \d + ) \. ( \d + ) \. \d + / ) ;
21
+ return `${ major } .${ minor } ` ;
22
+ } ) ; // uniq
23
+
24
+ const uniqueProjectVersions = [ ...new Set ( projectVersions ) ] ;
25
+
26
+ uniqueProjectVersions . forEach ( ( uniqVersion ) => {
27
+ urls . push ( `/${ p } /${ uniqVersion } ` ) ;
28
+
29
+ const sortedPatchVersions = fullProjectVersions
30
+ . filter ( ( projectVersion ) => {
31
+ // console.log("comparing", projectVersion, uniqVersion, semver.satisfies(projectVersion, uniqVersion))
32
+ return semver . satisfies ( projectVersion , uniqVersion ) ;
33
+ } )
34
+ . sort ( cmp ) ;
35
+
36
+ const highestPatchVersion =
37
+ sortedPatchVersions [ sortedPatchVersions . length - 1 ] ;
38
+
39
+ const revIndex = require ( `${ __dirname } /ember-api-docs-data/rev-index/${ p } -${ highestPatchVersion } .json` ) ;
40
+
41
+ [ 'classes' , 'namespaces' , 'modules' ] . forEach ( ( entity ) => {
42
+ // add classes
43
+ revIndex . data . relationships [ entity ] . data . forEach ( ( { id} ) => {
44
+ const [ , cleanId ] = id . match ( / ^ .+ - \d + \. \d + \. \d + - ( .* ) / ) ;
45
+ urls . push ( `/${ p } /${ uniqVersion } /${ entity } /${ cleanId } ` ) ;
46
+ urls . push ( `/${ p } /${ uniqVersion } /${ entity } /${ cleanId } /methods` ) ;
47
+ urls . push ( `/${ p } /${ uniqVersion } /${ entity } /${ cleanId } /properties` ) ;
48
+ urls . push ( `/${ p } /${ uniqVersion } /${ entity } /${ cleanId } /events` ) ;
49
+ } ) ;
50
+ } ) ;
22
51
} ) ;
23
52
} ) ;
24
53
@@ -31,4 +60,6 @@ if (process.env.DEBUG === 'prember-urls') {
31
60
let urls = module . exports ( ) ;
32
61
33
62
urls . forEach ( ( url ) => console . log ( url ) ) ;
63
+
64
+ console . log ( `\n${ urls . length } total URLs` ) ;
34
65
}
0 commit comments