2

A while back I asked how to override sails.js blueprints (CRUD blueprint overriding in sails.js)

With v0.11 of sails.js we now have blueprints (and they are awesome :)).

Is it possible to turn off the current blueprints and install a new version of them as a hook? This issue comment (https://github.com/balderdashy/sails/pull/2173#issuecomment-54165548) from @sgress454 seems to indicate it is/was in the works, but I can't find anything more specific about it.

I know I can override by creating an api/blueprints folder, but it would be easier for my users to consume via an npm install.

Community
  • 1
  • 1
davepreston
  • 1,260
  • 1
  • 10
  • 20

1 Answers1

0

You are right, this is possible.

It is actually what happens in Sails's core here : https://github.com/balderdashy/sails/tree/master/lib/hooks/blueprints Default blueprints are loaded like an Installable Hook would be.

You can just go ahead and copy that MIT licensed code and then replace the content of the actions directory with your own blueprints. After that, update the object BlueprintController in index.js to make sure it points to your files.

Finally, all the magic happens in the extendControllerMiddleware method. You can see the code will go through each controller to inject your blueprints. The key point here is the replace the call to _.defaults with _.assign because your sails hook will want to overwrite defaults blueprints and not simply add them if they do not exist.

dynamic_cast
  • 1,075
  • 1
  • 9
  • 23