New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build: Edit link in rule docs #9049
Changes from 5 commits
d18c3e2
facb3f1
fcf249e
7c110e0
bf28389
8cdeaae
e470cb4
6b129e0
7442f55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
@@ -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")) : {}; | ||
|
@@ -668,7 +671,11 @@ 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/", | ||
|
@@ -680,6 +687,8 @@ target.gensite = function(prereleaseVersion) { | |
let text = cat(filename), | ||
title; | ||
|
||
process.stdout.write(`> Updating files (Steps 4-9): ${i}/${length} - ${sourcePath + " ".repeat(30)}\r`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It resets to the beginning of the line, instead of spamming the terminal with lots and lots of lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat, TIL |
||
|
||
// 5. Prepend page title and layout variables at the top of rules | ||
if (path.dirname(filename).indexOf("rules") >= 0) { | ||
|
||
|
@@ -695,7 +704,16 @@ 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}`; | ||
text = [ | ||
"---", | ||
`title: ${ruleName} - Rules`, | ||
"layout: doc", | ||
filename.indexOf("rules/") !== -1 && `edit_link: https://github.com/eslint/eslint/edit/master/docs/rules/${baseName}`, | ||
"---", | ||
"<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->", | ||
"", | ||
text | ||
].filter(x => x).join("\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is |
||
} else { | ||
|
||
// extract the title from the file itself | ||
|
@@ -705,7 +723,16 @@ 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", | ||
`edit_link: https://github.com/eslint/eslint/edit/master/${baseName}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this use |
||
"---", | ||
"<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->", | ||
"", | ||
text | ||
].filter(x => x).join("\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is |
||
} | ||
|
||
// 6. Remove .md extension for relative links and change README to empty string | ||
|
@@ -745,8 +772,10 @@ target.gensite = function(prereleaseVersion) { | |
} | ||
}); | ||
JSON.stringify(versions).to("./versions.json"); | ||
echo(`> Updating files (Steps 4-9)${" ".repeat(50)}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It overwrites any file name contents so they don’t appear after the message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, thanks. To me, It seems undesirable to have a hardcoded value of 50 there (since it will probably cause a bug if we ever add a filepath with length longer than 50), but it's a very small issue either way, so I'm fine with leaving it for now. |
||
|
||
// 10. Copy temporary directory to site's docs folder | ||
echo("> Copying the temporary directory the site (Step 10)"); | ||
let outputDir = DOCS_DIR; | ||
|
||
if (prereleaseVersion) { | ||
|
@@ -755,18 +784,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() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use
echo
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo
adds a\n
to the end, which causes the status to extend to multiple lines, which doesn’t provide a very nice experience. Additionally,echo("-n", "foo")
doesn’t work.