// new.js
//

'use strict';

var download     = require('../download');
var extractTarGz = require('../extractTarGz');
var pkg = require('../../package.json');

var fs   = require('fs');
var os   = require('os');
var path = require('path');

var jsonfile = require('jsonfile');
var Queue    = require('queue');

module.exports = function (options) {

  // To do: Validate 'options'.
  options = options || {};

  var projectPath = path.join(options.dir, options.name);
  var tmpArchive  = path.join(os.tmpdir(), 'latest.tar.gz');

  var q = new Queue({ concurrency: 1 });

  // 1. Create project dir.
  q.push(function (cb) {
    fs.mkdir(projectPath, cb);
  });

  // 2. Download Collider release.
  q.push(function (cb) {
    download('http://getcollider.com/latest.tar.gz', tmpArchive, {
      headers: { 'User-Agent': `collider-cli/${pkg.version}`, },
      timeout: 10000,
    }, cb);
  });

  // 3. Extract Collider release into project dir.
  q.push(function (cb) {
    console.log('Download complete. Extracting...');
    extractTarGz(tmpArchive, projectPath, cb);
  });

  // 4. Write collider file.
  q.push(function (cb) {
    jsonfile.writeFile(`${projectPath}/collider.json`, options, { spaces: 2 }, cb);
  });

  // Go.
  q.start(function (err) {
    if (err) {
      q.end(err);
      throw err;
    }

    console.log(`Extraction complete. Your new project is located at "${projectPath}".`);
  });

};

@@ -30,18 +30,11 @@
 var 
-download  
+pkg
    =
@@ -50,36 +50,36 @@
 '../
-download');%0Avar extractTarGz
+../package.json');%0Avar utils
  = r
@@ -93,31 +93,26 @@
 '../
-extractTarGz
+utils
 ');%0A
+%0A
 var 
-pkg
+cp  
  = r
@@ -123,31 +123,25 @@
 re('
-../../package.json
+child_process
 ');%0A
-%0A
 var 
@@ -314,23 +314,23 @@
 nction (
-options
+project
 ) %7B%0A%0A  /
@@ -352,37 +352,37 @@
 te '
-options'.%0A  options = options
+project'.%0A  project = project
  %7C%7C 
@@ -420,28 +420,28 @@
 oin(
-options.dir, options
+project.dir, project
 .nam
@@ -703,16 +703,22 @@
 ) %7B%0A    
+utils.
 download
@@ -1011,16 +1011,22 @@
 ');%0A    
+utils.
 extractT
@@ -1117,24 +1117,110 @@
 tion (cb) %7B%0A
+    console.log(%60Extraction complete. Your project is located at %22$%7BprojectPath%7D%22.%60);%0A
     jsonfile
@@ -1266,15 +1266,15 @@
 n%60, 
-options
+project
 , %7B 
@@ -1351,140 +1351,17 @@
 rr) 
-%7B%0A      q.end(err);%0A      throw err;%0A    %7D%0A%0A    console.log(%60Extraction complete. Your new project is located at %22$%7BprojectPath%7D%22.%60)
+throw err
 ;%0A  

Update new handler