Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,62 @@ The CLI detects BoxLang projects using three methods (in order of precedence):
}
```

### 🗂️ App Layout Detection

The CLI automatically detects whether your project uses a **modern** or **flat** layout and generates files in the correct location.

| Layout | Detection | App Code Location | Tests Location |
| ------ | --------- | ----------------- | -------------- |
| **Modern** | Both `app/` and `public/` directories exist | `/app/models`, `/app/handlers`, etc. | `/tests/` |
| **Flat** | Default (no `app/` + `public/`) | `/models`, `/handlers`, etc. | `/tests/` |

#### Modern Layout (e.g. `boxlang`, `modern` templates)

```text
/app - Application source code
/config - Configuration
/handlers - Event handlers
/models - Models & services
/views - View templates
/layouts - Layout wrappers
/interceptors - Interceptors
/public - Web root
/modules - ColdBox modules
/tests - Test suites
/resources - Migrations, seeders, etc.
```

#### Flat Layout (e.g. `flat`, legacy templates)

```text
/config - Configuration
/handlers - Event handlers
/models - Models & services
/views - View templates
/layouts - Layout wrappers
/interceptors - Interceptors
/modules - ColdBox modules
/tests - Test suites
```

When you run a generation command in a modern-layout project, the CLI automatically targets the correct directory:

```bash
# In a flat layout project → creates /handlers/users.cfc
# In a modern layout project → creates /app/handlers/users.cfc
coldbox create handler users

# In a flat layout project → creates /models/User.cfc
# In a modern layout project → creates /app/models/User.cfc
coldbox create model User
```

You can always override the target directory explicitly:

```bash
coldbox create model User directory=app/models
```

#### 🚀 Usage Examples

```bash
Expand Down
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"ColdBox CLI",
"version":"8.9.0",
"version":"8.10.0",
"location":"https://downloads.ortussolutions.com/ortussolutions/commandbox-modules/coldbox-cli/@build.version@/coldbox-cli-@build.version@.zip",
"slug":"coldbox-cli",
"author":"Ortus Solutions, Corp",
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Automatic app layout detection for code generation commands. The CLI now detects whether the project uses a modern layout (with `app/` and `public/` directories) or a flat layout, and automatically places generated files in the correct location (e.g., `app/models` vs `models`, `app/handlers` vs `handlers`, etc.).

## [8.9.0] - 2026-04-07

### Updates
Expand Down
4 changes: 2 additions & 2 deletions commands/coldbox/create/handler.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ component aliases="coldbox create controller" extends="coldbox-cli.models.BaseCo
required name,
actions = "",
boolean views = true,
viewsDirectory = "views",
viewsDirectory = getAppPrefix( getCWD() ) & "views",
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock text says viewsDirectory defaults to views, but this argument now defaults to a layout-aware path (app/views in modern layouts). Update the docs so the documented default matches runtime behavior.

Copilot uses AI. Check for mistakes.
boolean integrationTests = true,
appMapping = "/",
testsDirectory = "tests/specs/integration",
directory = "handlers",
directory = getAppPrefix( getCWD() ) & "handlers",
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock/header says the handler directory defaults to handlers, but this argument now defaults to a layout-aware path (app/handlers in modern layouts). Update the docs so users see the correct default.

