Skip to content
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

fix: update ineff regex #357 #410

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions template/scripts/generateDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@ function formatTemplateFileContents(content, destination) {
/**
* Cleanup line breaks
*/
result = result.replace(/(\r\n|\r|\n)[\s]+(\r\n|\r|\n)/g, '\r\n\r\n'); // Replace lines containing only whitespace with a carriage return.
result = result.replace(/>(\r\n|\r|\n){2,}/g, '>\r\n'); // Remove empty lines directly after a closing html tag.
result = result.replace(/>(\r\n|\r|\n)```/g, '>\r\n\r\n```'); // Ensure an empty line before code samples.
result = result.replace(/>(\r\n|\r|\n){2,}```(\r\n|\r|\n)/g, '>\r\n```\r\n'); // Ensure no empty lines before close of code sample.
result = result.replace(/([^(\r\n|\r|\n)])(\r\n|\r|\n)+#/g, "$1\r\n\r\n#"); // Ensure empty line before header sections.
result = result.replace(/(\r|\n|\r\n)/g, '\r\n'); // Standardize line endings
result = result.replace(/(\r\n)[\s]+(\r\n)/g, '\r\n\r\n'); // Replace lines containing only whitespace with a carriage return.
result = result.replace(/>(\r\n){2,}/g, '>\r\n'); // Remove empty lines directly after a closing html tag.
result = result.replace(/>(\r\n)```/g, '>\r\n\r\n```'); // Ensure an empty line before code samples.
result = result.replace(/>(\r\n){2,}```(\r\n)/g, '>\r\n```\r\n'); // Ensure no empty lines before close of code sample.
result = result.replace(/([^\r\n])(\r\n)(#+)/g, "$1$2\r\n$3"); // Ensure empty line before header sections.

/**
* Make api.md specific changes
*/
const wcName = nameExtractionData.namespace + '-' + nameExtractionData.name;

result = result
.replace(/\r\n####\s`([a-zA-Z]*)`/g, `\r\n#### <a name="$1"></a>\`$1\`<a href="#${wcName}" style="float: right; font-size: 1rem; font-weight: 100;">back to top</a>`); // Add Back To Top
result = result.replace(/(\r\n)\| `([a-zA-Z]*)`/g, '\r\n| [$2](#$2)'); // Wrap API attributes as Markdown Links
result = result.replace(/\| \[\]\(#\)/g, ""); // TODO: What is this???

/**
* Write the result to the destination file
Expand All @@ -68,20 +79,15 @@ function formatTemplateFileContents(content, destination) {
};

function formatApiTableContents(content, destination) {
const nameExtractionData = nameExtraction();
const wcName = nameExtractionData.namespace + '-' + nameExtractionData.name;

let result = content;

result = result
.replace(/\r\n|\r|\n####\s`([a-zA-Z]*)`/g, `\r\n#### <a name="$1"></a>\`$1\`<a href="#${wcName}" style="float: right; font-size: 1rem; font-weight: 100;">back to top</a>`)
.replace(/\r\n|\r|\n\|\s`([a-zA-Z]*)`/g, '\r\n| [$1](#$1)')
.replace(/\| \[\]\(#\)/g, "");

fs.writeFileSync(destination, result, { encoding: 'utf8'});

fs.readFile('./demo/apiExamples.md', 'utf8', function(err, data) {
formatTemplateFileContents(data, './demo/apiExamples.md');
fs.readFile('./demo/api.md', 'utf8', function(err, data) {
formatTemplateFileContents(data, './demo/api.md');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following error traced back to this update

./index.js → dist/...
created dist/ in 266ms
/Users/dalesande/src/auro/test-element/scripts/generateDocs.js:49
  result = result.replace(/\[npm]/g, nameExtractionData.npm);
                  ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at formatTemplateFileContents (/Users/dalesande/src/auro/test-element/scripts/generateDocs.js:49:19)
    at ReadFileContext.callback (/Users/dalesande/src/auro/test-element/scripts/generateDocs.js:87:5)
    at FSReqCallback.readFileAfterOpen [as oncomplete] (node:fs:325:13)

Node.js v18.15.0
ERROR: "build:docs" exited with 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what repo/branch did you see this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generated a new repo using npm run build:test




});
}

Expand Down