Calling `ember g component` within a blueprint's index.js


#1

Not sure if this is even possible, but I want a blueprint to automatically create a corresponding component in its afterInstall/afterUninstall hook. The thing is, I can’t simply:

afterInstall: function(options) {
  ember g component options.entity.name;
}

But maybe there’s a way to hook into the actual command? Or some more elegant/build-in solution?


#2

Nevermind, just found an excellent example to follow here.


#3

For anyone who wants to do this, here’s how I pulled it off:

// blueprints/my-blueprint/index.js

var Blueprint = require('ember-cli/lib/models/blueprint');
var blueprints = ['component', 'component-addon'].map(function(name) {
  return Blueprint.lookup(name);
});

module.exports = {
  description: '',

  beforeInstall: function(options) {
    blueprints.forEach(function(blueprint) {
      blueprint.install(options);
    });
  },

  beforeUninstall: function(options) {
    blueprints.forEach(function(blueprint) {
      blueprint.uninstall(options);
    });
  }
};

Then in my corresponding test blueprint:

// blueprints/my-blueprint-test/index.js

var Blueprint = require('ember-cli/lib/models/blueprint');
var componentBlueprint = Blueprint.lookup('component-test');

module.exports = {
  description: '',

  beforeInstall: function(options) {
    return componentBlueprint.install(options);
  },

  beforeUninstall: function(options) {
    return componentBlueprint.uninstall(options);
  }
};

#4

@nullnullnull One of those beforeUninstall keys should be afterInstall, right?

Also, thanks for the thread! I found it helpful.


#5

I’ve posted an updated answer to this question at http://stackoverflow.com/q/38464568/1067145. The approach here was a step in the right direction, but it didn’t work for me out-of-the-box.