ESLintify Part 1 (#837)

* ESLint-ify

* Allow empty try/catch

* Escape regexp
This commit is contained in:
Yangshun Tay 2018-07-08 09:13:18 -07:00 committed by GitHub
parent 128dbfca0a
commit e8e3f42685
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 466 additions and 555 deletions

View file

@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
/* eslint-disable no-cond-assign */
function execute(port, options) {
const extractTranslations = require('../write-translations');
@ -45,8 +47,18 @@ function execute(port, options) {
const join = path.join;
const sep = path.sep;
// remove a module and child modules from require cache, so server does not have
// to be restarted
function removeModulePathFromCache(moduleName) {
/* eslint-disable no-underscore-dangle */
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
if (cacheKey.indexOf(moduleName) > 0) {
delete module.constructor._pathCache[cacheKey];
}
});
/* eslint-enable no-underscore-dangle */
}
// Remove a module and child modules from require cache, so server
// does not have to be restarted.
function removeModuleAndChildrenFromCache(moduleName) {
let mod = require.resolve(moduleName);
if (mod && (mod = require.cache[mod])) {
@ -59,14 +71,6 @@ function execute(port, options) {
}
}
function removeModulePathFromCache(moduleName) {
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
if (cacheKey.indexOf(moduleName) > 0) {
delete module.constructor._pathCache[cacheKey];
}
});
}
/****************************************************************************/
let readMetadata = require('./readMetadata.js');
@ -147,6 +151,36 @@ function execute(port, options) {
});
}
function startLiveReload() {
// Start LiveReload server.
process.env.NODE_ENV = 'development';
const server = tinylr();
server.listen(constants.LIVE_RELOAD_PORT, function() {
console.log(
'LiveReload server started on port %d',
constants.LIVE_RELOAD_PORT
);
});
// gaze watches some specified dirs and triggers a callback when they change.
gaze(
[
'../' + readMetadata.getDocsPath() + '/**/*', // docs
'**/*', // website
'!node_modules/**/*', // node_modules
],
function() {
// Listen for all kinds of file changes - modified/added/deleted.
this.on('all', function() {
// Notify LiveReload clients that there's a change.
// Typically, LiveReload will only refresh the changed paths,
// so we use / here to force a full-page reload.
server.notifyClients(['/']);
});
}
);
}
/****************************************************************************/
reloadMetadata();
@ -200,12 +234,10 @@ function execute(port, options) {
} else {
file = join(CWD, 'versioned_docs', metadata.source);
}
} else if (!env.translation.enabled || metadata.language === 'en') {
file = join(CWD, '..', readMetadata.getDocsPath(), metadata.source);
} else {
if (!env.translation.enabled || metadata.language === 'en') {
file = join(CWD, '..', readMetadata.getDocsPath(), metadata.source);
} else {
file = join(CWD, 'translated_docs', metadata.language, metadata.source);
}
file = join(CWD, 'translated_docs', metadata.language, metadata.source);
}
if (!fs.existsSync(file)) {
@ -225,7 +257,7 @@ function execute(port, options) {
let defaultVersion = env.versioning.defaultVersion;
// replace any links to markdown files to their website html links
Object.keys(mdToHtml).forEach(function(key, index) {
Object.keys(mdToHtml).forEach(key => {
let link = mdToHtml[key];
link = utils.getPath(link, siteConfig.cleanUrl);
link = link.replace('/en/', '/' + language + '/');
@ -333,8 +365,8 @@ function execute(port, options) {
);
const str = renderToStaticMarkupWithDoctype(blogPageComp);
let path = (page > 0 ? 'page' + (page + 1) : '') + '/index.html';
blogPages[path] = str;
const pagePath = (page > 0 ? 'page' + (page + 1) : '') + '/index.html';
blogPages[pagePath] = str;
}
let parts = req.path.toString().split('blog/');
@ -398,7 +430,7 @@ function execute(port, options) {
// handle all other main pages
app.get(pageRouting(siteConfig.baseUrl), (req, res, next) => {
// look for user provided html file first
// Look for user-provided HTML file first.
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, '');
htmlFile = join(CWD, 'pages', htmlFile);
if (
@ -470,8 +502,8 @@ function execute(port, options) {
fs.existsSync((userFile = englishFile))
) {
// copy into docusaurus so require paths work
let parts = userFile.split('pages' + sep);
let tempFile = join(__dirname, '..', 'pages', parts[1]);
let userFileParts = userFile.split('pages' + sep);
let tempFile = join(__dirname, '..', 'pages', userFileParts[1]);
tempFile = tempFile.replace(
path.basename(file),
'temp' + path.basename(file)
@ -501,7 +533,6 @@ function execute(port, options) {
res.send(str);
} else {
next();
return;
}
});
@ -598,36 +629,6 @@ function execute(port, options) {
if (options.watch) startLiveReload();
app.listen(port);
function startLiveReload() {
// Start LiveReload server.
process.env.NODE_ENV = 'development';
const server = tinylr();
server.listen(constants.LIVE_RELOAD_PORT, function() {
console.log(
'LiveReload server started on port %d',
constants.LIVE_RELOAD_PORT
);
});
// gaze watches some specified dirs and triggers a callback when they change.
gaze(
[
'../' + readMetadata.getDocsPath() + '/**/*', // docs
'**/*', // website
'!node_modules/**/*', // node_modules
],
function() {
// Listen for all kinds of file changes - modified/added/deleted.
this.on('all', function() {
// Notify LiveReload clients that there's a change.
// Typically, LiveReload will only refresh the changed paths,
// so we use / here to force a full-page reload.
server.notifyClients(['/']);
});
}
);
}
}
module.exports = execute;