ESLintify Part 3 (#846)

* ESLintify Part 3

* ESLintify Part 3

* ESLintify Part 3
This commit is contained in:
Yangshun Tay 2018-07-11 03:21:31 -07:00 committed by Endilie Yacop Sucipto
parent 5ac2cee658
commit a7a214fb3a
54 changed files with 435 additions and 497 deletions

View file

@ -23,7 +23,7 @@ async function execute() {
const chalk = require('chalk');
const Site = require('../core/Site.js');
const env = require('./env.js');
const siteConfig = require(CWD + '/siteConfig.js');
const siteConfig = require(`${CWD}/siteConfig.js`);
const translate = require('./translate.js');
const feed = require('./feed.js');
const sitemap = require('./sitemap.js');
@ -164,29 +164,29 @@ async function execute() {
Object.keys(mdToHtml).forEach(key => {
let link = mdToHtml[key];
link = utils.getPath(link, siteConfig.cleanUrl);
link = link.replace('/en/', '/' + language + '/');
link = link.replace('/en/', `/${language}/`);
link = link.replace(
'/VERSION/',
metadata.version && metadata.version !== defaultVersion
? '/' + metadata.version + '/'
? `/${metadata.version}/`
: '/'
);
// replace relative links without "./"
rawContent = rawContent.replace(
new RegExp('\\]\\(' + key, 'g'),
'](' + link
new RegExp(`\\]\\(${key}`, 'g'),
`](${link}`
);
// replace relative links with "./"
rawContent = rawContent.replace(
new RegExp('\\]\\(\\./' + key, 'g'),
'](' + link
new RegExp(`\\]\\(\\./${key}`, 'g'),
`](${link}`
);
});
// replace any relative links to static assets to absolute links
rawContent = rawContent.replace(
/\]\(assets\//g,
'](' + siteConfig.baseUrl + 'docs/assets/'
`](${siteConfig.baseUrl}docs/assets/`
);
const docComp = (
@ -305,7 +305,7 @@ async function execute() {
const targetFile = join(
buildDir,
'blog',
page > 0 ? 'page' + (page + 1) : '',
page > 0 ? `page${page + 1}` : '',
'index.html'
);
writeFileAndCreateFolder(targetFile, str);
@ -341,7 +341,7 @@ async function execute() {
let targetFile = path.normalize(file);
targetFile = join(
buildDir,
targetFile.split(sep + 'static' + sep)[1] || ''
targetFile.split(`${sep}static${sep}`)[1] || ''
);
// parse css files to replace colors according to siteConfig
if (file.match(/\.css$/)) {
@ -361,16 +361,16 @@ async function execute() {
Object.keys(siteConfig.colors).forEach(key => {
const color = siteConfig.colors[key];
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
cssContent = cssContent.replace(new RegExp(`\\$${key}`, 'g'), color);
});
if (siteConfig.fonts) {
Object.keys(siteConfig.fonts).forEach(key => {
const fontString = siteConfig.fonts[key]
.map(font => '"' + font + '"')
.map(font => `"${font}"`)
.join(', ');
cssContent = cssContent.replace(
new RegExp('\\$' + key, 'g'),
new RegExp(`\\$${key}`, 'g'),
fontString
);
});
@ -394,20 +394,20 @@ async function execute() {
if (normalizedFile.match(/\.css$/) && !isSeparateCss(normalizedFile)) {
const mainCss = join(buildDir, 'css', 'main.css');
let cssContent = fs.readFileSync(normalizedFile, 'utf8');
cssContent = fs.readFileSync(mainCss, 'utf8') + '\n' + cssContent;
cssContent = `${fs.readFileSync(mainCss, 'utf8')}\n${cssContent}`;
Object.keys(siteConfig.colors).forEach(key => {
const color = siteConfig.colors[key];
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
cssContent = cssContent.replace(new RegExp(`\\$${key}`, 'g'), color);
});
if (siteConfig.fonts) {
Object.keys(siteConfig.fonts).forEach(key => {
const fontString = siteConfig.fonts[key]
.map(font => '"' + font + '"')
.map(font => `"${font}"`)
.join(', ');
cssContent = cssContent.replace(
new RegExp('\\$' + key, 'g'),
new RegExp(`\\$${key}`, 'g'),
fontString
);
});
@ -418,7 +418,7 @@ async function execute() {
normalizedFile.match(/\.png$|.jpg$|.svg$|.gif$/) &&
!commander.skipImageCompression
) {
const parts = normalizedFile.split(sep + 'static' + sep);
const parts = normalizedFile.split(`${sep}static${sep}`);
const targetDirectory = join(
buildDir,
parts[1].substring(0, parts[1].lastIndexOf(sep))
@ -435,7 +435,7 @@ async function execute() {
],
});
} else if (!fs.lstatSync(normalizedFile).isDirectory()) {
const parts = normalizedFile.split(sep + 'static' + sep);
const parts = normalizedFile.split(`${sep}static${sep}`);
const targetFile = join(buildDir, parts[1]);
mkdirp.sync(path.dirname(targetFile));
fs.copySync(normalizedFile, targetFile);
@ -463,7 +463,7 @@ async function execute() {
let tempFile = join(__dirname, '..', 'pages', parts[1]);
tempFile = tempFile.replace(
path.basename(normalizedFile),
'temp' + path.basename(normalizedFile)
`temp${path.basename(normalizedFile)}`
);
mkdirp.sync(path.dirname(tempFile));
fs.copySync(normalizedFile, tempFile);
@ -474,9 +474,9 @@ async function execute() {
targetFile = targetFile.replace(/\.js$/, '.html');
const regexLang = new RegExp(
escapeStringRegexp(sep + 'pages' + sep) +
'(.*)' +
escapeStringRegexp(sep)
`${escapeStringRegexp(`${sep}pages${sep}`)}(.*)${escapeStringRegexp(
sep
)}`
);
const match = regexLang.exec(normalizedFile);
const langParts = match[1].split(sep);
@ -488,7 +488,7 @@ async function execute() {
if (
language === 'en' ||
!fs.existsSync(
normalizedFile.replace(sep + 'en' + sep, sep + language + sep)
normalizedFile.replace(`${sep}en${sep}`, sep + language + sep)
)
) {
translate.setLanguage(language);
@ -504,7 +504,7 @@ async function execute() {
);
writeFileAndCreateFolder(
// TODO: use path functions
targetFile.replace(sep + 'en' + sep, sep + language + sep),
targetFile.replace(`${sep}en${sep}`, sep + language + sep),
str
);
}
@ -524,7 +524,7 @@ async function execute() {
</Site>
);
writeFileAndCreateFolder(
targetFile.replace(sep + 'en' + sep, sep),
targetFile.replace(`${sep}en${sep}`, sep),
str
);
} else {
@ -542,7 +542,7 @@ async function execute() {
</Site>
);
writeFileAndCreateFolder(
targetFile.replace(sep + 'en' + sep, sep),
targetFile.replace(`${sep}en${sep}`, sep),
str
);
}