In this guide we use a really good typescript library starter package, with the nondescript name of typescript-starter. Since typescript is a superset of javascript with better IDE support. It includes CI/CD configuration, publishing, documentation and release notes documentation. So it is a great start.
Run the following command line and follow the prompts. Make sure to name the project with this convention @{{OWNER}}/library-name
npx typescript-starter
Create a git repository. For this guide we use github, since npm is now owned by github and the npm registry is sunsetted.
git remote add origin https://@{{OWNER}}/library-name
git branch -M main
git push -u origin main
For Github packages. Modify your global or local .npmrc
file to include the following two lines
@{{OWNER}}:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken={{TOKEN}}
And add the following to your library package.config
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
Where the token is a github token with read and write access. Other users will need to do the same, adding their own tokens. Here is a link to github for convenience: https://github.com/settings/tokens. Of course if the library is public you can skip the token step.
The typescript-starter documentation is very thorough, I recommend you read it to see what other scripts and features are included. To publish you will need to make sure that all your commits are up to date and then type:
npm run prepare-release
Then you will have to push your code to github. And publish your package to github as well in this case.
git push --follow-tags && npm publish
To find the location of the global .npmrc
file use this command.
npm config list