import { schedule, message, warn } from "danger";
import fs from 'fs';
import prettier from 'prettier';
import glob from 'glob';

const srcDirGlob = `${__dirname}/src/**/*.js`;
const options = {
  singleQuote: true,
  printWidth: 100
};

const getAllFilePaths = dirGlob => {
  return new Promise((resolve, reject) => {
    glob(dirGlob, (err, filePaths) => {
      if (err) {
        reject(err);
      } else {
        resolve(filePaths);
      }
    });
  });
};

const isFileFormatted = path => {
  const fileContents = fs.readFileSync(path);
  return prettier.check(fileContents.toString(), options);
}

schedule(async () => {
  try {
    const failedFilePaths = [];
    const filePaths = await getAllFilePaths(srcDirGlob);
    
    filePaths.forEach(filePath => {
      if (!isFileFormatted(filePath)) {
        failedFilePaths.push(filePath);
      }
    });

    if (failedFilePaths.length > 0) {
      warn('You haven\'t formated the code using prettier. Please run `npm run format` before merging the PR');
    } else {
      message(':tada: Your code is formatted correctly');
    }
  } catch (e) {
    console.error('Looks like something went wrong! :/');
  }
});

@@ -21,20 +21,20 @@
 essage, 
-warn
+fail
  %7D from 
@@ -907,12 +907,12 @@
     
-warn
+fail
 ('Yo
@@ -1110,21 +1110,12 @@
     
-console.error
+fail
 ('Lo

Change warn to fail in dangerfile