`oclif-dev readme` duplicates content and end tags
Opened this issue · 5 comments
I am using oclif on Windows, and am having trouble with oclif-dev readme
duplicating content and the end tags. This produces diffs like this:
λ git diff
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory
diff --git a/README.md b/README.md
index 8199c0c..b9952ae 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,9 @@ Tools for releasing Apache Cordova packages
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->
+* [Usage](#usage)
+* [Commands](#commands)
+<!-- tocstop -->
# Usage
<!-- usage -->
```sh-session
@@ -28,8 +31,207 @@ USAGE
...
`` `
<!-- usagestop -->
+```sh-session
+$ npm install -g cordova-release-tools
+$ cort COMMAND
+running command...
+$ cort (-v|--version|version)
+cordova-release-tools/0.1.0 win32-x64 node-v12.3.1
+$ cort --help [COMMAND]
+USAGE
+ $ cort COMMAND
+...
+```
+<!-- usagestop -->
# Commands
...
So it seems to recognize where to put the generated data, but doesn't delete the old stuff - which leads to duplicated content and end tags (<!-- tocstop -->
, <!-- usagestop -->
etc).
I thought I might have somehow messed up the line breaks, this is Windows after all, but I don't know how and why. Sometimes it even works, and then suddenly doesn't any more (I think after changes Git branches, but that doesn't make too much sense)
Any idea what could be going on here?
λ oclif-dev -v
@oclif/dev-cli/1.22.0 win32-x64 node-v12.3.1
Just noticed: TOC and Usage get added after the existing "blocks", but the commands are inserted before the existing list of commands.
Same is happening to me on macOS
I have found that if I put new lines before and after the special tags, then this doesn't happen....once, because after running this command once my new line is removed
FOUND THE ISSUE!!
This is caused by a regex issue due to discrepancies in new line characters.
If any of the text inside a block contains '\n\r' instead of just '\n' as the new line, then the oclif cli fails to detect the end tag block.
The offending code is in dev-cli/lib/commands/readme.js.replaceTag
readme = readme.replace(new RegExp(
(.|\n)*, 'm'),
);
The regex should be updated with (.|\n|\r)*
to be
readme = readme.replace(new RegExp(
(.|\n|\r)*, 'm'),
);
This should fix it, as a temporary work around, edit the readme to remove all \r AND make sure that any of the text the readme is built off of (such as command descriptions or usage examples) also don't have \r in them.
I discovered that it also helps to switch the line endings in VSCode to LF
instead of CRLF
before you run npm run version
(with a project generated by the cli).
So it is definitely related to the line endings.