Skip to content

Commit 57678f5

Browse files
committed
chore(scripts/website): enable lint for file
1 parent a926772 commit 57678f5

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = {
77
ignorePatterns: [
88
'tools',
99
'dist',
10-
'website.js',
1110
'test/files/*',
1211
'benchmarks',
1312
'*.min.js',

scripts/website.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const path = require('path');
99
const pug = require('pug');
1010
const pkg = require('../package.json');
1111
const transform = require('acquit-require');
12-
const childProcess = require("child_process");
12+
const childProcess = require('child_process');
1313

1414
// using "__dirname" and ".." to have a consistent CWD, this script should not be runnable, even when not being in the root of the project
1515
// also a consistent root path so that it is easy to change later when the script should be moved
@@ -183,8 +183,8 @@ function parseVersion(str) {
183183

184184
const match = versionReg.exec(str);
185185

186-
if (!!match) {
187-
const parsed = [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])]
186+
if (match) {
187+
const parsed = [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])];
188188

189189
// fallback just in case some number did not parse
190190
if (Number.isNaN(parsed[0]) || Number.isNaN(parsed[1]) || Number.isNaN(parsed[2])) {
@@ -195,7 +195,7 @@ function parseVersion(str) {
195195
}
196196

197197
// special case, to not log a warning
198-
if (str === "test") {
198+
if (str === 'test') {
199199
return undefined;
200200
}
201201

@@ -210,27 +210,27 @@ function parseVersion(str) {
210210
function getVersions() {
211211
// get all tags from git
212212
// "trim" is used to remove the ending new-line
213-
const res = childProcess.execSync("git tag").toString().trim();
213+
const res = childProcess.execSync('git tag').toString().trim();
214214

215215
filteredTags = res.split('\n')
216216
// map all gotten tags if they match the regular expression
217-
.map(parseVersion)
217+
.map(parseVersion)
218218
// filter out all null / undefined / falsy values
219-
.filter(v => !!v)
219+
.filter(v => !!v)
220220
// sort tags with latest (highest) first
221-
.sort((a, b) => {
222-
if (a[0] === b[0]) {
223-
if (a[1] === b[1]) {
224-
return b[2] - a[2];
221+
.sort((a, b) => {
222+
if (a[0] === b[0]) {
223+
if (a[1] === b[1]) {
224+
return b[2] - a[2];
225+
}
226+
return b[1] - a[1];
225227
}
226-
return b[1] - a[1];
227-
}
228-
return b[0] - a[0];
229-
});
228+
return b[0] - a[0];
229+
});
230230

231231
if (filteredTags.length === 0) {
232-
console.error("no tags found!");
233-
filteredTags.push([0,0,0]);
232+
console.error('no tags found!');
233+
filteredTags.push([0, 0, 0]);
234234
}
235235
}
236236

@@ -269,7 +269,7 @@ function getLatestVersionOf(version) {
269269
foundVersion = [0, 0, 0];
270270
}
271271

272-
return {listed: stringifySemverNumber(foundVersion), path: stringifySemverNumber(foundVersion, true)};
272+
return { listed: stringifySemverNumber(foundVersion), path: stringifySemverNumber(foundVersion, true) };
273273
}
274274

275275
/**
@@ -281,11 +281,11 @@ function getCurrentVersion() {
281281

282282
// i dont think this will ever happen, but just in case
283283
if (!pkg.version) {
284-
console.log("no version from package?");
284+
console.log('no version from package?');
285285
versionToUse = getLatestVersion();
286286
}
287287

288-
return {listed: versionToUse, path: stringifySemverNumber(parseVersion(versionToUse), true) };
288+
return { listed: versionToUse, path: stringifySemverNumber(parseVersion(versionToUse), true) };
289289
}
290290

291291
// execute function to get all tags from git
@@ -314,7 +314,7 @@ const versionObj = (() => {
314314
getLatestVersionOf(6)
315315
]
316316
};
317-
const versionedDeploy = !!process.env.DOCS_DEPLOY ? !(base.currentVersion.listed === base.latestVersion.listed) : false;
317+
const versionedDeploy = process.env.DOCS_DEPLOY ? !(base.currentVersion.listed === base.latestVersion.listed) : false;
318318

319319
const versionedPath = versionedDeploy ? `/docs/${base.currentVersion.path}` : '';
320320

@@ -380,20 +380,20 @@ function mapURLs(block, currentUrl) {
380380
while ((match = mongooseComRegex.exec(block)) !== null) {
381381
// console.log("match", match);
382382
// cant just use "match.index" byitself, because of the extra "href=\"" condition, which is not factored in in "match.index"
383-
let startIndex = match.index + match[0].length - match[1].length;
383+
const startIndex = match.index + match[0].length - match[1].length;
384384
out += block.slice(lastIndex, startIndex);
385385
lastIndex = startIndex + match[1].length;
386386

387387
// somewhat primitive gathering of the url, but should be enough for now
388-
let fullUrl = /^\/[^"]+/.exec(block.slice(lastIndex-1));
388+
const fullUrl = /^\/[^"]+/.exec(block.slice(lastIndex - 1));
389389

390390
let noPrefix = false;
391391

392392
if (fullUrl) {
393393
// extra processing to only use "#otherId" instead of using full url for the same page
394394
// at least firefox does not make a difference between a full path and just "#", but it makes debugging paths easier
395395
if (fullUrl[0].startsWith(currentUrl)) {
396-
let indexMatch = /#/.exec(fullUrl);
396+
const indexMatch = /#/.exec(fullUrl);
397397

398398
if (indexMatch) {
399399
lastIndex += indexMatch.index - 1;
@@ -404,10 +404,10 @@ function mapURLs(block, currentUrl) {
404404

405405
if (!noPrefix) {
406406
// map all to the versioned-path, unless a explicit version is given
407-
if (!versionedDocs.test(block.slice(lastIndex, lastIndex+10))) {
408-
out += versionObj.versionedPath + "/";
407+
if (!versionedDocs.test(block.slice(lastIndex, lastIndex + 10))) {
408+
out += versionObj.versionedPath + '/';
409409
} else {
410-
out += "/";
410+
out += '/';
411411
}
412412
}
413413
}
@@ -429,7 +429,7 @@ async function pugify(filename, options, isReload = false) {
429429
let newfile = undefined;
430430
options = options || {};
431431
options.package = pkg;
432-
const isAPI = options.api && !filename.endsWith('docs/api.pug');
432+
// const isAPI = options.api && !filename.endsWith('docs/api.pug');
433433

434434
const _editLink = 'https://github.com/Automattic/mongoose/blob/master' +
435435
filename.replace(cwd, '');
@@ -443,7 +443,7 @@ async function pugify(filename, options, isReload = false) {
443443
if (isReload) {
444444
apiReq.parseFile(options.file);
445445
// overwrite original options because of reload
446-
options = {...options, ...apiReq.docs.get(options.file)};
446+
options = { ...options, ...apiReq.docs.get(options.file) };
447447
}
448448
inputFile = path.resolve(cwd, 'docs/api_split.pug');
449449
}
@@ -453,7 +453,7 @@ async function pugify(filename, options, isReload = false) {
453453
if (options.acquit) {
454454
contents = transform(contents, getTests());
455455

456-
contents = contents.replaceAll(/^```acquit$/gmi, "```javascript");
456+
contents = contents.replaceAll(/^```acquit$/gmi, '```javascript');
457457
}
458458
if (options.markdown) {
459459
const lines = contents.split('\n');
@@ -486,7 +486,7 @@ async function pugify(filename, options, isReload = false) {
486486

487487
if (versionObj.versionedDeploy) {
488488
newfile = path.resolve(cwd, path.join('.', versionObj.versionedPath), path.relative(cwd, newfile));
489-
await fs.promises.mkdir(path.dirname(newfile), {recursive:true});
489+
await fs.promises.mkdir(path.dirname(newfile), { recursive: true });
490490
}
491491

492492
options.outputUrl = newfile.replace(cwd, '');
@@ -497,11 +497,11 @@ async function pugify(filename, options, isReload = false) {
497497

498498
let str = await pugRender(contents, options).catch(console.error);
499499

500-
if (typeof str !== "string") {
500+
if (typeof str !== 'string') {
501501
return;
502502
}
503503

504-
str = mapURLs(str, '/' + path.relative(cwd, docsPath))
504+
str = mapURLs(str, '/' + path.relative(cwd, docsPath));
505505

506506
await fs.promises.writeFile(newfile, str).catch((err) => {
507507
console.error('could not write', err.stack);
@@ -534,20 +534,20 @@ function startWatch() {
534534
}
535535
});
536536

537-
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), {interval: 1000}, (cur, prev) => {
537+
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), { interval: 1000 }, (cur, prev) => {
538538
if (cur.mtime > prev.mtime) {
539539
console.log('docs/api_split.pug modified, reloading all api files');
540-
Promise.all(files.filter(v=> v.startsWith('docs/api')).map(async (file) => {
540+
Promise.all(files.filter(v => v.startsWith('docs/api')).map(async(file) => {
541541
const filename = path.join(cwd, file);
542542
await pugify(filename, docsFilemap.fileMap[file], true);
543543
}));
544544
}
545545
});
546546

547-
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), {interval: 1000}, (cur, prev) => {
547+
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), { interval: 1000 }, (cur, prev) => {
548548
if (cur.mtime > prev.mtime) {
549549
console.log('docs/api_split.pug modified, reloading all api files');
550-
Promise.all(files.filter(v=> v.startsWith('docs/api')).map(async (file) => {
550+
Promise.all(files.filter(v => v.startsWith('docs/api')).map(async(file) => {
551551
const filename = path.join(cwd, file);
552552
await pugify(filename, docsFilemap.fileMap[file]);
553553
}));
@@ -561,7 +561,7 @@ function startWatch() {
561561
* @param {Boolean} isReload Indicate this is a reload of all files
562562
*/
563563
async function pugifyAllFiles(noWatch, isReload = false) {
564-
await Promise.all(files.map(async (file) => {
564+
await Promise.all(files.map(async(file) => {
565565
const filename = path.join(cwd, file);
566566
await pugify(filename, docsFilemap.fileMap[file], isReload);
567567
}));
@@ -590,7 +590,7 @@ async function copyAllRequiredFiles() {
590590
await Promise.all(pathsToCopy.map(async v => {
591591
const resultPath = path.resolve(cwd, path.join('.', versionObj.versionedPath, v));
592592
await fsextra.copy(v, resultPath);
593-
}))
593+
}));
594594
}
595595

596596
exports.default = pugify;

0 commit comments

Comments
 (0)