Copilot uses AI. Check for mistakes.
description = "I am a new handler",
boolean open = false,
boolean rest = false,
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/interceptor.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ component extends="coldbox-cli.models.BaseCommand" {
description = "I am a new interceptor",
boolean tests = true,
testsDirectory = "tests/specs/interceptors",
directory = "interceptors",
directory = getAppPrefix( getCWD() ) & "interceptors",
boolean open = false,
boolean force = false,
boolean boxlang = isBoxLangProject( getCWD() )
Comment on lines 31 to 35
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header/docs still state the default interceptor directory is /interceptors, but this default directory argument is now layout-aware (app/interceptors in modern layouts). Update the docs to match the new behavior.

Copilot uses AI. Check for mistakes.
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/layout.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ component extends="coldbox-cli.models.BaseCommand" {
function run(
required name,
boolean helper = false,
directory = "layouts",
directory = getAppPrefix( getCWD() ) & "layouts",
boolean open = false,
Comment on lines 21 to 25
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command docs say the default layout directory is /layouts, but the default directory argument now resolves to app/layouts for modern layouts. Update the header/@Directory docs accordingly so users aren’t misled.

Copilot uses AI. Check for mistakes.
boolean force = false,
content = "<h1>#arguments.name# Layout</h1>#variables.utility.BREAK#",
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/model.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ component extends="coldbox-cli.models.BaseCommand" {
persistence = "transient",
boolean tests = true,
testsDirectory = "tests/specs/unit",
directory = "models",
directory = getAppPrefix( getCWD() ) & "models",
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file header/docs still state the default output directory is /models, but this directory argument is now layout-aware (app/models in modern layouts). Update the header/@Directory docs to match the new default behavior.

Copilot uses AI. Check for mistakes.
description = "I am a new Model Object",
boolean open = false,
boolean accessors = true,
Expand Down
4 changes: 2 additions & 2 deletions commands/coldbox/create/orm-crud.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ component extends="coldbox-cli.models.BaseCommand" {
function run(
required entity,
pluralName = "",
handlersDirectory = "handlers",
viewsDirectory = "views",
handlersDirectory = getAppPrefix( getCWD() ) & "handlers",
viewsDirectory = getAppPrefix( getCWD() ) & "views",
Comment on lines +25 to +26
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock still says handlersDirectory defaults to handlers and viewsDirectory defaults to views, but these are now layout-aware defaults (app/handlers and app/views in modern layouts). Update the docs so they match actual behavior.

Copilot uses AI. Check for mistakes.
boolean tests = true,
testsDirectory = "tests/specs/integration",
boolean boxlang = isBoxLangProject( getCWD() )
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/orm-entity.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ component extends="coldbox-cli.models.BaseCommand" {
function run(
required entityName,
table = "",
directory = "models",
directory = getAppPrefix( getCWD() ) & "models",
boolean activeEntity = false,
primaryKey = "id",
primaryKeyColumn = "",
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/orm-service.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ component extends="coldbox-cli.models.BaseCommand" {
**/
function run(
required serviceName,
directory = "models",
directory = getAppPrefix( getCWD() ) & "models",
boolean queryCaching = false,
boolean eventHandling = true,
cacheRegion = "",
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/orm-virtual-service.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ component extends="coldbox-cli.models.BaseCommand" {
**/
function run(
required entityName,
directory = "models",
directory = getAppPrefix( getCWD() ) & "models",
boolean queryCaching = false,
boolean eventHandling = true,
cacheRegion = "",
Expand Down
6 changes: 3 additions & 3 deletions commands/coldbox/create/resource.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ component extends="coldbox-cli.models.BaseCommand" {
generator = "native",
properties = "",
modulesDirectory = "modules_app",
handlersDirectory = "handlers",
viewsDirectory = "views",
modelsDirectory = "models",
handlersDirectory = getAppPrefix( getCWD() ) & "handlers",
viewsDirectory = getAppPrefix( getCWD() ) & "views",
modelsDirectory = getAppPrefix( getCWD() ) & "models",
Comment on lines +94 to +96
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock still claims handlersDirectory/viewsDirectory/modelsDirectory default to handlers/views/models, but these defaults are now layout-aware (prefixed with app/ in modern layouts). Update the docs so the documented defaults match behavior.

Copilot uses AI. Check for mistakes.
boolean tests = true,
specsDirectory = "tests/specs",
boolean api = false,
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/service.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ component extends="coldbox-cli.models.BaseCommand" {
methods = "",
boolean tests = true,
testsDirectory = "tests/specs/unit",
directory = "models",
directory = getAppPrefix( getCWD() ) & "models",
description = "I am a new service",
Comment on lines 33 to 37
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file header/docs still state the default output directory is /models, but the default directory argument now resolves to app/models for modern layouts. Update the command documentation/@Directory description to reflect the new modern-vs-flat default behavior.

Copilot uses AI. Check for mistakes.
boolean open = false,
boolean force = false,
Expand Down
2 changes: 1 addition & 1 deletion commands/coldbox/create/view.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ component extends="coldbox-cli.models.BaseCommand" {
function run(
required name,
boolean helper = false,
directory = "views",
directory = getAppPrefix( getCWD() ) & "views",
boolean open = false,
Comment on lines 22 to 26
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command docs mention the default output directory is /views, but the default directory argument now resolves to app/views for modern layouts. Update the header/@Directory docs to match the new layout-aware default.

Copilot uses AI. Check for mistakes.
content = "<h1>#arguments.name# view</h1>",
boolean force = false,
Expand Down
13 changes: 13 additions & 0 deletions models/BaseCommand.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ component accessors="true" {
return this;
}

/**
* Detects the application layout and returns the appropriate path prefix.
* In a modern layout (app/ and public/ directories exist), returns "app/".
* In a flat layout, returns "".
*
* @cwd The current working directory
*
* @return string "app/" for modern layout, "" for flat layout
*/
function getAppPrefix( required cwd ){
return variables.utility.detectTemplateType( cwd ) == "modern" ? "app/" : "";
}

/**
* Determines if we are running on a BoxLang server
* or using the BoxLang runner.
Expand Down