New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

complan

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

complan - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

.eslintrc.js

63

index.js
#!/usr/bin/env node
const Debug = require('debug')('main')
const Program = require('commander')
const Fse = require('fs-extra');
const Path = require('path');
const Program = require('commander');
const clone = require('./lib/clone')
const getJsFiles = require('./lib/getJsFiles')
const computeComplexity = require('./lib/computeComplexity')
const generateReport = require('./lib/generateReport')
const util = require('./lib/util')
const version = require('./package.json').version
const clone = require('./lib/clone');
const getJsFiles = require('./lib/getJsFiles');
const computeComplexity = require('./lib/computeComplexity');
const generateReport = require('./lib/generateReport');
Program
.version('0.0.1')
.version(version)
.usage('-g <giturl>')
.option('-g, --gitUrl [url]', 'Git Url of the project you want complexity report for')
.parse(process.argv);
.parse(process.argv)
if (!Program.gitUrl) {
console.log('Missing git Url. Git url is mandatory');
process.exit(1);
console.log('Missing git Url. Git url is mandatory')
process.exit(1)
}
const gitUrl = Program.gitUrl;
const projectName = gitUrl.substr(gitUrl.lastIndexOf('/') + 1);
const path = Path.join(process.cwd(), 'clonedrepos' ,projectName);
const gitUrl = Program.gitUrl
const clonedRepoPath = util.getClonedRepoPath(gitUrl)
const reportsPath = util.getReportsPath(gitUrl)
clone(gitUrl, path).then(function () {
return getJsFiles(path);
clone(gitUrl, clonedRepoPath).then(function () {
return getJsFiles(clonedRepoPath)
}).then(function (jsfiles) {
return computeComplexity(jsfiles);
}).then(function (path){
var complexityReport = generateReport(path);
console.log(JSON.stringify(complexityReport, null ,3));
}).
catch(function (err) {
if (err) {
console.log(err);
}
}).
finally(function () {
try {
Fse.removeSync(path);
} catch (e) {
console.error('Error in deleting ' + path);
console.error(e);
}
});
return computeComplexity(jsfiles, reportsPath)
}).then(function (path) {
var complexityReport = generateReport(path)
Debug(JSON.stringify(complexityReport, null, 3))
}).catch(function (err) {
if (err) {
console.log(err)
}
}).finally(function () {
util.cleanupClonedRepos()
})

@@ -1,29 +0,30 @@

