Skip to content

Commit 012e728

Browse files
committed
run lint:fix
1 parent 8bca4be commit 012e728

File tree

9 files changed

+162
-203
lines changed

9 files changed

+162
-203
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ module.exports = {
77
sourceType: 'module',
88
requireConfigFile: false,
99
},
10-
extends: [
11-
'eslint:recommended',
12-
'plugin:n/recommended',
13-
'plugin:prettier/recommended',
14-
],
10+
extends: ['eslint:recommended', 'plugin:n/recommended', 'plugin:prettier/recommended'],
1511
env: {
1612
node: true,
1713
browser: false,

index.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import program from 'commander';
22

3-
import { runApi } from './lib/api.js'
3+
import { runApi } from './lib/api.js';
44

55
program
6-
.option(
7-
'-c, --clear-index',
8-
'Whether indexes of the project should be cleared while processing'
9-
)
10-
.option('-j, --json-driver', 'Use the json driver instead of algolia')
6+
.option('-c, --clear-index', 'Whether indexes of the project should be cleared while processing')
7+
.option('-j, --json-driver', 'Use the json driver instead of algolia');
118

12-
program.on('--help', function() {
9+
program.on('--help', function () {
1310
console.log(`
1411
Examples:
1512
$ npm start
1613
$ npm start -- -j # to write to fs
1714
$ npm start -- -c # Clear indexes before populating content
18-
`)
19-
})
15+
`);
16+
});
2017

21-
program.parse(process.argv)
18+
program.parse(process.argv);
2219

23-
runApi(program.clearIndex, program.jsonDriver)
20+
runApi(program.clearIndex, program.jsonDriver);

lib/api.js

Lines changed: 88 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,77 @@
1-
import 'dotenv/config'
1+
import 'dotenv/config';
22

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';
66

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';
1010

1111
const { readJsonSync } = fsExtra;
1212

13-
const apiIndexes = ['modules', 'classes', 'methods', 'versions']
13+
const apiIndexes = ['modules', 'classes', 'methods', 'versions'];
1414

1515
export async function runApi(clearIndex = false, useJsonDriver = false) {
16-
let driver = useJsonDriver ? jsonDriver : algoliaDriver
16+
let driver = useJsonDriver ? jsonDriver : algoliaDriver;
1717

18-
apiIndexes.map(driver.init)
18+
apiIndexes.map(driver.init);
1919

2020
if (clearIndex) {
21-
apiIndexes.map(driver.clear)
21+
apiIndexes.map(driver.clear);
2222
}
2323

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')]);
2825
}
2926

3027
async function processDocs(driver, project) {
31-
let prevIndexedVersions = await driver.getPreviouslyIndexedVersions(project)
28+
let prevIndexedVersions = await driver.getPreviouslyIndexedVersions(project);
3229

3330
const {
3431
meta: { availableVersions },
35-
} = readJsonSync(`../ember-api-docs-data/rev-index/${project}.json`)
32+
} = readJsonSync(`../ember-api-docs-data/rev-index/${project}.json`);
3633

37-
let versionsToProcess = difference(availableVersions, prevIndexedVersions)
34+
let versionsToProcess = difference(availableVersions, prevIndexedVersions);
3835

3936
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;
4239
}
4340

4441
try {
4542
// iterate versions and drop latest minor of each major in buckets
4643
// make an array of the latest minors you get
4744
let latestPatches = Object.values(versionsToProcess.reduce(addIfLatestPatch, {}));
48-
console.log(`Processing ${project} for versions: ${latestPatches}`)
45+
console.log(`Processing ${project} for versions: ${latestPatches}`);
4946
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))
5249
// Fetch all public modules and public classes
53-
.map(versionIndexObject =>
54-
fetchPublicModuleClassesForVersion(versionIndexObject, project)
55-
)
50+
.map((versionIndexObject) => fetchPublicModuleClassesForVersion(versionIndexObject, project))
5651
// Run the schema against all data stored
5752
.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);
6255

6356
await driver.write(
6457
'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+
],
7166
project
72-
)
67+
);
7368
} catch (err) {
74-
console.log('Error:: ', err)
69+
console.log('Error:: ', err);
7570
}
7671
}
7772

7873
function addIfLatestPatch(latestPatches, version) {
79-
let semvers = version.split('.')
74+
let semvers = version.split('.');
8075
let major = semvers[0];
8176
let minor = semvers[1];
8277
let minorVersion = `${major}.${minor}`;
@@ -89,56 +84,52 @@ function addIfLatestPatch(latestPatches, version) {
8984
}
9085

9186
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;
9489
try {
95-
readJsonSync(emberVersionJSONPath)
96-
} catch(e) {
97-
isIncluded = false
90+
readJsonSync(emberVersionJSONPath);
91+
} catch (e) {
92+
isIncluded = false;
9893
}
99-
return isIncluded
94+
return isIncluded;
10095
}
10196

10297
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);
106101
}
107102

108103
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);
116125
}
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+
);
136127

137128
return {
138129
version: versionIndexObject,
139130
publicModules,
140131
publicClasses,
141-
}
132+
};
142133
}
143134

144135
/**
@@ -148,39 +139,33 @@ function fetchPublicModuleClassesForVersion(versionIndexObject, libName) {
148139
* @returns {object} - Extended version object with methods & mapped schemas
149140
*/
150141
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);
155144

156145
return {
157146
...versionObject,
158147
methods: [...methods, ...staticFunctions],
159148
publicModules: versionObject.publicModules.map(schemas.moduleSchema),
160149
publicClasses: versionObject.publicClasses.map(schemas.classSchema),
161-
}
150+
};
162151
}
163152

164153
function writeToDriver(driver, versionObject) {
165-
const { id } = versionObject.version.data
154+
const { id } = versionObject.version.data;
166155

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('-');
170159

171160
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+
);
178163

179164
return Promise.all([
180165
driver.write('modules', versionObject.publicModules, projectName, version),
181166
driver.write('classes', versionObject.publicClasses, projectName, version),
182167
driver.write('methods', versionObject.methods, projectName, version),
183-
])
168+
]);
184169
}
185170

186171
/**
@@ -195,34 +180,34 @@ function extractMethodsFromClasses(classes) {
195180
currentClass.data.attributes.methods
196181
.reduce((classMethods, currentMethod) => {
197182
// 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;
200185
}, [])
201186
// Merge all methods of all classes into a single array
202187
.concat(methods)
203-
)
204-
}, [])
188+
);
189+
}, []);
205190
}
206191

207192
function extractStaticFunctionsFromModules(modules) {
208193
return modules.reduce((methods, currentModule) => {
209-
const staticfunctionsObj = currentModule.data.attributes.staticfunctions
194+
const staticfunctionsObj = currentModule.data.attributes.staticfunctions;
210195

211196
// Guard against staticfunctions not existing.
212-
if (!staticfunctionsObj) return methods
197+
if (!staticfunctionsObj) return methods;
213198
// Extract all the static functions from inside their sub-modules
214199
const moduleStaticFunctions = Object.keys(staticfunctionsObj).reduce(
215200
(prevStaticFunctions, currModuleName) => {
216-
return prevStaticFunctions.concat(staticfunctionsObj[currModuleName])
201+
return prevStaticFunctions.concat(staticfunctionsObj[currModuleName]);
217202
},
218203
[]
219-
)
204+
);
220205

221206
return moduleStaticFunctions
222207
.reduce((moduleStaticFunctions, currentStaticFunction) => {
223-
moduleStaticFunctions.push(schemas.methodSchema(currentStaticFunction, currentModule))
224-
return moduleStaticFunctions
208+
moduleStaticFunctions.push(schemas.methodSchema(currentStaticFunction, currentModule));
209+
return moduleStaticFunctions;
225210
}, [])
226-
.concat(methods)
227-
}, [])
211+
.concat(methods);
212+
}, []);
228213
}

0 commit comments

Comments
 (0)