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/` |
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 Flat layout detection description is slightly inaccurate. The code treats a project as "flat" whenever both app/ and public/ are not present (i.e., either folder missing), not only when neither exists. Update the table wording to match the actual detection behavior.

Suggested change
| **Flat** | Default (no `app/` + `public/`) | `/models`, `/handlers`, etc. | `/tests/` |
| **Flat** | Default (when either `app/` or `public/` is missing) | `/models`, `/handlers`, etc. | `/tests/` |

Copilot uses AI. Check for mistakes.

#### 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
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",
boolean integrationTests = true,
appMapping = "/",
testsDirectory = "tests/specs/integration",
directory = "handlers",
directory = getAppPrefix( getCWD() ) & "handlers",
description = "I am a new handler",
Comment on lines 43 to 50
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 documentation currently says the handler default directory is /handlers (and the @directory param says it defaults to handlers), but the default now depends on layout detection (handlers vs app/handlers, and similarly for viewsDirectory). Update the help text/param docs so the CLI help matches the new behavior.

Copilot uses AI. Check for mistakes.
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,
Comment on lines 29 to 33
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 above still state the default interceptor directory is /interceptors, but the default now depends on layout detection (interceptors vs app/interceptors). Update the description/param docs so the CLI help matches the new behavior.

Copilot uses AI. Check for mistakes.
boolean force = false,
boolean boxlang = isBoxLangProject( getCWD() )
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 22 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 above still state the default layout directory is /layouts, but the default now depends on layout detection (layouts vs app/layouts). Update the description/param docs so the CLI help matches the new behavior.

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",
description = "I am a new Model Object",
Comment on lines 61 to 64
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 above still state the default model directory is /models, but the default now depends on layout detection (models vs app/models). Update the description/param docs so the CLI help matches the new behavior.

Copilot uses AI. Check for mistakes.
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",
boolean tests = true,
Comment on lines 23 to 27
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 @handlersDirectory / @viewsDirectory parameter docs still say the defaults are handlers and views, but the defaults now depend on layout detection (handlers vs app/handlers, views vs app/views). Update the help text so the CLI help matches the new behavior.

Copilot uses AI. Check for mistakes.
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",
boolean tests = true,
Comment on lines 92 to 97
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 @handlersDirectory / @viewsDirectory / @modelsDirectory parameter docs still say the defaults are handlers, views, and models, but the defaults now depend on layout detection (* vs app/*). Update the help text so the CLI help matches the new behavior.

Copilot uses AI. Check for mistakes.
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 34 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 command help/docs above still state the default output directory is /models, but the default now depends on layout detection (models vs app/models). Update the description/param docs so the displayed CLI help matches the new 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 23 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 above still state the default view directory is /views, but the default now depends on layout detection (views vs app/views). Update the description/param docs so the CLI help matches the new behavior.

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/" : "";
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.

Use arguments.cwd when calling detectTemplateType() to match the explicit argument scoping used elsewhere in this component (and avoid any potential name collisions with variables in other scopes).

Suggested change
return variables.utility.detectTemplateType( cwd ) == "modern" ? "app/" : "";
return variables.utility.detectTemplateType( arguments.cwd ) == "modern" ? "app/" : "";

Copilot uses AI. Check for mistakes.
}

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