Skip to content

Commit

Permalink
Build: Add an edit link to the rule docs’ metadata (#9049)
Browse files Browse the repository at this point in the history
This also splits the template into separate lines.
  • Loading branch information
j-f1 authored and not-an-aardvark committed Aug 26, 2017
1 parent fcb7bb4 commit e6b115c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions Makefile.js
Expand Up @@ -631,11 +631,13 @@ target.gensite = function(prereleaseVersion) {
}

// 1. create temp and build directory
echo("> Creating a temporary directory (Step 1)");
if (!test("-d", TEMP_DIR)) {
mkdir(TEMP_DIR);
}

// 2. remove old files from the site
echo("> Removing old files (Step 2)");
docFiles.forEach(filePath => {
const fullPath = path.join(DOCS_DIR, filePath),
htmlFullPath = fullPath.replace(".md", ".html");
Expand All @@ -651,6 +653,7 @@ target.gensite = function(prereleaseVersion) {
});

// 3. Copy docs folder to a temporary directory
echo("> Copying the docs folder (Step 3)");
cp("-rf", "docs/*", TEMP_DIR);

let versions = test("-f", "./versions.json") ? JSON.parse(cat("./versions.json")) : {};
Expand All @@ -668,18 +671,25 @@ target.gensite = function(prereleaseVersion) {
const FIXABLE_TEXT = "\n\n(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) can automatically fix some of the problems reported by this rule.";

// 4. Loop through all files in temporary directory
find(TEMP_DIR).forEach(filename => {
process.stdout.write("> Updating files (Steps 4-9): 0/... - ...\r");
const tempFiles = find(TEMP_DIR);
const length = tempFiles.length;

tempFiles.forEach((filename, i) => {
if (test("-f", filename) && path.extname(filename) === ".md") {

const rulesUrl = "https://github.com/eslint/eslint/tree/master/lib/rules/",
docsUrl = "https://github.com/eslint/eslint/tree/master/docs/rules/",
baseName = path.basename(filename),
sourceBaseName = `${path.basename(filename, ".md")}.js`,
sourcePath = path.join("lib/rules", sourceBaseName),
ruleName = path.basename(filename, ".md");
ruleName = path.basename(filename, ".md"),
filePath = path.join("docs", path.relative("tmp", filename));
let text = cat(filename),
title;

process.stdout.write(`> Updating files (Steps 4-9): ${i}/${length} - ${filePath + " ".repeat(30)}\r`);

// 5. Prepend page title and layout variables at the top of rules
if (path.dirname(filename).indexOf("rules") >= 0) {

Expand All @@ -695,7 +705,7 @@ target.gensite = function(prereleaseVersion) {

text = `${ruleHeading}${isRecommended ? RECOMMENDED_TEXT : ""}${isFixable ? FIXABLE_TEXT : ""}\n${ruleDocsContent}`;

text = `---\ntitle: ${ruleName} - Rules\nlayout: doc\n---\n<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->\n\n${text}`;
title = `${ruleName} - Rules`;
} else {

// extract the title from the file itself
Expand All @@ -705,9 +715,19 @@ target.gensite = function(prereleaseVersion) {
} else {
title = "Documentation";
}
text = `---\ntitle: ${title}\nlayout: doc\n---\n<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->\n\n${text}`;
}

text = [
"---",
`title: ${title}`,
"layout: doc",
`https://github.com/eslint/eslint/edit/master/${filePath}`,
"---",
"<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->",
"",
text
].join("\n");

// 6. Remove .md extension for relative links and change README to empty string
text = text.replace(/\((?!https?:\/\/)([^)]*?)\.md.*?\)/g, "($1)").replace("README.html", "");

Expand Down Expand Up @@ -745,8 +765,10 @@ target.gensite = function(prereleaseVersion) {
}
});
JSON.stringify(versions).to("./versions.json");
echo(`> Updating files (Steps 4-9)${" ".repeat(50)}`);

// 10. Copy temporary directory to site's docs folder
echo("> Copying the temporary directory the site (Step 10)");
let outputDir = DOCS_DIR;

if (prereleaseVersion) {
Expand All @@ -755,18 +777,26 @@ target.gensite = function(prereleaseVersion) {
cp("-rf", `${TEMP_DIR}*`, outputDir);

// 11. Generate rule listing page
echo("> Generating the rule listing (Step 11)");
generateRuleIndexPage(process.cwd());

// 12. Delete temporary directory
echo("> Removing the temporary directory (Step 12)");
rm("-r", TEMP_DIR);

// 13. Update demos, but only for non-prereleases
if (!prereleaseVersion) {
echo("> Updating the demos (Step 13)");
cp("-f", "build/eslint.js", `${SITE_DIR}js/app/eslint.js`);
} else {
echo("> Skipped updating the demos (Step 13)");
}

// 14. Create Example Formatter Output Page
echo("> Creating the formatter examples (Step 14)");
generateFormatterExamples(getFormatterResults(), prereleaseVersion);

echo("Done generating eslint.org");
};

target.browserify = function() {
Expand Down

0 comments on commit e6b115c

Please sign in to comment.