Wednesday, November 15, 2017

Actions in Bouquet

Sails 1.0 added the concept of actions to the architecture. This has given me an idea to add actions to the bouquet generate suite. An action is basically a function that is called when a route in a controller is accessed. Each action is in it own file. Which makes life very easy for generators. 

Bouquet Actions

I recently (Nov 2017) extended bouquet to handle the creation of Actions for Controllers. The concept behind this is to auto generate tests, command line interface and controllers for the actions created.

Pattern

  1. An action is created for a specific controller. in the controllers/<controller name> directory.
  2. And a corresponding binary is created to access the action. bin/<projectName>-<controller>-<action>.
  3. Next a test for the binary is created in the test/bin directory <controller>-<name>.test.js
  4. Finally a test set of test cases is created for the action via the controller test/integration/<controller>-<name>.test.js

Here is a breakdown of what gets created.


  • api/controllers/<controller>/<action>.js
  • bin/<project name>-<controller name>-<action name>     
  • test/bin/<controller-name>-<action-name>.test.js
  • test/integration/<controller-name>-<action-name>.test.js

Usage

$ sails generate bouquet-Action <controller> <action>
In this example I am generating a action name create for the stack controller.
$ sails generate bouquet-Action stack create 
will generate
# api/controllers/stack/create.js
# bin/bouquet-stack-create
# test/bin/stack-create.test.js
# test/integration/stack-create.test.js

If you have any additional ideas just let me know darren@pulsipher.org.

DWP