The document discusses modular development in modern CFML. It defines packages and modules, explaining that packages are reusable code that can be a single function or an entire application, while modules add lifecycle methods. It provides examples of installing packages and module locations. It also covers versioning, dependencies, and automating release processes through package scripts.
2. What is a package?
Reusable, self contained, self describing, versioned code, functionality, or
application building blocks.
● A folder
● A box.json file
● Some code
A package could be a single UDF or an entire CMS. What makes it portable is the
agreed format of packaging, distribution, and installation.
3. What is a module?
A Box module is everything a package is, but with additional conventions and
lifecycle methods defined by ColdBox, ContentBox, CommandBox, etc.
● A folder
● A box.json file
● A ModuleConfig.cfc
● Some code
A Module could be a single interceptor or an entire shopping cart. Box modules are
“active” the framework loads them and they can run custom logic on registration as
well as contribute behaviors or functionality to the base app.
6. ● Packages can depend on other packages
● Promotes reusability and smaller, single-purpose packages
● cborm
○ cbvalidation
■ Cb18n
● Dev dependencies
○ Only required for developing on the project (like testing frameworks)
○ Don’t want installed on production
○ Use “install --production” to skip
Package Dependencies
8. Turn any folder into a package with one CLI command:
package init
Want some hand holding?
package init --wizard
Set additional metadata with:
package set name=”My Package”
Let’s create a package
9. Scaffold out a new module with one CLI command:
coldbox create module myModule
Let’s take a look at the ModuleConfig.cfc
component {
function configure() {
}
}
Let’s create a module
10. modules/
These are modules managed by CommandBox. Usually 3rd party. Not committed to
source control.
modules_app/
These are modules that are a core part of your app that you want to be part of the
main source repo. CommandBox doesn’t not manage them.
Box Module Locations
11. A ForgeBox account is free, easy, and let’s you publish packages and collaborators
forgebox register
Already have a ForgeBox account?
forgebox login
Create a ForgeBox account
12. ● What happens when your code changes?
● You need to increment the version!
● Semantic versioning
○ Major
○ Minor
○ Patch
○ Prerelease Identifier
○ Build ID
Versioning
❏ 5
❏ 3.2
❏ 1.7.8
❏ 1.2.3-alpha
❏ 5.6+0045
❏ 2-beta.3
❏ 1.2.3-rc.4+9876
13. Semver Ranges
● Give me the latest version that starts with 5
○ 5.x
● Any version greater than 1.0.0 starting with 1.0.1
○ >1.0.0
● Any version between 2.0.0 and 2.5.0 inclusive
○ >=2.0.0 <=2.5.0
○ 2.0.0 - 2.5.0
● Any one of these exact versions
○ 1.0.0 || 2.0.0 || 3.0.0
● Allows 1.2.4 and 1.3, but not 2.0 (same as 1.x.x)
○ ^1.2.3
14. From the CLI
install coldbox@4.3
install testbox@<=2.6
In your box.json
“dependencies” : {
“coldbox” : “4.3”,
“Testbox” : “<=2.6”
}
Install a Specific Version
15. Automatically increment version numbers in box.json
● bump --major
● bump --minor
● bump --patch
If package is a Git repo, a tag will be created that matches the version number.
This helps “lock in” the exact commit of this version.
Bump Command
16. ● Arbitrary commands of your choice to run at interception points
● postVersion
● onRelease
● postPublish
● Ties multiple steps together
● Automates repetitive bits
● Boils releasing down to a single command
"scripts" : {
"postVersion":"package set location='Ortus-Solutions/commandbox-cfconfig#v`package version`'",
"onRelease":"publish",
"postPublish":"!git push --follow-tags",
}
Package Scripts
17. A nice tool for scaffolding box modules complete with tests, Travis-CI builds, and
package scripts.
module scaffold myCoolModule
https://www.forgebox.io/view/cb-module-template
cbModuleTemplate Module
18. ● Your code
● Frameworks
● 3rd party modules
● Your modules
● Git ignores
● box.json
● “Install” command
● --production flag
Building Your Apps