UNPKG

1.14 kBJavaScriptView Raw
1var sync = require('child_process').execSync,
2 glob = require('glob'),
3 fs = require('fs'),
4 path = require('path');
5
6isSonarInstalled();
7
8function isSonarInstalled() {
9 return isSonarInstalledGlobally() || isSonarInstalledLocally();
10}
11
12function isSonarInstalledGlobally() {
13 try {
14 sync('sonar-runner --version', {encoding: 'utf8', stdio: ['ignore', 'ignore', 'ignore']});
15 console.debug('Sonar-runner is already installed globally.');
16 exit(0);
17 } catch (e) {
18 console.log('command not found: sonar-runner (is not available globally)');
19 return false;
20 }
21}
22
23function isSonarInstalledLocally() {
24 var libDir = path.join(__dirname, 'lib'),
25 extension = (/^win/.test(process.platform) ? '.bat' : '');
26 console.log(libDir)
27 if (fs.existsSync(libDir)) {
28 glob.sync('**/bin/sonar-runner' + extension, {cwd: libDir, root: '/'}).forEach(function (file) {
29 console.log('Sonar-runner is already installed locally.');
30 exit(0);
31 });
32 }
33 console.log('command not found: sonar-runner (is not available locally)');
34 return false;
35}