We have a complex monolithic application that has a folder of 60+ controllers, some 1000 lines long.
We're going through a big refactor of a codebase to reduce the line-length of files by code-splitting.
For example, a controller might have 4 functions, find, delete, findOne, update
etc.
What I'd like to do is change the directory structure from a flat approach:
controllers/ ControllerOne.js ...
to:
controllers/ controllerOne/ update.js find.js findOne.js delete.js index.js ...
Where index.js
exports the same object that ControllerOne.js
traditionally would.
I've achieved this by leaving the root ControllerOne.js
in the controllers directory, and importing controllerOne/index.js
into it, then exporting it.
This works, but isn't clean as we end up with a redundant Controller file which exports the same methods as index.js, it also pollutes the directory with unnecessary files.
Additionally, Sails warns you in the console the the update.js files etc are ignored and don't fit the standard controller pattern (obviously)
Has anyone achieved this pattern and has any ideas how we can achieve this?
Aucun commentaire:
Enregistrer un commentaire