Skip to content

Auto-detect app layout and generate files in correct path (flat vs modern)#51

Merged
lmajano merged 3 commits intodevelopmentfrom
copilot/add-app-path-setting
Apr 10, 2026
Merged

Auto-detect app layout and generate files in correct path (flat vs modern)#51
lmajano merged 3 commits intodevelopmentfrom
copilot/add-app-path-setting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

Modern ColdBox templates (boxlang, modern) place app source under /app/, but all coldbox create * commands hardcoded paths like handlers, models, views — requiring developers to cd app or manually pass directory=app/models every time.

Changes

models/BaseCommand.cfc

  • Added getAppPrefix(cwd) — returns "app/" if both /app and /public directories exist (modern layout), "" otherwise. Delegates detection to the existing Utility.detectTemplateType().

All 13 coldbox create commands — default directory params now use getAppPrefix(getCWD()) & "<dir>":

Command Affected params
handler directory, viewsDirectory
model, service, orm-entity, orm-service, orm-virtual-service directory
view, layout, interceptor directory
resource handlersDirectory, viewsDirectory, modelsDirectory
orm-crud handlersDirectory, viewsDirectory

tests/, modules/, and resources/ paths are intentionally unchanged — those remain at the project root in both layouts.

Behavior

# Flat layout project → /handlers/users.cfc
# Modern layout project → /app/handlers/users.cfc
coldbox create handler users

# Override still works in either layout
coldbox create model User directory=custom/path

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add setting to specify app path for coldbox-cli Auto-detect app layout and generate files in correct path (flat vs modern) Apr 10, 2026
Copilot AI requested a review from lmajano April 10, 2026 09:55
@lmajano lmajano marked this pull request as ready for review April 10, 2026 10:15
Copilot AI review requested due to automatic review settings April 10, 2026 10:15
@lmajano lmajano merged commit 49a4191 into development Apr 10, 2026
5 checks passed
@lmajano lmajano deleted the copilot/add-app-path-setting branch April 10, 2026 10:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the ColdBox CLI generators to automatically target the correct app source directory based on whether the project uses a modern (/app + /public) or flat layout, reducing the need for manual directory= overrides.

Changes:

  • Added BaseCommand.getAppPrefix(cwd) to map detected layout → app/ prefix or no prefix.
  • Updated coldbox create * generators to default output directories to getAppPrefix(getCWD()) & "<dir>" for handlers/models/views/layouts/interceptors (and related CRUD/resource params).
  • Documented the new behavior in README.md and noted it in changelog.md.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
README.md Documents modern vs flat layout detection and where generators will output files.
changelog.md Adds an Unreleased note about automatic layout detection for generators.
models/BaseCommand.cfc Introduces getAppPrefix(cwd) helper based on Utility.detectTemplateType().
commands/coldbox/create/handler.cfc Defaults directory and viewsDirectory to respect detected layout.
commands/coldbox/create/interceptor.cfc Defaults directory to respect detected layout.
commands/coldbox/create/layout.cfc Defaults directory to respect detected layout.
commands/coldbox/create/model.cfc Defaults directory to respect detected layout.
commands/coldbox/create/service.cfc Defaults directory to respect detected layout.
commands/coldbox/create/view.cfc Defaults directory to respect detected layout.
commands/coldbox/create/resource.cfc Defaults handlersDirectory/viewsDirectory/modelsDirectory to respect detected layout.
commands/coldbox/create/orm-crud.cfc Defaults handlersDirectory/viewsDirectory to respect detected layout.
commands/coldbox/create/orm-entity.cfc Defaults directory to respect detected layout.
commands/coldbox/create/orm-service.cfc Defaults directory to respect detected layout.
commands/coldbox/create/orm-virtual-service.cfc Defaults directory to respect detected layout.

| 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.
* @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.
Comment on lines 34 to 37
boolean tests = true,
testsDirectory = "tests/specs/unit",
directory = "models",
directory = getAppPrefix( getCWD() ) & "models",
description = "I am a new service",
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.
Comment on lines 43 to 50
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",
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.
Comment on lines 23 to 26
required name,
boolean helper = false,
directory = "views",
directory = getAppPrefix( getCWD() ) & "views",
boolean open = false,
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.
Comment on lines 22 to 25
required name,
boolean helper = false,
directory = "layouts",
directory = getAppPrefix( getCWD() ) & "layouts",
boolean open = false,
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.
Comment on lines 29 to 33
description = "I am a new interceptor",
boolean tests = true,
testsDirectory = "tests/specs/interceptors",
directory = "interceptors",
directory = getAppPrefix( getCWD() ) & "interceptors",
boolean open = false,
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.
Comment on lines 61 to 64
boolean tests = true,
testsDirectory = "tests/specs/unit",
directory = "models",
directory = getAppPrefix( getCWD() ) & "models",
description = "I am a new Model Object",
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.
Comment on lines 23 to 27
required entity,
pluralName = "",
handlersDirectory = "handlers",
viewsDirectory = "views",
handlersDirectory = getAppPrefix( getCWD() ) & "handlers",
viewsDirectory = getAppPrefix( getCWD() ) & "views",
boolean tests = true,
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.
Comment on lines 92 to 97
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,
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting to specify app path

3 participants