'use strict';

var debug = require('debug')('base:base-generators:generator');
var utils = require('./utils');

/**
 * Set the parent context for `app`. The `parent` property is used
 * to resolve `app.base`
 *
 * @param {Object} `app`
 * @param {Object} `parent`
 */

exports.setParent = function setParent(app, parent) {
  app.options = utils.merge({}, parent.options, app.options);

  var emit = app.emit;
  app.define('emit', function() {
    parent.emit.apply(parent, arguments);
    emit.apply(app, arguments);
  });

  app.define('parent', parent);
  parent.run(app);
};

/**
 * Decorate `app` with `env` properties used for lookups
 * and invoking.
 */

exports.decorate = function decorate(app, ctx) {

  /**
   * Get the generator `alias`
   *
   * @getter
   * @return {String} Returns the value from `generator.env.alias`
   * @api public
   */

  app.define('alias', {
    configurable: true,
    get: function() {
      return ctx.env.alias;
    }
  });

  /**
   * Get the generator `name`
   *
   * @getter
   * @return {String} Returns the value from `generator.env.name`
   * @api public
   */

  app.define('name', {
    configurable: true,
    get: function() {
      return ctx.env.name;
    }
  });

  /**
   * Invoke `generator.fn` with the given `options` and optional `context`.
   *
   * @param {Object} `options`
   * @param {Object} `context`
   * @return {Object} Returns the context object or generator instance, modified by invoking `fn`.
   * @api public
   */

  app.define('invoke', function(options, context) {
    return ctx.env.invoke(context || ctx, options);
  });

  /**
   * Returns true if `str` matches one of the following properties on `generator.env`
   * - `key`: the original name used to register the generator
   * - `name`: the name of the generator. this can be different than `key` if the generator was registered using a filepath.
   * - `path`: the file path of the generator.
   *
   * @param {String} `str`
   * @return {Boolean}
   * @api public
   */

  app.define('isMatch', function(str) {
    return ctx.env.isMatch(str);
  });
}

@@ -12,72 +12,8 @@
 ';%0A%0A
-var debug = require('debug')('base:base-generators:generator');%0A
 var 
@@ -364,28 +364,77 @@
 ', function(
+name
 ) %7B%0A
+    if (!/starting%7Cfinished/.test(name)) %7B%0A  
     parent.e
@@ -463,16 +463,22 @@
 ments);%0A
+    %7D%0A
     emit
@@ -694,16 +694,46 @@
 , ctx) %7B
+%0A  var name, alias, namespace;
 %0A%0A  /**%0A
@@ -912,32 +912,80 @@
 igurable: true,%0A
+    set: function() %7B%0A      alias = val;%0A    %7D,%0A
     get: functio
@@ -994,32 +994,50 @@
 ) %7B%0A      return
+ alias %7C%7C (alias =
  ctx.env.alias;%0A
@@ -1034,16 +1034,17 @@
 nv.alias
+)
 ;%0A    %7D%0A
@@ -1249,51 +1249,592 @@
     
-get: function() %7B%0A      return ctx.env.name
+set: function(val) %7B%0A      name = val;%0A    %7D,%0A    get: function() %7B%0A      return name %7C%7C (name = ctx.env.name);%0A    %7D%0A  %7D);%0A%0A  /**%0A   * Get the generator %60namespace%60%0A   *%0A   * @getter%0A   * @return %7BString%7D Returns the value from %60generator.env.namespace%60%0A   * @api public%0A   */%0A%0A  app.define('namespace', %7B%0A    configurable: true,%0A    set: function(val) %7B%0A      namespace = val;%0A    %7D,%0A    get: function() %7B%0A      if (namespace) return namespace;%0A      if (ctx.parent && ctx.parent.namespace) %7B%0A        return ctx.parent.namespace + '.' + ctx.alias;%0A      %7D%0A      return ctx.env.alias
 ;%0A  
@@ -2713,9 +2713,11 @@
 %0A  %7D);%0A%7D
+;%0A
 %0A

add setters