commands/create.js
function(template, parent) {
    var templateLocation;
    if (templateNameToRepo[template].startsWith('file://')) {
      templateLocation = templateNameToRepo[template].slice(7);
    } else {
      templateLocation = path.join(path.homedir(), '.khaos', 'templates', template);
    }
    return function(callback, results) {
      var processTemplate = function(location, cb) {
        var khaos = new Khaos(path.join(templateLocation, 'template'));
        khaos.read(function(err, files) {
          if (err) return cb(err);
          khaos.parse(files, function(err2, schema) {
            if (err2) return cb(err2);

            // only prompt for new variables
            var newVars = _.omit(schema, _.keys(results[parent] || args.answers));
            khaos.prompt(newVars, function(err3, answers) {
              if (err3) return cb(err3);

              // merge new answers with existing ones and pass to next template
              answers = _.merge(answers, results[parent] || args.answers || {});
              khaos.write(results.destination, files, answers, function(err4) {
                cb(err4, answers);
              });
            });
          });
        });
      };

      // download from github if not yet locally cached
      if (!exists(templateLocation)) {
        download(templateNameToRepo[template], templateLocation, function(err) {
          if (err) return callback(err);
          processTemplate(templateLocation, callback);
        });
      } else {
        processTemplate(templateLocation, callback);
      }
    };
  }
function(template, parent) {
    var templateLocation;
    if (templateNameToRepo[template].startsWith('file://')) {
      templateLocation = templateNameToRepo[template].slice(7);
    } else {
      templateLocation = path.join(path.homedir(), '.khaos', 'templates', template);
    }
    return function(callback, results) {
      var processTemplate = function(location, cb) {
        var khaos = new Khaos(path.join(templateLocation, 'template'));
        khaos.read(function(err, files) {
          if (err) return cb(err);
          khaos.parse(files, function(err2, schema) {
            if (err2) return cb(err2);

            // only prompt for new variables
            var newVars = _.omit(schema, _.keys(results[parent] || args.answers));
            khaos.prompt(newVars, function(err3, answers) {
              if (err3) return cb(err3);

              // merge new answers with existing ones and pass to next template
              answers = _.merge(answers, results[parent] || args.answers || {});
              khaos.write(results.destination, files, answers, function(err4) {
                cb(err4, answers);
              });
            });
          });
        });
      };

      // download from github if not yet locally cached
      if (!exists(templateLocation)) {
        download(templateNameToRepo[template], templateLocation, function(err) {
          if (err) return callback(err);
          processTemplate(templateLocation, callback);
        });
      } else {
        processTemplate(templateLocation, callback);
      }
    };
  }
function ( template , parent ) { var templateLocation ; if ( templateNameToRepo [ template ] . startsWith ( 'file://' ) ) { templateLocation = templateNameToRepo [ template ] . slice ( 7 ) ; } else { templateLocation = path . join ( path . homedir ( ) , '.khaos' , 'templates' , template ) ; } return function ( callback , results ) { var processTemplate = function ( location , cb ) { var khaos = new Khaos ( path . join ( templateLocation , 'template' ) ) ; khaos . read ( function ( err , files ) { if ( err ) return cb ( err ) ; khaos . parse ( files , function ( err2 , schema ) { if ( err2 ) return cb ( err2 ) ; // only prompt for new variables var newVars = _ . omit ( schema , _ . keys ( results [ parent ] || args . answers ) ) ; khaos . prompt ( newVars , function ( err3 , answers ) { if ( err3 ) return cb ( err3 ) ; // merge new answers with existing ones and pass to next template answers = _ . merge ( answers , results [ parent ] || args . answers || { } ) ; khaos . write ( results . destination , files , answers , function ( err4 ) { cb ( err4 , answers ) ; } ) ; } ) ; } ) ; } ) ; } ; // download from github if not yet locally cached if ( ! exists ( templateLocation ) ) { download ( templateNameToRepo [ template ] , templateLocation , function ( err ) { if ( err ) return callback ( err ) ; processTemplate ( templateLocation , callback ) ; } ) ; } else { processTemplate ( templateLocation , callback ) ; } } ; }
add khaos tasks for each template in the dependency tree
add khaos tasks for each template in the dependency tree