feat: add the ability to run with '--json' and output the result (#78)

* addition-of-json-flag

* Set output of npn audit
This commit is contained in:
sgkiokas
2020-12-12 13:56:05 +02:00
committed by GitHub
parent 3868af0215
commit c4cd169835
8 changed files with 133 additions and 10 deletions

9
dist/index.js vendored
View File

@@ -556,12 +556,15 @@ class Audit {
this.stdout = '';
this.status = null;
}
run(auditLevel, productionFlag) {
run(auditLevel, productionFlag, jsonFlag) {
try {
const auditOptions = ['audit', '--audit-level', auditLevel];
if (productionFlag === 'true') {
auditOptions.push('--production');
}
if (jsonFlag === 'true') {
auditOptions.push('--json');
}
const result = child_process_1.spawnSync('npm', auditOptions, {
encoding: 'utf-8',
maxBuffer: SPAWN_PROCESS_BUFFER_SIZE
@@ -1435,6 +1438,10 @@ function run() {
if (!['true', 'false'].includes(productionFlag)) {
throw new Error('Invalid input: production_flag');
}
const jsonFlag = core.getInput('json_flag', { required: false });
if (!['true', 'false'].includes(jsonFlag)) {
throw new Error('Invalid input: json_flag');
}
// run `npm audit`
const audit = new audit_1.Audit();
audit.run(auditLevel, productionFlag);