const exec = require('child_process').exec;

const AUDIT_EXCEPTIONS = [handlebars];

const execute = (command, callback) => {
  exec(
    command, {
      maxBuffer: 2000 * 1024
    },
    (error, stdout, stderr) => {
      callback(stdout);
    }
  );
};
execute('npm audit --json', json => {
  const advisories = JSON.parse(json).advisories;
  if (!advisories) {
    console.info('Most likely npm audit is unavailable', json);
    process.exit(0);
  }
  let auditPass = true;
  for (const id in advisories) {
    if (
      advisories[id].severity === 'high' &&
      !AUDIT_EXCEPTIONS.includes(advisories[id].module_name)
    ) {
      console.error('AUDIT Failed', advisories[id]);
      auditPass = false;
    }
  }
  if (!auditPass) process.exit(1);
});

@@ -64,16 +64,17 @@
 IONS = %5B
+'
 handleba
@@ -75,16 +75,17 @@
 ndlebars
+'
 %5D;%0A%0Acons

update AUDIT_EXCEPTIONS