From edacc7125ccb15a925b3df98eb69899376a442b9 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 7 Sep 2024 14:31:03 -0400 Subject: [PATCH 1/4] feat: Added support for the `TEMPLATES_VENDOR_DIR` environment variable, either defined in the environment itself, or in a `.env` file if [Dotenv](https://github.com/vlucas/phpdotenv)) is used --- src/Installer.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Installer.php b/src/Installer.php index 3eb46fa..06d42bd 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -15,7 +15,9 @@ use Composer\Package\PackageInterface; use Composer\Repository\InstalledRepositoryInterface; use Composer\Util\Filesystem; +use Dotenv\Dotenv; use React\Promise\PromiseInterface; +use RuntimeException; /** * Class Installer @@ -43,7 +45,11 @@ class Installer extends BaseLibraryInstaller public function __construct(IOInterface $io, Composer $composer, $type = self::TWIG_BUNDLE_PACKAGE_TYPE, Filesystem $filesystem = null, BinaryInstaller $binaryInstaller = null) { parent::__construct($io, $composer, $type, $filesystem, $binaryInstaller); - $this->vendorDir = rtrim(self::TEMPLATES_VENDOR_DIR, '/'); + // Load dotenv? + if (class_exists('Dotenv\Dotenv')) { + Dotenv::createUnsafeMutable(__DIR__)->safeLoad(); + } + $this->vendorDir = rtrim(getenv('TEMPLATES_VENDOR_DIR') ?: self::TEMPLATES_VENDOR_DIR, '/'); $this->type = self::TWIG_BUNDLE_PACKAGE_TYPE; } @@ -101,7 +107,7 @@ protected function writeGitIgnore(): void $dir = self::TEMPLATES_VENDOR_DIR; if (!file_exists($dir)) { if (!mkdir($dir, 0777, true) && !is_dir($dir)) { - throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); + throw new RuntimeException(sprintf('Directory "%s" was not created', $dir)); } } // Create the .gitignore file if it doesn't exist From 5a5f8de2028c7197a9138d0f91eee9ca01eeb3fe Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 7 Sep 2024 14:31:31 -0400 Subject: [PATCH 2/4] docs: Update docs for the new `TEMPLATES_VENDOR_DIR` environment variable --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 17c5549..25ea9c1 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,8 @@ Example including a template from a Twig Bundle: Since Twig Bundle Installer is looking for a directory in your project root named `templates/` that points to your Twig templates directory: * You should treat the `templates/vendor/` directory as **read only** just like you do the `vendor/` directory -* If you store your templates somewhere else, for now you must create a symlink or alias from `templates/` to where you store your templates -* If you exclude your `vendor/` directory from your Git repo, you probably would want to add `templates/vendor/` to your `.gitignore` as well +* If you store your templates somewhere else, you can create a symlink or alias from `templates/` to where you store your templates, or you can set the `TEMPLATES_VENDOR_DIR` environment variable (either in the environment itself, or in your `.env` file in your project root if you're using [Dotenv](https://github.com/vlucas/phpdotenv)) +* If you exclude your `vendor/` directory from your Git repo, you probably would want to add `templates/vendor/` to your `.gitignore` as well. Twig Bundle Installer will automatically put `.gitignore` file in the `templates/vendor/` directory for you Example `.gitignore` file: ``` @@ -189,7 +189,6 @@ This project is usable as-is, but it's also very much in the germination phase. Some ideas: -* The templates directory shouldn't be hard-coded * Bundles could include CSS and JavaScript that the installer builds a `manifest.json` for something else to consume * Framework specific tools could compliment Twig Bundle Installer by automatically publishing bundles on the frontend * Technically, the technique described here would work fine for [Antlers](https://docs.statamic.com/antlers) or [Blade](https://laravel.com/docs/5.8/blade) and other templating systems as well. From b4876d9150dd662ec2dad8da9243211b9b8ef034 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 7 Sep 2024 14:31:45 -0400 Subject: [PATCH 3/4] feat: Add project top level Makefile --- Makefile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..21b9533 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +MAJOR_VERSION?=5 +PLUGINDEV_PROJECT_DIR?=/Users/andrew/webdev/sites/plugindev/cms_v${MAJOR_VERSION}/ +VENDOR?=nystudio107 +PROJECT_PATH?=${VENDOR}/$(shell basename $(CURDIR)) + +.PHONY: dev docs release + +# Start up the buildchain dev server +dev: +# Start up the docs dev server +docs: +# Run code quality tools, tests, and build the buildchain & docs in preparation for a release +release: --code-quality --code-tests --buildchain-clean-build --docs-clean-build +# The internal targets used by the dev & release targets +--buildchain-clean-build: +--code-quality: + ${MAKE} -C ${PLUGINDEV_PROJECT_DIR} -- ecs check vendor/${PROJECT_PATH}/src --fix + ${MAKE} -C ${PLUGINDEV_PROJECT_DIR} -- phpstan analyze -c vendor/${PROJECT_PATH}/phpstan.neon +--code-tests: +--docs-clean-build: From 60ddb4b1f2f11c1374144c0a270f58b682b227f8 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 7 Sep 2024 14:31:53 -0400 Subject: [PATCH 4/4] chore: Version 1.1.2 --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afd7691..706c5eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +## 1.1.2 - 2024.09.07 +### Added +* Added support for the `TEMPLATES_VENDOR_DIR` environment variable, either defined in the environment itself, or in a `.env` file if [Dotenv](https://github.com/vlucas/phpdotenv)) is used + ## 1.1.1 - 2024.04.16 ### Added * Add `phpstan` and `ecs` code linting diff --git a/composer.json b/composer.json index fa88fea..21014fb 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "nystudio107/twig-bundle-installer", "description": "Install, update, and manage Twig template bundles via Composer", - "version": "1.1.1", + "version": "1.1.2", "keywords": [ "twig", "composer",