From a77c083ccb77815909128819cfabf901b242490b Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Mon, 29 Jan 2024 12:55:29 +1300 Subject: [PATCH] NEW Add script for setting phpstan config --- funcs_scripts.php | 38 ++++++++++++++++++++++++++++++ scripts/cms5/phpstan.php | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 scripts/cms5/phpstan.php diff --git a/funcs_scripts.php b/funcs_scripts.php index 6082824..a14784d 100644 --- a/funcs_scripts.php +++ b/funcs_scripts.php @@ -4,6 +4,22 @@ // These functions in scripts can be used in scripts +/** + * Check that a directory exists relative to the root of the module being processed + * + * Example usage: + * check_dir_exists('src') + */ +function check_dir_exists($dirname) { + global $MODULE_DIR; + $path = "$MODULE_DIR/$dirname"; + if (!is_dir($path)) { + info("Directory $path does not exist, though this should be OK"); + return false; + } + return true; +} + /** * Check that a file exists relative to the root of the module being processed * @@ -132,6 +148,28 @@ function is_module() && strpos($MODULE_DIR, '/webpack-config') === false; } +/** + * Determine if the module being processed is a theme + * + * Example usage: + * is_theme() + */ +function is_theme() +{ + if (!check_file_exists('composer.json')) { + return false; + } + + $contents = read_file('composer.json'); + $json = json_decode($contents); + if (is_null($json)) { + $lastError = json_last_error(); + error("Could not parse from composer.json - last error was $lastError"); + } + + return $json->type === 'silverstripe-theme'; +} + /** * Determine if the module being processed is a source of documentation * diff --git a/scripts/cms5/phpstan.php b/scripts/cms5/phpstan.php new file mode 100644 index 0000000..0357074 --- /dev/null +++ b/scripts/cms5/phpstan.php @@ -0,0 +1,50 @@ +