const gitClone = require('git-clone');
const Fse = require('fs-extra');
const Promise = require('bluebird');
const Debug = require('debug')('clone')
const GitClone = require('git-clone')
const Fse = require('fs-extra')
const Promise = require('bluebird')
module.exports = function clone(gitUrl, path) {
try {
Fse.emptyDirSync(path);
} catch (e) {
console.error('Error in emptying ' + path);
console.error(e);
}
module.exports = function clone (gitUrl, path) {
try {
Fse.emptyDirSync(path)
} catch (e) {
console.error('Error in emptying ' + path)
console.error(e)
}
return new Promise(function (resolve, reject) {
gitClone(gitUrl, path, {}, function (err, result) {
if (err) {
console.log('Error in cloning ' + gitUrl);
reject(err);
} else {
if (!result) {
console.log('Successfully cloned ' + gitUrl);
resolve('Cloned successfully..' + gitUrl)
} else {
console.log(result);
resolve(result);
}
}
});
});
return new Promise(function (resolve, reject) {
GitClone(gitUrl, path, {}, function (err, result) {
if (err) {
console.log('Error in cloning ' + gitUrl)
reject(err)
} else {
if (!result) {
Debug('Successfully cloned ' + gitUrl)
resolve('Cloned successfully..' + gitUrl)
} else {
Debug(result)
resolve(result)
}
}
})
})
}

@@ -1,18 +0,19 @@

const Path = require('path');
const Promise = require('bluebird');
const Exec = require('child_process').exec;
const Path = require('path')
const Promise = require('bluebird')
const Exec = require('child_process').exec
module.exports = function computeComplexity (path) {
var jsonPath = Path.join(process.cwd(), 'cc.json');
var crPath = Path.resolve(process.execPath, '../..', 'lib/node_modules/complan/node_modules/.bin/cr');
var cmd = crPath + ' -l -w -f json -e -x node_modules -o ' + jsonPath + ' ' + path.join(' ');
return new Promise(function (resolve, reject) {
Exec(cmd , function (err, stdout,stderr) {
if (err instanceof Error) {
reject(err);
}
console.log('Successfully wrote cc.json');
resolve(jsonPath);
});
});
}
module.exports = function computeComplexity (paths, reportsPath) {
var jsonPath = Path.join(process.cwd(), 'cc.json')
var jsonReportPath = Path.join(reportsPath, 'complexity-report.json')
var crPath = Path.resolve(process.execPath, '../..', 'lib/node_modules/complan/node_modules/.bin/cr')
var cmd = crPath + ' -l -w -f json -e -x node_modules -o ' + jsonReportPath + ' ' + paths.join(' ')
return new Promise(function (resolve, reject) {
Exec(cmd, function (err, stdout, stderr) {
if (err instanceof Error) {
reject(err)
}
console.log('Successfully wrote ' + jsonReportPath)
resolve(jsonPath)
})
})
}

@@ -1,20 +0,19 @@

const Fs = require('fs');
const Fs = require('fs')
module.exports = function (path) {
var complexityReport = {};
complexityReport.report = [];
var jsonReport = JSON.parse(Fs.readFileSync(path, 'utf-8'));
jsonReport.reports.forEach(function (report) {
var rep = {};
rep.path = report.path;
rep.cyclomatic = report.cyclomatic;
rep.loc = report.loc;
rep.maintainability = report.maintainability;
complexityReport.report.push(rep);
});
complexityReport.cyclomatic = jsonReport.cyclomatic;
complexityReport.loc = jsonReport.loc;
complexityReport.maintainability = jsonReport.maintainability;
return complexityReport;
var complexityReport = {}
complexityReport.report = []
var jsonReport = JSON.parse(Fs.readFileSync(path, 'utf-8'))
jsonReport.reports.forEach(function (report) {
var rep = {}
rep.path = report.path
rep.cyclomatic = report.cyclomatic
rep.loc = report.loc
rep.maintainability = report.maintainability
complexityReport.report.push(rep)
})
complexityReport.cyclomatic = jsonReport.cyclomatic
complexityReport.loc = jsonReport.loc
complexityReport.maintainability = jsonReport.maintainability
return complexityReport
}

@@ -1,24 +0,25 @@

const Dir = require('node-dir');
const Promise = require('bluebird');
const Debug = require('debug')('getJsFiles')
const Dir = require('node-dir')
const Promise = require('bluebird')
module.exports = function getJsFiles(path) {
return new Promise(function (resolve, reject) {
Dir.readFiles(path, {
match: /.js$/,
exclude: /^\./,
excludeDir: /node_modules/
}, function(err, content, next) {
if (err) {
return reject(err);
}
next();
},
function(err, files){
if (err) {
return reject (err);
}
console.log(files.length + ' files found');
resolve(files);
});
});
}
module.exports = function getJsFiles (path) {
return new Promise(function (resolve, reject) {
Dir.readFiles(path, {
match: /.js$/,
exclude: /^\./,
excludeDir: /node_modules/
}, function (err, content, next) {
if (err) {
return reject(err)
}
next()
},
function (err, files) {
if (err) {
return reject(err)
}
Debug(files.length + ' files found')
resolve(files)
})
})
}
{
"name": "complan",
"version": "1.0.3",
"version": "1.0.4",
"description": "COMPLexity ANalyzer Tool For Javascript",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "./node_modules/.bin/eslint ."
},

@@ -23,6 +24,11 @@ "bin": "./index.js",

"complexity-report": "^1.4.1",
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"git-clone": "^0.1.0",
"git-url-parse": "^6.0.5",
"node-dir": "^0.1.16"
},
"pre-commit": [
"lint"
],
"author": "Pranav Parikh",

@@ -33,3 +39,10 @@ "license": "MIT",

},
"homepage": "https://github.com/pranavparikh/complan#readme"
"homepage": "https://github.com/pranavparikh/complan#readme",
"devDependencies": {
"eslint": "^3.7.1",
"eslint-config-standard": "^6.2.0",
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-standard": "^2.0.1",
"pre-commit": "^1.1.3"
}
}

@@ -38,2 +38,9 @@ # Complan

```
```
e.g
complan -g https://github.com/pranavparikh/complan
or
complan -g git@github.com:pranavparikh/complan.git
```
The above command will generate complexity report under a directory named ```pranavparikh/complan``` in your current directory.

@@ -40,0 +47,0 @@ The tool will locally clone the repository from git (Git has to be installed as a pre-requisite) , compute complexity and output it in a form of JSON report.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc