From 7df5563fd8d498828ca25a856a46d3386ee89a01 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 12 Mar 2026 12:17:49 +0000 Subject: [PATCH 1/2] feature: implement `gt add` for page, cron, api closes #54 --- README.md | 49 ++++++++ bin/gt | 2 + src/Command/AddCommand.php | 195 ++++++++++++++++++++++++++++++++ src/Template/api/template.json | 29 +++++ src/Template/api/template.php | 3 + src/Template/cron/template.php | 3 + src/Template/page/template.html | 2 + src/Template/page/template.php | 3 + 8 files changed, 286 insertions(+) create mode 100644 src/Command/AddCommand.php create mode 100644 src/Template/api/template.json create mode 100644 src/Template/api/template.php create mode 100644 src/Template/cron/template.php create mode 100644 src/Template/page/template.html create mode 100644 src/Template/page/template.php diff --git a/README.md b/README.md index e4d5f70..dcea096 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ This repository holds the CLI functionality for [PHP.Gt/WebEngine](https://www.p The following commands are exposed: ++ `gt add` - add a page, API endpoint or cron script from a template + `gt create` - create a new WebEngine application + `gt serve` - run the inbuilt development server + `gt build` - compile client-side assets @@ -12,6 +13,54 @@ The following commands are exposed: + `gt run` - run all background scripts at once - a combination of `serve`, `build --watch` and `cron --watch --now` + `gt deploy` - instantly deploy your application to the internet +## `gt add` + +Use `gt add type name [template]` to create new files in the current project. + +Supported types: + ++ `page` ++ `api` ++ `cron` + +Examples: + ++ `gt add page about` ++ `gt add api users` ++ `gt add cron cleanup` ++ `gt add page about multi-column` + +`type` and `name` are required. `template` is optional. + +### Built-in templates + +If no template name is provided, `gt add` copies the built-in templates from this package: + ++ `src/Template/page/template.html` -> `page/.html` ++ `src/Template/page/template.php` -> `page/.php` ++ `src/Template/api/template.php` -> `api/.php` ++ `src/Template/api/template.json` -> `api/.json` ++ `src/Template/cron/template.php` -> `cron/.php` + +If a template file contains `{{name}}`, it is replaced with the provided `name`. + +### Project templates + +If a template name is provided, files are loaded from the current working directory instead: + ++ `/_template/