Search code examples
ember.jscode-generationember-cli

Generate another blueprint from an Ember CLI blueprint


I've created a custom blueprint based on the docs at ember-cli and I want to run a different blueprint (essentially ember g something-else ...) from inside my first blueprint. How can I do this?

Specific use-case: I've overrode Ember CLI's default Component blueprint, and I want to generate a matching CSS partial (in app/styles/components/) for every generated Component, inside my new Component blueprint.


Solution

  • Inside your generator (probably app/blueprints/blueprint-name/index.js):

    var Blueprint = require('ember-cli/lib/models/blueprint');
    
    module.exports = {
    
      ...
    
      afterInstall: function(options) {
        var otherBlueprint = Blueprint.lookup('other-blueprint-name', {
          paths: [path.resolve(__dirname, '..')]
        });
    
        return otherBlueprint.install(options);
      },
    };
    

    Thanks to nullnullnull for pointing out this approach at calling-ember-g-component-within-a-blueprints-index-js.