mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-01 02:12:36 +02:00
ESLintify Part 3 (#846)
* ESLintify Part 3 * ESLintify Part 3 * ESLintify Part 3
This commit is contained in:
parent
5ac2cee658
commit
a7a214fb3a
54 changed files with 435 additions and 497 deletions
|
@ -22,7 +22,7 @@ const CWD = process.cwd();
|
|||
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;
|
||||
|
@ -54,7 +54,7 @@ if (
|
|||
}
|
||||
|
||||
// error if no versions currently exist
|
||||
if (!fs.existsSync(CWD + '/versions.json')) {
|
||||
if (!fs.existsSync(`${CWD}/versions.json`)) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
'No versions found!'
|
||||
|
@ -63,14 +63,14 @@ if (!fs.existsSync(CWD + '/versions.json')) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
const versions = JSON.parse(fs.readFileSync(CWD + '/versions.json', 'utf8'));
|
||||
const versions = JSON.parse(fs.readFileSync(`${CWD}/versions.json`, 'utf8'));
|
||||
|
||||
const versionIndex = versions.indexOf(currentVersion);
|
||||
// error if current specified version does not exist
|
||||
if (versionIndex < 0) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
'Version ' + currentVersion + ' does not currently exist!'
|
||||
`Version ${currentVersion} does not currently exist!`
|
||||
)}\n Version ${currentVersion} is not in the versions.json file. You can only rename existing versions.`
|
||||
);
|
||||
process.exit(1);
|
||||
|
@ -78,19 +78,19 @@ if (versionIndex < 0) {
|
|||
// replace old version with new version in versions.json file
|
||||
versions[versionIndex] = newVersion;
|
||||
fs.writeFileSync(
|
||||
CWD + '/versions.json',
|
||||
JSON.stringify(versions, null, 2) + '\n'
|
||||
`${CWD}/versions.json`,
|
||||
`${JSON.stringify(versions, null, 2)}\n`
|
||||
);
|
||||
|
||||
// if folder of docs for this version exists, rename folder and rewrite doc
|
||||
// headers to use new version
|
||||
if (fs.existsSync(CWD + '/versioned_docs/version-' + currentVersion)) {
|
||||
if (fs.existsSync(`${CWD}/versioned_docs/version-${currentVersion}`)) {
|
||||
fs.renameSync(
|
||||
CWD + '/versioned_docs/version-' + currentVersion,
|
||||
CWD + '/versioned_docs/version-' + newVersion
|
||||
`${CWD}/versioned_docs/version-${currentVersion}`,
|
||||
`${CWD}/versioned_docs/version-${newVersion}`
|
||||
);
|
||||
|
||||
const files = glob.sync(CWD + '/versioned_docs/version-' + newVersion + '/*');
|
||||
const files = glob.sync(`${CWD}/versioned_docs/version-${newVersion}/*`);
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
|
@ -112,10 +112,8 @@ if (fs.existsSync(CWD + '/versioned_docs/version-' + currentVersion)) {
|
|||
|
||||
// if sidebar file exists for this version, rename sidebar file and rewrite
|
||||
// doc ids in the file
|
||||
const currentSidebarFile =
|
||||
CWD + '/versioned_sidebars/version-' + currentVersion + '-sidebars.json';
|
||||
const newSidebarFile =
|
||||
CWD + '/versioned_sidebars/version-' + newVersion + '-sidebars.json';
|
||||
const currentSidebarFile = `${CWD}/versioned_sidebars/version-${currentVersion}-sidebars.json`;
|
||||
const newSidebarFile = `${CWD}/versioned_sidebars/version-${newVersion}-sidebars.json`;
|
||||
if (fs.existsSync(currentSidebarFile)) {
|
||||
fs.renameSync(currentSidebarFile, newSidebarFile);
|
||||
let sidebarContent = fs.readFileSync(newSidebarFile, 'utf8');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue