Skip to content

Commit 49a4191

Browse files
authored
Merge pull request #51 from ColdBox/copilot/add-app-path-setting
Auto-detect app layout and generate files in correct path (flat vs modern)
2 parents ffa124a + a1e3a7e commit 49a4191

File tree

14 files changed

+88
-15
lines changed

14 files changed

+88
-15
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,62 @@ The CLI detects BoxLang projects using three methods (in order of precedence):
486486
}
487487
```
488488

489+
### 🗂️ App Layout Detection
490+
491+
The CLI automatically detects whether your project uses a **modern** or **flat** layout and generates files in the correct location.
492+
493+
| Layout | Detection | App Code Location | Tests Location |
494+
| ------ | --------- | ----------------- | -------------- |
495+
| **Modern** | Both `app/` and `public/` directories exist | `/app/models`, `/app/handlers`, etc. | `/tests/` |
496+
| **Flat** | Default (no `app/` + `public/`) | `/models`, `/handlers`, etc. | `/tests/` |
497+
498+
#### Modern Layout (e.g. `boxlang`, `modern` templates)
499+
500+
```text
501+
/app - Application source code
502+
/config - Configuration
503+
/handlers - Event handlers
504+
/models - Models & services
505+
/views - View templates
506+
/layouts - Layout wrappers
507+
/interceptors - Interceptors
508+
/public - Web root
509+
/modules - ColdBox modules
510+
/tests - Test suites
511+
/resources - Migrations, seeders, etc.
512+
```
513+
514+
#### Flat Layout (e.g. `flat`, legacy templates)
515+
516+
```text
517+
/config - Configuration
518+
/handlers - Event handlers
519+
/models - Models & services
520+
/views - View templates
521+
/layouts - Layout wrappers
522+
/interceptors - Interceptors
523+
/modules - ColdBox modules
524+
/tests - Test suites
525+
```
526+
527+
When you run a generation command in a modern-layout project, the CLI automatically targets the correct directory:
528+
529+
```bash
530+
# In a flat layout project → creates /handlers/users.cfc
531+
# In a modern layout project → creates /app/handlers/users.cfc
532+
coldbox create handler users
533+
534+
# In a flat layout project → creates /models/User.cfc
535+
# In a modern layout project → creates /app/models/User.cfc
536+
coldbox create model User
537+
```
538+
539+
You can always override the target directory explicitly:
540+
541+
```bash
542+
coldbox create model User directory=app/models
543+
```
544+
489545
#### 🚀 Usage Examples
490546

491547
```bash

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
### Added
13+
14+
- 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.).
15+
1216
## [8.9.0] - 2026-04-07
1317

1418
### Updates

commands/coldbox/create/handler.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ component aliases="coldbox create controller" extends="coldbox-cli.models.BaseCo
4242
required name,
4343
actions = "",
4444
boolean views = true,
45-
viewsDirectory = "views",
45+
viewsDirectory = getAppPrefix( getCWD() ) & "views",
4646
boolean integrationTests = true,
4747
appMapping = "/",
4848
testsDirectory = "tests/specs/integration",
49-
directory = "handlers",
49+
directory = getAppPrefix( getCWD() ) & "handlers",
5050
description = "I am a new handler",
5151
boolean open = false,
5252
boolean rest = false,

commands/coldbox/create/interceptor.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ component extends="coldbox-cli.models.BaseCommand" {
2929
description = "I am a new interceptor",
3030
boolean tests = true,
3131
testsDirectory = "tests/specs/interceptors",
32-
directory = "interceptors",
32+
directory = getAppPrefix( getCWD() ) & "interceptors",
3333
boolean open = false,
3434
boolean force = false,
3535
boolean boxlang = isBoxLangProject( getCWD() )

commands/coldbox/create/layout.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ component extends="coldbox-cli.models.BaseCommand" {
2121
function run(
2222
required name,
2323
boolean helper = false,
24-
directory = "layouts",
24+
directory = getAppPrefix( getCWD() ) & "layouts",
2525
boolean open = false,
2626
boolean force = false,
2727
content = "<h1>#arguments.name# Layout</h1>#variables.utility.BREAK#",

commands/coldbox/create/model.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ component extends="coldbox-cli.models.BaseCommand" {
6060
persistence = "transient",
6161
boolean tests = true,
6262
testsDirectory = "tests/specs/unit",
63-
directory = "models",
63+
directory = getAppPrefix( getCWD() ) & "models",
6464
description = "I am a new Model Object",
6565
boolean open = false,
6666
boolean accessors = true,

commands/coldbox/create/orm-crud.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ component extends="coldbox-cli.models.BaseCommand" {
2222
function run(
2323
required entity,
2424
pluralName = "",
25-
handlersDirectory = "handlers",
26-
viewsDirectory = "views",
25+
handlersDirectory = getAppPrefix( getCWD() ) & "handlers",
26+
viewsDirectory = getAppPrefix( getCWD() ) & "views",
2727
boolean tests = true,
2828
testsDirectory = "tests/specs/integration",
2929
boolean boxlang = isBoxLangProject( getCWD() )

commands/coldbox/create/orm-entity.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ component extends="coldbox-cli.models.BaseCommand" {
5656
function run(
5757
required entityName,
5858
table = "",
59-
directory = "models",
59+
directory = getAppPrefix( getCWD() ) & "models",
6060
boolean activeEntity = false,
6161
primaryKey = "id",
6262
primaryKeyColumn = "",

commands/coldbox/create/orm-service.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ component extends="coldbox-cli.models.BaseCommand" {
2323
**/
2424
function run(
2525
required serviceName,
26-
directory = "models",
26+
directory = getAppPrefix( getCWD() ) & "models",
2727
boolean queryCaching = false,
2828
boolean eventHandling = true,
2929
cacheRegion = "",

commands/coldbox/create/orm-virtual-service.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ component extends="coldbox-cli.models.BaseCommand" {
2323
**/
2424
function run(
2525
required entityName,
26-
directory = "models",
26+
directory = getAppPrefix( getCWD() ) & "models",
2727
boolean queryCaching = false,
2828
boolean eventHandling = true,
2929
cacheRegion = "",

0 commit comments

Comments
 (0)