import fs from 'fs-promise';
import getFiles from './get-files';
import hash from './hash';
import Agent from './Agent';

export default async function now (path, { debug }) {
  try {
    await fs.stat(path);
  } catch (err) {
    throw new Error(`Could not read directory ${path}.`);
  }

  if (debug) console.time('> [debug] Getting files');
  const files = await getFiles(path);
  if (debug) console.timeEnd('> [debug] Getting files');

  if (debug) console.time('> [debug] Computing hashes');
  const hashes = await hash(files);
  if (debug) console.timeEnd('> [debug] Computing hashes');

  if (debug) {
    hashes.forEach((val, key) => {
      console.log(`> [debug] Found "${key}" [${val}]`);
    });
  }

  const agent = new Agent('www.google.com');
  if (debug) console.time('> [debug] http');
  const res = await agent.fetch('/now/create');
  if (debug) console.timeEnd('> [debug] http');
  console.log(res.status);
  agent.close();

  return 'https://test.now.run';
}

@@ -113,16 +113,48 @@
 /Agent';
+%0Aimport %7B resolve %7D from 'path';
 %0A%0Aexport
@@ -187,16 +187,23 @@
 w (path,
+ token,
  %7B debug
@@ -322,16 +322,215 @@
 );%0A  %7D%0A%0A
+  let pkg;%0A  try %7B%0A    pkg = await fs.readFile(resolve(path, 'package.json'));%0A    pkg = JSON.parse(pkg);%0A  %7D catch (err) %7B%0A    throw new Error(%60Failed to read JSON in %22$%7Bpath%7D/package.json%22%60);%0A  %7D%0A%0A
   if (de
@@ -606,24 +606,29 @@
 etFiles(path
+, pkg
 );%0A  if (deb

read package.json