// generate.js
//

'use strict';

var createError  = require('../createError');
var logErrorExit = require('../logErrorExit');
var pkg = require('../../package.json');

var docopt = require('docopt').docopt;

// GENERATE
//

var doc = 'usage: collider generate (atom | molecule | organism) <name> [<locale>]';

module.exports = function (argv) {

  var args = docopt(doc, {
    argv: argv,
    version: `Collider CLI ${pkg.version}`,
  });

  var name   = args['<name>'];
  var locale = args['<locale>'] || 'project';

  var cmds = ['atom', 'molecule', 'organism'];

  var cmd;
  for (var i = 0; i < cmds.length; i++) {
    cmd = cmds[i];
    if (args[cmd]) break;
  }

  generate(cmd, name, locale);

};

// FUNCTIONS
//

function generate(type, name, locale) {
  console.log(type, name, locale);
};

@@ -69,24 +69,71 @@
 ateError');%0A
+var colliderfile = require('../colliderfile');%0A
 var logError
@@ -163,24 +163,24 @@
 rrorExit');%0A
-
 var pkg = re
@@ -247,16 +247,72 @@
 .docopt;
+%0Avar fs = require('fs');%0Avar mkdirp = require('mkdirp');
 %0A%0A// GEN
@@ -865,40 +865,1202 @@
 %7B%0A  
-console.log(type, name, locale);%0A%7D;
+var dir = %60./$%7Blocale%7D/matter/$%7Btype%7D/$%7Bname%7D%60;%0A  var prefix = locale !== 'project' ? %60$%7Blocale%7D/%60 : '';%0A%0A  colliderfile.exists('.', function (err) %7B%0A    if (err) throw err;%0A%0A    mkdirp(dir, %7B%7D, function (err) %7B%0A      if (err) throw err;%0A%0A      // Write skeleton Sass stylesheet.%0A      writeSkeletonFile(%0A        %60$%7Bdir%7D%60,%0A        %60_$%7Bname%7D.scss%60,%0A        %60// $%7Bprefix%7D_$%7Bname%7D.scss%5Cn//%5Cn%5Cn.$%7Bname%7D %7B%7D%5Cn%60,%0A      function (err) %7B%0A        if (err) %7B%0A          var err = createError(%60Failed to create skeleton stylesheet in $%7Bdir%7D.%60);%0A          logErrorExit(err, false);%0A        %7D%0A      %7D);%0A%0A      // Write skeleton Handlebars template.%0A      writeSkeletonFile(%0A        %60$%7Bdir%7D%60,%0A        %60$%7Bname%7D.hbs%60,%0A        %60%7B%7B! $%7Bprefix%7D$%7Bname%7D.hbs %7D%7D%5Cn%5Cn%60,%0A      function (err) %7B%0A        if (err) %7B%0A          var err = createError(%60Failed to create skeleton template in $%7Bdir%7D.%60);%0A          logErrorExit(err, false);%0A        %7D%0A      %7D);%0A%0A    %7D);%0A  %7D);%0A%7D;%0A%0Afunction writeSkeletonFile(dir, file, data, cb) %7B%0A  fs.access(%60$%7Bdir%7D/$%7Bfile%7D%60, fs.F_OK, function (err) %7B%0A    if (err) %7B%0A      fs.writeFile(%60$%7Bdir%7D/$%7Bfile%7D%60, data, function (err) %7B%0A        if (err) return cb(err);%0A        cb(null);%0A      %7D);%0A    %7D%0A  %7D);%0A%7D
 %0A

Complete initial impl. of `collider generate`