With Ember-CLI you now need to run ember generate <addon-name>
to instantiate the addon into your application. This is also
true with sub-addons.
Using the above method, you can essentially run
ember generate <sub-addon-name>
. The addon needs to be included
as a hard dependency in your package.json
. We can then configure
our blueprint in blueprints/<addon-name>/index.js
.
We want to run the sub addon blueprints after our addon blueprint
has completed. We will use the afterInstall
hook for this.
The first thing we need to do is gain access to the task for running a blueprint:
var blueprintTask = this.taskFor('generate-from-blueprint');
Once we have the task, we need to create the options object to pass
to it. The options object reflects the arguments available at
the command line, --dry-run
and --verbose
.
var options = {
args: ['<sub-addon-name>'],
dryRun: false,
verbose: false,
disableAnalytics: false
};
The generate-from-blueprint
task requires the blueprint name to be in
the options.args
array as the first element.
To properly complete the afterInstall
hook, we need to return a promise.
To allow tasks to run in an asynchronous manner, methods such as
addPackageToProject
and addBowerPackageToProject
return a promise.
The blueprint task's run
method also returns a promise. This allows
us to call multiple sub-addon blueprints form our blueprint.
This method can be used to call built in blueprints from Ember-CLI. This
means you can generate routes
, resources
, controllers
etc. by chaining
the blueprintsTask.run()
calls at the end of the afterInstall
return.