One solution can be to use two readme files and rename them using npm scripting during npm publish
.
This can be done as follows.
On source control, we would have the following files:
README.md
- This is the default git readme where you would document your source.
npm.README.md
- This would be the readme that would be seen on NPM.
Next, we would have the following in package.json
(note that some contents are omitted).
{
...
"scripts": {
...
"build": "...",
"use:npmReadme": "mv 'README.md' 'git.README.md' && mv 'npm.README.md' 'README.md'",
"use:gitReadme": "mv 'README.md' 'npm.README.md' && mv 'git.README.md' 'README.md'",
"prepublishOnly": "run-s build use:npmReadme",
"postpublish": "npm run use:gitReadme"
},
"dependencies": {
...
},
"devDependencies": {
...
"npm-run-all": "^4.1.2",
...
}
}
In devDependencies, the npm-run-all package is used. This allows using the run-s command to run specified npm scripts sequentially.
in the scripts section, we have the following scripts:
Scripts to Rename README files
use:npmReadme
- This simply backs up the current git specific readme, and then renames npm.README.md
to be the default README.md
.
use:gitReadme
- This simply reverts back to using the git specific readme as the default README.md
.
prepublishOnly
This is executed BEFORE the package is prepared and packed, and ONLY on npm publish
. (Does not run with npm install
).
Here, the solution is built, and then we run use:npmReadme
.
postPublish
This is executed AFTER the package is published on npm.
Here, we run use:gitReadme
to revert the readme files back to their original state.
More information on prepublishOnly and postPublish can be found here.