npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sonar-wrapper

v0.1.3

Published

sonar-wrapper standalone scanner

Downloads

3

Readme

sonar-wrapper

Wrap SonarQube Scanner as a node module.

Installation

Install sonar-wrapper as node module in the dev dependencies

npm i sonar-wrapper --save-dev

Requirements

This module is based on sonar-scanner Java ARchive, a Java Runtime Environement has to be present on the computer and set as JAVA_HOME env variable.

Use

sonar-wrapper offers only one function to run analisys and get back the metrics result.

var sonar = require('sonar-wrapper');

sonar.runAnalisys(sonarqube_server_url, options, metrics).then(function(result) {
  //handle the result here
});

Settings

Run Sonar analisys require somme configurations, the module have to know the SonarQube server URL, the specifics options about project and wich informations you'll like to get back.

SonarQube server url

A string value representing the sonarqube server url.

ex.

"http://localhost:9000" 

Options

Options have to be a json Object representing the sonar project properties such as src folder , project name etc ...

It could be like bellow :

{
    "sonar.language": "js",
    "sonar.projectKey": "sk-sonar-tester-node-module",
    "sonar.projectName": "9019_SonarTesterNodeModule",
    "sonar.projectVersion": "0.76.0-dev.24",
    "sonar.sources": "src",
    "sonar.test": "src",
    "sonar.coverage.exclusions": "**/*.module.js,**/*.constants.js,**/*.spec.js",
    "sonar.sourceEncoding": "UTF-8",
    "sonar.exclusions": "node_modules/,**/*.spec.js"
}

Metrics

An array of metrics key name you want to get back after analisys

var mertics = ['code_smells', 'bugs', 'alert_status', 'violations'];

Check analisys results progamaticly

Have a look on the analisys result in the source code can be great for continous integration. The main function runAnalisys() return a callback containing informations about analisys such as issues, code coverage (if set in options) or quality gate status.

sonar.runAnalisys(sonarqube_server_url, options, resultMetrics).then(function(results) {

    console.log(JSON.stringify(results));
})

Will give the output :

{
  "component":{
    "id":"AWXn51sqgFSCIYM641s_",
    "key":"sk-sonar-tester-node-module",
    "name":"9019_SonarTesterNodeModule",
    "qualifier":"TRK",
    "measures":[
      {
        "metric":"code_smells",
        "value":"0",
        "periods":[
          {
            "index":1,
            "value":"0"
          }
        ]
      },
      {
        "metric":"bugs",
        "value":"0",
        "periods":[
          {
            "index":1,
            "value":"0"
          }
        ]
      },
      {
        "metric":"alert_status",
        "value":"OK"
      },
      {
        "metric":"violations",
        "value":"0",
        "periods":[
          {
            "index":1,
            "value":"0"
          }
        ]
      }
    ]
  }
}