From cd442079f5da0ad64371d8a92550f99f8c105550 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 26 Feb 2023 23:48:53 +0100 Subject: [PATCH] Add CLI command to initialize a new project --- docs/getting-start.md | 17 + example/locales/.gitignore | 4 + skel/.gitignore | 15 + skel/bin/manage | 7 + skel/config.yml | 303 ++++++++++++++++++ skel/data/logs/.gitignore | 2 + skel/data/tmp/templates_c/.gitignore | 1 + skel/includes/core.php | 53 +++ skel/includes/views/index.php | 5 + skel/locales/.gitignore | 4 + skel/public_html/.htaccess | 8 + skel/public_html/index.php | 9 + src/App.php | 2 + src/Cli.php | 64 ++++ .../css/style.css => static/css/eesyphp.css | 2 +- templates/empty.tpl | 2 +- 16 files changed, 496 insertions(+), 2 deletions(-) create mode 100644 docs/getting-start.md create mode 100644 example/locales/.gitignore create mode 100644 skel/.gitignore create mode 100644 skel/bin/manage create mode 100644 skel/config.yml create mode 100644 skel/data/logs/.gitignore create mode 100644 skel/data/tmp/templates_c/.gitignore create mode 100644 skel/includes/core.php create mode 100644 skel/includes/views/index.php create mode 100644 skel/locales/.gitignore create mode 100644 skel/public_html/.htaccess create mode 100644 skel/public_html/index.php rename example/static/css/style.css => static/css/eesyphp.css (99%) diff --git a/docs/getting-start.md b/docs/getting-start.md new file mode 100644 index 0000000..0a2bf07 --- /dev/null +++ b/docs/getting-start.md @@ -0,0 +1,17 @@ +# Getting start + +To start using the EesyPHP framework on your project, you have to firstly install it using [composer](https://getcomposer.org/) : + +```bash +mkdir my_project +cd my_project +composer init --stability dev +# When asking for dependency, search brenard/eesyphp +composer update +``` + +With the provided `eesyphp` CLI tool, you can quickly init a new project: + +```bash +vendor/bin/eesyphp new_project +``` diff --git a/example/locales/.gitignore b/example/locales/.gitignore new file mode 100644 index 0000000..cfeb792 --- /dev/null +++ b/example/locales/.gitignore @@ -0,0 +1,4 @@ +headers.pot +js-*-messages.pot +php-messages.pot +templates-*-messages.pot diff --git a/skel/.gitignore b/skel/.gitignore new file mode 100644 index 0000000..a09d069 --- /dev/null +++ b/skel/.gitignore @@ -0,0 +1,15 @@ +# Ignore vim temporary/backup files +*~ +.*.swp +# Exclude composer installed libs +/vendor +/composer.lock +# Common UNIX user home directory files +/.bash* +/.vim* +/.composer +/.gitconfig +/.vim* +/.less* +/.ssh +/.phplint-cache diff --git a/skel/bin/manage b/skel/bin/manage new file mode 100644 index 0000000..211a8ed --- /dev/null +++ b/skel/bin/manage @@ -0,0 +1,7 @@ +#!/usr/bin/php + array( + "$root_dir_path/config.local.yml", + ), + 'templates' => array( + 'static_directories' => array( + "$root_dir_path/static" + ), + ), + ), + $root_dir_path +); + +$sentry_span = new SentrySpan('core.init', 'Core initialization'); + +// Put here your own initialization stuff + +require 'views/index.php'; + +$sentry_span->finish(); + +# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab diff --git a/skel/includes/views/index.php b/skel/includes/views/index.php new file mode 100644 index 0000000..2eac086 --- /dev/null +++ b/skel/includes/views/index.php @@ -0,0 +1,5 @@ +finish(); } diff --git a/src/Cli.php b/src/Cli.php index c525036..fa7f955 100644 --- a/src/Cli.php +++ b/src/Cli.php @@ -6,6 +6,24 @@ use Exception; class Cli { + /** + * Initialize + * @return void + */ + public static function init() { + if (php_sapi_name() != 'cli') + return; + self :: add_command( + 'new_project', + array('\\EesyPHP\\Cli', 'cli_new_project'), + I18n :: ___("Create a new project using EesyPHP framework"), + null, + I18n :: ___( + "This command could be used to easily build the structure of a new project using the ". + "EesyPHP framework.") + ); + } + /** * Registered commands * @var array @@ -180,4 +198,50 @@ class Cli { } } + /** + * Command to create new project based on EesyPHP framework + * + * @param array $command_args The command arguments + * @return void + */ + public static function cli_new_project($command_args) { + echo "This CLI tool permit to initialize a new project using the EesyPHP framework.\n"; + readline('[Press enter to continue]'); + echo "\n"; + + $root_path = null; + while (!$root_path) { + $root_path = getcwd(); + $input = readline("Please enter the root directory of your new project [$root_path]: "); + if (empty($input)) + break; + if (!is_dir($input)) + echo "Invalid root directory specified: not found or is not a directory\n"; + else if (!is_writeable($input)) + echo "Invalid root directory specified: not writeable\n"; + else + $root_path = $input; + } + $root_path = rtrim($root_path, "/"); + $skel = __DIR__ . "/../skel"; + + foreach ( + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($skel, \RecursiveDirectoryIterator::SKIP_DOTS), + \RecursiveIteratorIterator::SELF_FIRST + ) as $item + ) { + $path = "$root_path/".$iterator->getSubPathname(); + if ($item->isDir()) { + if (!mkdir($path)) + die("Fail to create $path directory\n"); + } + else { + if (!copy($item, $path)) + die("Fail to copy file to $path\n"); + } + } + echo "done. Start coding!\n"; + } + } diff --git a/example/static/css/style.css b/static/css/eesyphp.css similarity index 99% rename from example/static/css/style.css rename to static/css/eesyphp.css index 5fbf2aa..3c5c361 100644 --- a/example/static/css/style.css +++ b/static/css/eesyphp.css @@ -54,7 +54,7 @@ img { max-width: 100%; } th a, th a:hover { color: #000; text-decoration: none; - } +} /* * Forms diff --git a/templates/empty.tpl b/templates/empty.tpl index 30a28e5..f20af27 100644 --- a/templates/empty.tpl +++ b/templates/empty.tpl @@ -20,7 +20,7 @@ - + {foreach $css as $path} {/foreach}