var promzard = require('promzard'),
    fs = require('fs'),
    path = require('path'),
    childproc = require('child_process'),
    _ = require('underscore'),
    cwd = process.cwd(),
    templateDir = path.join(__dirname, '../templates'),
    pkgIn = path.join(__dirname, 'input.js'),
    pkgOut = path.join(cwd, 'package.json');

if (fs.existsSync(pkgOut)) {
  bail('ERROR: ' + path.basename(pkgOut) + ' already exists!');
}

var ctx = {
  defaultAuthorName: 'Chris Pettitt',
  defaultAuthorEmail: 'cpettitt@gmail.com',
  defaultGitName: 'cpettitt'
};

promzard(pkgIn, ctx, function(err, data) {
  if (err) { throw err; }

  validate(data);

  writePackageJson(data);
  renderTemplate(getLicenseFile(data.license), data, path.join(cwd, 'LICENSE'));
  renderTemplate(path.join(templateDir, 'README.md'), data, path.join(cwd, 'README.md'));
  renderTemplate(path.join(templateDir, 'CHANGELOG.md'), data, path.join(cwd, 'CHANGELOG.md'));
  installCommonDevLibraries(function(err) {
    if (err) { throw err; }
    console.log('Done.');
  });
});

function bail(msg) {
  console.error(msg);
  process.exit(1);
}

function validate(data) {
  if (!fs.existsSync(getLicenseFile(data.license))) {
    bail('ERROR: A license file for ' + data.license + ' does not exist.\n'+
         'Missing: ' + getLicenseFile(data.license));
  }
}

function getLicenseFile(license) {
  return path.join(templateDir, 'license', 'LICENSE.' + license);
}

function writePackageJson(data) {
  var contents = {
    name: data.name,
    version: data.version + '-pre',
    description: data.description,
    author: data.authorName + ' <' + data.authorEmail + '>',
    main: 'index.js',
    license: data.license
  };

  fs.writeFileSync(pkgOut, JSON.stringify(contents, null, 2));
}

function renderTemplate(src, ctx, dest) {
  var template = fs.readFileSync(src, 'UTF-8'),
      rendered = _.template(template, ctx);
  fs.writeFileSync(dest, rendered); 
}

function installCommonDevLibraries(cb) {
  var devLibs = [
        // For producing the final JS
        'browserify',
        'uglify-js',

        // For testing
        'chai',
        'mocha',

        // For code cleanliness
        'jscs',
        'jshint'
      ].sort(),
      args = ['install', '--save'].concat(devLibs);

  var proc = childproc.spawn('npm', args, { stdio: 'inherit' });
  proc.on('error', function(err) { cb(err); })
      .on('exit', function(code) {
        if (code) {
          cb(new Error('Installing ' + lib + ' failed. Errno: ' + code));
        } else {
          cb(null);
        }
      });
}

@@ -645,95 +645,128 @@
 %0A%0A  
-writePackageJson(data);%0A  renderTemplate(getLicenseFile(data.license), data, path.join(
+var license = readFile(getLicenseFile(data.license));%0A%0A  writePackageJson(data);%0A  writeFile(_.template(license, data), 
 cwd,
@@ -780,37 +780,41 @@
 SE')
-)
 ;%0A  
-renderTemplate(path.join
+writeFile(_.template(readFile
 (tem
@@ -837,36 +837,27 @@
 E.md'), data
+)
 , 
-path.join(
 cwd, 'README
@@ -865,37 +865,41 @@
 md')
-)
 ;%0A  
-renderTemplate(path.join
+writeFile(_.template(readFile
 (tem
@@ -933,20 +933,11 @@
 data
+)
 , 
-path.join(
 cwd,
@@ -952,17 +952,16 @@
 LOG.md')
-)
 ;%0A  inst
@@ -1446,24 +1446,285 @@
 icense);%0A%7D%0A%0A
+function readFile() %7B%0A  var file = path.join.apply(path, arguments);%0A  return fs.readFileSync(file, 'UTF-8');%0A%7D%0A%0Afunction writeFile(contents) %7B%0A  var file = path.join.apply(path, Array.prototype.slice.call(arguments, 1));%0A  fs.writeFileSync(file, contents);%0A%7D%0A%0A
 function wri
@@ -1971,16 +1971,16 @@
 e%0A  %7D;%0A%0A
+
   fs.wri
@@ -2041,182 +2041,8 @@
 %0A%7D%0A%0A
-function renderTemplate(src, ctx, dest) %7B%0A  var template = fs.readFileSync(src, 'UTF-8'),%0A      rendered = _.template(template, ctx);%0A  fs.writeFileSync(dest, rendered); %0A%7D%0A%0A
 func

Remove renderTemplate helper