Add folders to your template
Members of collections, folders of your own, and what each does to the template.
A template says what may be created in a folder, and Barnark creates it with the template’s whole structure, so the template and the folders stay in step. Two things can be added: a member of a collection, and a folder of your own.
Ask a folder what it offers #
template:offers lists what can be created in a folder. The browser app draws its “Create New …” buttons from the same list.
$ vendor/bin/barnark template:offers src/Context
Barn: …/hotel
Slots offered in /src/Context by 'Hotel'
========================================
--------- --------- -------------------------------------------------
Slot Key Create it with
--------- --------- -------------------------------------------------
Context Context barnark template:new Context <name> src/Context
--------- --------- -------------------------------------------------
The last column is the command to run. A folder that holds only fixed parts offers nothing:
$ vendor/bin/barnark template:offers src/Context/Reservation
Barn: …/hotel
Slots offered in /src/Context/Reservation by 'Hotel'
====================================================
None. Nothing named can be created directly here.
A folder offers slots only where the part or slot it stands for has slots of its own.
A folder also offers nothing when the template names nothing inside it, or when it sits outside the template altogether.
Add a member #
template:new adds a member you name to a collection. The template records it as a new revision, and the
member’s folder arrives with the folders its member type holds. A Context comes with its Domain,
Application, Infrastructure and PublicApi.
$ vendor/bin/barnark template:new Context Reservation src/Context
Barn: …/hotel
New Context 'Reservation'
=========================
…/hotel/src/Context/Reservation
…/hotel/src/Context/Reservation/Application
…/hotel/src/Context/Reservation/Application/Command
…
[OK] Created …/hotel/src/Context/Reservation, added to the template as
Context.
Check it with `barnark template:check`.
Members nest. A context’s Domain folder is itself a collection of aggregates:
$ vendor/bin/barnark template:offers src/Context/Reservation/Domain
Barn: …/hotel
Slots offered in /src/Context/Reservation/Domain by 'Hotel'
===========================================================
----------- ----------- ----------------------------------------------------------------------
Slot Key Create it with
----------- ----------- ----------------------------------------------------------------------
Aggregate Aggregate barnark template:new Aggregate <name> src/Context/Reservation/Domain
----------- ----------- ----------------------------------------------------------------------
$ vendor/bin/barnark template:new Aggregate Booking src/Context/Reservation/Domain
Barn: …/hotel
New Aggregate 'Booking'
=======================
…/hotel/src/Context/Reservation/Domain/Booking
[OK] Created …/hotel/src/Context/Reservation/Domain/Booking, added to the
template as Aggregate.
Check it with `barnark template:check`.
The first argument is the slot as template:offers names it. Ask for one the folder doesn’t offer and Barnark lists
the ones it does, rather than guessing:
$ vendor/bin/barnark template:new Widget Invoices app
Barn: …/hotel
[ERROR] 'Shop' does not offer a 'Widget' in 'app'.
It offers:
Feature
A feature at a time #
Feature Based Architecture makes only its folder, then each feature arrives with the folders a feature holds:
$ vendor/bin/barnark template:new Feature Invoices app
Barn: …/hotel
New Feature 'Invoices'
======================
…/hotel/app/Invoices
…/hotel/app/Invoices/Controller
…/hotel/app/Invoices/Entity
…/hotel/app/Invoices/Exception
…/hotel/app/Invoices/Repository
…
$ find app | sort
app
app/Invoices
app/Invoices/Controller
app/Invoices/Controller/.gitkeep
app/Invoices/Entity
app/Invoices/Entity/.gitkeep
app/Invoices/Exception
app/Invoices/Exception/.gitkeep
app/Invoices/Repository
app/Invoices/Repository/.gitkeep
app/Invoices/Value
app/Invoices/Value/.gitkeep
Names #
A member’s name can’t be one that the collection already has, even ignoring case. A member already in the template is refused. Nothing already on disk is overwritten, so running a command again fills in only what is missing. This example ran in a project whose template was cloned from Library, with a feature Invoices already added:
$ vendor/bin/barnark template:new Feature invoices lib/Internal/Feature
Barn: …/hotel
[ERROR] 'invoices' can't name a member: the folder 'Invoices' is already
here, and differs from it only by case.
Add a folder of your own #
A folder that is none of the template’s members can be added to the template with
template:add-folder <path> <meaning>: a new revision with the folder in it, saying what belongs
there, and then the folder. A folder already made by hand is kept as it is, so this is also how a folder the check reports as
unexpected is taken in.
$ vendor/bin/barnark template:add-folder src/Scratch "Throwaway experiments."
Barn: …/hotel
[OK] Added /src/Scratch to the template.
Check it with `barnark template:check`.
One folder is added at a time. A folder inside one you have taken in is added on its own, and the folder above it must
be in the template already. A collection holds only members, so a folder inside one is refused. In the same Library project, Internal/Feature is a collection:
$ vendor/bin/barnark template:add-folder lib/Internal/Feature/Extras "x"
Barn: …/hotel
[ERROR] The template can't take that change at 'lib/Internal/Feature/Extras':
'Internal/Feature' is a collection, which holds only members of its
member type.
Change what a folder means #
template:change-meaning changes the words that say what a folder of the template, or an ark’s folder itself, is for.
It is a revision of the template. No folder changes.
$ vendor/bin/barnark template:change-meaning src/Scratch "Notes."
Barn: …/hotel
[OK] Changed what /src/Scratch means.
A member’s meaning is its member type’s, so it can’t be changed on its own. A folder that the template uses in several places can’t be changed in only one, since the change would reach each.
Where to run the commands #
Every command prints the barn’s root first and works from any folder inside the barn. Paths are relative to the root.
A command that takes a path to create in, such as template:new, takes . to mean the folder you are in:
$ cd src/Context
$ ../../vendor/bin/barnark template:new Context FrontDesk .
Next: check the project.