npm-template
A template for creating npm packages
- Clone this repo or "use as template" and upload it to GitHub
- Setup GitHub Secrets
- Get your Sonar credentials
- Configure and run the setup script
- Configure Quality Gate in Sonar
If not done by your organisation you will need to define the following secrets for your repository or your organisation:
- GITHUB_TOKEN
- NPM_TOKEN
(Note: You will also need to add a secret for Sonar in step 3.)
Sonar Cloud will be used to analyse our project in terms of code-quality: https://en.wikipedia.org/wiki/Software_quality Therefore we need to get credentials for our project. Create a Sonar-Account if you dont have one (it is free).
- Visit: https://sonarcloud.io/
- Select your profile or organisation.
- Select the GitHub project: https://sonarcloud.io/projects/create
- Configure "With GitHub Actions" and disable SonarCloud Automatic Analysis
- Follow Step 1: Add the secret to your repository
- "Skip" step 2
- Copy and paste the values of "sonar.projectKey" and "sonar.organization" into the setup.json
For the correct upload to npm and sonar and keep everything working correctly, the package.json file needs to be setup correctly. This can be tedious, so that you only need to configure the setup.json file to match your project:
{
"package": {
"name": "<packageName>",
"description": "<packageDescription>",
"keywords": [
"npm-template"
],
"repositoryURL": "https://github.com/FireboltCasters/npm-template.git",
"author": "Steffen Droppelmann",
"contributors": [
{
"name": "Nils Baumgartner",
"email": "nilsbaumgartner1994@gmail.com",
"url": "https://github.com/FireboltCasters"
},
{
"name": "Steffen Droppelmann",
"email": "steffen.droppelmann@gmail.com",
"url": "https://github.com/FireboltCasters"
}
],
"license": "MIT"
},
"sonar": {
"projectKey": "ExampleKey",
"organization": "ExampleOrganization"
}
}
Then, run the following command: (Note: After running this command, the setup files will be deleted)
npm run setup
Push your current project to GitHub. After that you should see on GitHub under "Actions" that some GitHub-Actions are being executed. The Sonar-Action will firstly fail with:
ERROR: QUALITY GATE STATUS: FAILED
This is because we haven't told Sonarcloud how it should measure the Quality Gate.
- Visit your project at: https://sonarcloud.io/projects/
- Select: "Set New Code definition"
- Select the code definition for your match. We recommend: "Previous version"
- Re-Upload your some minor change in your GitRepo to the master
The FireboltCasters