@@ -13,11 +13,11 @@ const shortIndexFile = path.join(pagesPath, 'shortIndex.json');
13
13
function findPlatform ( page , preferredPlatform , done ) {
14
14
// Load the index
15
15
getShortIndex ( ( idx ) => {
16
- // First checking whether page is there or not
16
+ // First, check whether page is in the index
17
17
if ( ! ( page in idx ) ) {
18
18
return done ( null ) ;
19
19
}
20
- // Getting the platforms
20
+ // Get the platforms
21
21
let platforms = idx [ page ] ;
22
22
if ( platforms . indexOf ( preferredPlatform ) >= 0 ) {
23
23
return done ( preferredPlatform ) ;
@@ -28,29 +28,32 @@ function findPlatform(page, preferredPlatform, done) {
28
28
} ) ;
29
29
}
30
30
31
- // hasPage is always called after index is created, hence just return the variable
32
- // in memory. There is no need to re-read the index file again.
31
+ // hasPage is always called after the index is created,
32
+ // hence just return the variable in memory.
33
+ // There is no need to re-read the index file again.
33
34
function hasPage ( page ) {
34
35
if ( ! shortIndex ) {
35
36
return false ;
36
37
}
37
38
return page in shortIndex ;
38
39
}
39
40
40
- // This returns all commands available in the local cache
41
+ // Return all commands available in the local cache.
41
42
function commands ( done ) {
42
43
getShortIndex ( ( idx ) => {
43
44
return done ( Object . keys ( idx ) . sort ( ) ) ;
44
45
} ) ;
45
46
}
46
47
47
- // This returns all commands for a given platform.
48
+ // Return all commands for a given platform.
48
49
// P.S. - The platform 'common' is always included.
49
50
function commandsFor ( platform , done ) {
50
51
getShortIndex ( ( idx ) => {
51
52
let commands = Object . keys ( idx )
52
53
. filter ( ( cmd ) => {
53
- /* eslint-disable */ // To allow using -1 to check if it contains in the array
54
+ // ESLint is disabled for this statement, to allow using -1
55
+ // to check if a command is contained in the array.
56
+ /* eslint-disable */
54
57
return idx [ cmd ] . indexOf ( platform ) !== - 1
55
58
|| idx [ cmd ] . indexOf ( 'common' ) !== - 1 ;
56
59
/* eslint-enable */
@@ -60,15 +63,15 @@ function commandsFor(platform, done) {
60
63
} ) ;
61
64
}
62
65
63
- // Delete the index file
66
+ // Delete the index file.
64
67
function clearPagesIndex ( done ) {
65
68
fs . unlink ( shortIndexFile , ( ) => {
66
69
clearRuntimeIndex ( ) ;
67
70
done ( ) ;
68
71
} ) ;
69
72
}
70
73
71
- // Set the variable to null
74
+ // Set the shortIndex variable to null.
72
75
function clearRuntimeIndex ( ) {
73
76
shortIndex = null ;
74
77
}
@@ -82,21 +85,21 @@ function rebuildPagesIndex(done) {
82
85
}
83
86
84
87
// If the variable is not set, read the file and set it.
85
- // Else, just return the variable
88
+ // Else, just return the variable.
86
89
function getShortIndex ( done ) {
87
90
if ( ! shortIndex ) {
88
91
return readShortPagesIndex ( done ) ;
89
92
}
90
93
return done ( shortIndex ) ;
91
94
}
92
95
93
- // Reads the index file, and loads it into memory.
94
- // If the file is not created , create the data structure, write the file, and load
95
- // it into memory
96
+ // Read the index file, and load it into memory.
97
+ // If the file does not exist , create the data structure, write the file,
98
+ // and load it into memory.
96
99
function readShortPagesIndex ( done ) {
97
100
fs . readFile ( shortIndexFile , 'utf8' , ( err , idx ) => {
98
- // file is not present, need to create the index
99
101
if ( err ) {
102
+ // File is not present; we need to create the index.
100
103
idx = buildShortPagesIndex ( ) ;
101
104
if ( Object . keys ( idx ) . length > 0 ) {
102
105
fs . writeFile ( shortIndexFile , JSON . stringify ( idx ) , ( err ) => {
@@ -109,7 +112,9 @@ function readShortPagesIndex(done) {
109
112
} else {
110
113
return done ( idx ) ;
111
114
}
112
- } else { // Just parse and set shortIndex variable, then return the value
115
+ } else {
116
+ // File is present, so just parse and set the shortIndex variable,
117
+ // then return the value.
113
118
idx = JSON . parse ( idx ) ;
114
119
shortIndex = idx ;
115
120
return done ( idx ) ;
0 commit comments