Skip to content

FireboltCasters/npm-template

Repository files navigation

npm-template

npm package MIT last commit downloads week downloads total size dependencies

Npm publish Build status Quality Gate Bugs Coverage Code Smells Duplicated Lines (%) Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities

npm-template

About

A template for creating npm packages

How to setup your project

  1. Clone this repo or "use as template" and upload it to GitHub
  2. Setup GitHub Secrets
  3. Get your Sonar credentials
  4. Configure and run the setup script
  5. Configure Quality Gate in Sonar

2. GitHub Secrets

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.)

3. Sonar

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

4. Setup Script

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": "[email protected]",
        "url": "https://github.com/FireboltCasters"
      },
      {
        "name": "Steffen Droppelmann",
        "email": "[email protected]",
        "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

5. Configure Quality Gate

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

Contributors

The FireboltCasters

Contributors

About

A template for creating npm packages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published