Skip to content

Commit

Permalink
Added first version of cli #11
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPap committed Oct 15, 2018
1 parent de474e3 commit 0525240
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 3 deletions.
126 changes: 126 additions & 0 deletions bin/jssa-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env node

const minimist = require('minimist');
const analysis = require('../analysis');

const menus = {
main: `
analyze [command] <options>
all ................... run all analyzers
escomplex ............. run escomplex analyzer
eslint ................ run eslint analyzer
jsinspect ............. run jsinspect analyzer
npmaudit .............. run npmaudit analyzer
nsp ................... run nsp analyzer
sonarjs ............... run sonarjs analyzer
help .................. show help menu for a command`,

all: `
analyze all <options>
--project, -p ..... the project root directory
--files, -f ....... the list of files to analyze`,

sonarjs: `
analyze all <options>
--project, -p ..... the project root directory`,

eslint: `
analyze all <options>
--files, -f ....... the list of files to analyze`,

nsp: `
analyze all <options>
--project, -p ..... the project root directory`,

npmaudit: `
analyze all <options>
--project, -p ..... the project root directory`,

jsinspect: `
analyze all <options>
--files, -f ....... the list of files to analyze`,

escomplex: `
analyze all <options>
--files, -f ....... the list of files to analyze`,
}

const args = minimist(process.argv.slice(2))

if(args._.length === 1){
switch(args["_"][0]){
case 'all':
if( !(args.f || args.f) ){
console.log(menus[args["_"][0]])
break;
}
if( !(args.p || args.project) ){
console.log(menus[args["_"][0]])
break;
}
var list_of_files = args.f ? args.f.split(',') : args.files.split(',');
analysis.analyze_all(args.p || args.project, list_of_files).then(res => {
analysis_results = res; // JSON Object Containing the analysis results
console.log(analysis_results)
})
break;
case 'sonarjs':
analysis.analyze_sonarjs(args.p || args.project).then(res => {
analysis_results = res; // JSON Object Containing the analysis results
console.log(analysis_results)
})
break;
case 'eslint':
var list_of_files = args.f ? args.f.split(',') : args.files.split(',');
analysis.analyze_eslint(list_of_files).then(res => {
analysis_results = res; // JSON Object Containing the analysis results
console.log(analysis_results)
})
break;
case 'nsp':
analysis.analyze_nsp(args.p || args.project).then(res => {
analysis_results = res; // JSON Object Containing the analysis results
console.log(analysis_results)
})
break;
case 'npmaudit':
analysis.analyze_npmaudit(args.p || args.project).then(res => {
analysis_results = res; // JSON Object Containing the analysis results
console.log(analysis_results)
})
break;
case 'jsinspect':
var list_of_files = args.f ? args.f.split(',') : args.files.split(',');
analysis.analyze_jsinspect(list_of_files).then(res => {
analysis_results = res; // JSON Object Containing the analysis results
console.log(analysis_results)
})
break;
case 'escomplex':
var list_of_files = args.f ? args.f.split(',') : args.files.split(',');
analysis.analyze_escomplex(list_of_files).then(res => {
analysis_results = res; // JSON Object Containing the analysis results
console.log(analysis_results)
})
break;
case 'help':
console.log(menus.main)
break;
default:
console.log(args["_"][0] + ' command does not exist')
console.log(menus.main)
}
}
else{
console.log('Invalid arguments...')
console.log(menus.main)
}
19 changes: 16 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.0.5",
"description": "JS static analyzer (jssa): An aggregation of javascript source code static analysis tools",
"main": "analysis.js",
"bin": {
"jssa": "./bin/jssa-cli.js"
},
"dependencies": {
"babel-eslint": "^8.2.3",
"bluebird": "^3.5.1",
Expand All @@ -16,6 +19,7 @@
"fs": "^0.0.1-security",
"jsinspect": "^0.12.7",
"lodash": "^4.17.10",
"minimist": "^1.2.0",
"nsp": "^3.2.1",
"run-npm-audit": "^1.0.2",
"shelljs": "^0.7.8",
Expand Down

0 comments on commit 0525240

Please sign in to comment.