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

@ -22,8 +22,8 @@ const env = require('./server/env.js');
const CWD = process.cwd();
let versions;
if (fs.existsSync(CWD + '/versions.json')) {
versions = require(CWD + '/versions.json');
if (fs.existsSync(`${CWD}/versions.json`)) {
versions = require(`${CWD}/versions.json`);
} else {
versions = [];
}
@ -63,7 +63,7 @@ if (versions.includes(version)) {
function makeHeader(metadata) {
let header = '---\n';
Object.keys(metadata).forEach(key => {
header += key + ': ' + metadata[key] + '\n';
header += `${key}: ${metadata[key]}\n`;
});
header += '---\n';
return header;
@ -75,12 +75,12 @@ function writeFileAndCreateFolder(file, content, encoding) {
fs.writeFileSync(file, content, encoding);
}
const versionFolder = CWD + '/versioned_docs/version-' + version;
const versionFolder = `${CWD}/versioned_docs/version-${version}`;
mkdirp.sync(versionFolder);
// copy necessary files to new version, changing some of its metadata to reflect the versioning
const files = glob.sync(CWD + '/../' + readMetadata.getDocsPath() + '/**');
const files = glob.sync(`${CWD}/../${readMetadata.getDocsPath()}/**`);
files.forEach(file => {
const ext = path.extname(file);
if (ext !== '.md' && ext !== '.markdown') {
@ -109,7 +109,7 @@ files.forEach(file => {
}
metadata.original_id = metadata.id;
metadata.id = 'version-' + version + '-' + metadata.id;
metadata.id = `version-${version}-${metadata.id}`;
const docsDir = path.join(CWD, '../', readMetadata.getDocsPath());
const subDir = utils.getSubDir(file, docsDir);
@ -126,12 +126,12 @@ files.forEach(file => {
// copy sidebar if necessary
if (versionFallback.diffLatestSidebar()) {
mkdirp(CWD + '/versioned_sidebars');
const sidebar = JSON.parse(fs.readFileSync(CWD + '/sidebars.json', 'utf8'));
mkdirp(`${CWD}/versioned_sidebars`);
const sidebar = JSON.parse(fs.readFileSync(`${CWD}/sidebars.json`, 'utf8'));
const versioned = {};
Object.keys(sidebar).forEach(sb => {
const versionSidebar = 'version-' + version + '-' + sb;
const versionSidebar = `version-${version}-${sb}`;
versioned[versionSidebar] = {};
const categories = sidebar[sb];
@ -140,16 +140,14 @@ if (versionFallback.diffLatestSidebar()) {
const ids = categories[category];
ids.forEach(id => {
versioned[versionSidebar][category].push(
'version-' + version + '-' + id
);
versioned[versionSidebar][category].push(`version-${version}-${id}`);
});
});
});
fs.writeFileSync(
CWD + '/versioned_sidebars/version-' + version + '-sidebars.json',
JSON.stringify(versioned, null, 2) + '\n',
`${CWD}/versioned_sidebars/version-${version}-sidebars.json`,
`${JSON.stringify(versioned, null, 2)}\n`,
'utf8'
);
}
@ -157,8 +155,8 @@ if (versionFallback.diffLatestSidebar()) {
// update versions.json file
versions.unshift(version);
fs.writeFileSync(
CWD + '/versions.json',
JSON.stringify(versions, null, 2) + '\n'
`${CWD}/versions.json`,
`${JSON.stringify(versions, null, 2)}\n`
);
console.log(`${chalk.green('Version ' + version + ' created!\n')}`);
console.log(`${chalk.green(`Version ${version} created!\n`)}`);