Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Mar 8, 2022
2 parents 2d840a2 + d9996d5 commit c10203b
Show file tree
Hide file tree
Showing 187 changed files with 38,198 additions and 5,939 deletions.
15 changes: 7 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# CRAFT ENVIRONMENT
.env*
license.key*

# COMPOSER
*/vendor/*
Expand All @@ -22,20 +23,18 @@
!*/storage/.gitkeep

# ASSETS
/cms/web/assets/*
/cms/web/cpresources/*
/cms/web/dist/*
/cms/web/favicon.*
/cms/web/sw.*
/cms_v3/web/assets/*
/cms_v3/web/cpresources/*
/cms_v3/web/dist/*
/cms_v4/web/assets/*
/cms_v4/web/cpresources/*
/cms_v4/web/dist/*

# BUILD FILES
node_modules
yarn-error.log
npm-debug.log

# TRANSCODER
/cms/web/transcoder/*

# MISC FILES
.cache
.DS_Store
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# nystudio107/plugindev Change Log

## 1.1.0 - 2022.03.07
### Added
* Added a dual Craft CMS 3 & Craft CMS 4 setup

## 1.0.39 - 2022.02.18
### Added
* Add new `make ssh` command to open up a shell inside the PHP container ([#4](https://github.com/nystudio107/plugindev/pull/4))
Expand Down
49 changes: 17 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,27 @@
CONTAINER?=$(shell basename $(CURDIR))-php-1
PROJECT_NAME?=$(shell basename $(CURDIR))
SERVICE_NAME?=php
CMS_ROOT_NAME?=cms_
CMS_VERSIONS:=v3 v4
SEPARATOR:=-

.PHONY: dev clean composer craft mysql nuke postgres ssh update update-clean up
.PHONY: dev clean nuke up

dev: up
clean:
for v in $(CMS_VERSIONS) ; do \
rm -f $(CMS_ROOT_NAME)$$v/composer.lock ; \
rm -rf $(CMS_ROOT_NAME)$$v/vendor/ ; \
done
nuke: clean
docker-compose down -v
docker-compose up --build
composer: up
docker exec -it ${CONTAINER} su-exec www-data composer \
$(filter-out $@,$(MAKECMDGOALS))
craft: up
docker exec -it ${CONTAINER} su-exec www-data php craft \
$(filter-out $@,$(MAKECMDGOALS))
mysql: up
cp cms/config/_configs/mysql/db.php cms/config/db.php
cp cms/config/_configs/mysql/general.php cms/config/general.php
nuke:
docker-compose down -v
rm -f cms/composer.lock
docker-compose up --build --force-recreate
postgres: up
cp cms/config/_configs/postgres/db.php cms/config/db.php
cp cms/config/_configs/postgres/general.php cms/config/general.php
ssh: up
docker exec -it ${CONTAINER} su-exec www-data /bin/sh
update:
docker-compose down
rm -f cms/composer.lock
docker-compose up
update-clean:
docker-compose down
rm -f cms/composer.lock
rm -rf cms/vendor/
docker-compose up
up: CONTAINER=$(PROJECT_NAME)$(SEPARATOR)$(SERVICE_NAME)_$(word 1,$(CMS_VERSIONS))$(SEPARATOR)1
up:
if [ ! "$$(docker ps -q -f name=${CONTAINER})" ]; then \
cp -n cms/example.env cms/.env; \
docker-compose up; \
if [ ! "$$(docker ps -q -f name=$(CONTAINER))" ]; then \
for v in $(CMS_VERSIONS) ; do \
cp -fn $(CMS_ROOT_NAME)$$v/example.env $(CMS_ROOT_NAME)$$v/.env ; \
done ; \
docker-compose up ; \
fi
%:
@:
Expand Down
118 changes: 77 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## About nystudio107/plugindev

This is a project scaffolding package for Craft 3 CMS plugin development.
This is a project scaffolding package for Craft CMS & Craft CMS 4 plugin development.

Read the [A Craft CMS Plugin Local Development Environment article](https://nystudio107.com/blog/a-craft-cms-plugin-local-development-environment) for full details on this project.

It gives you the following out of the box:

* Craft CMS `^3.6.7` is installed
* Dual installs of both Craft CMS `^3.7.26` and Craft CMS `^4.0.0-alpha.1` running simultaneously
* `craftcms/redactor` plugin is installed
* `craftcms/commerce` plugin is installed
* A PHP 8.x environment with Imagick and other needed extensions pre-installed
Expand All @@ -18,49 +18,101 @@ It gives you the following out of the box:
* Multiple sites for testing
* Prefab content with a "blog" channel for testing

## Using nystudio107/plugindev
## Creating nystudio107/plugindev

This project package works exactly the way Pixel & Tonic's [craftcms/craft](https://github.com/craftcms/craft) package works; you create a new project by first creating & installing the project:
This project package works exactly the way Pixel & Tonic's [craftcms/craft](https://github.com/craftcms/craft) package works; you create a new project via Composer:

composer create-project nystudio107/plugindev --no-install --remove-vcs
composer create-project nystudio107/plugindev --no-install

This will create a project named `plugindev` which is a turnkey Craft CMS install for developing plugins.

We use `--no-install` so that the composer packages for the root project are not installed.

It works this way so that you can take the basic scaffolding, and then modify it as you see fit.

## Setting Up Local Dev

You'll need Docker desktop for your platform installed to run the project in local development
You'll need [Docker desktop](https://www.docker.com/products/docker-desktop) for your platform installed to run the project in local development

Craft CMS 3 runs out of the `cms_v3/` directory available at `http://localhost:8003`, and Craft CMS 4 runs out of the `cms_v4` directory available at `http://localhost:8004`.

Each version of Craft CMS runs in separate Docker containers, and uses a separate database running out of the database containers (MySQL and Postgres).

Composer will have already created a `.env` file in the `cms_v3/` & `cms_v4` directories, based off of the respective `example.env` files.

To set up your local dev environment:

* Composer will have already created a `.env` file in the `cms/` directory, based off of the provided `example.env`

* Edit the `cms/composer.json` file and change the line `"url": "/Users/andrew/webdev/craft/*",` in `repostories` to point to your local plugin Git repositories
* Edit the `docker-composer.yaml` file and change the line `- /Users/andrew/webdev/craft:/Users/andrew/webdev/craft` to point to your local plugin Git repositories
* Start up the site with `make dev` (the first build will be somewhat lengthy)
* Navigate to `http://localhost:8000` to use the site
* Edit the `cms_v3/composer.json` file and change the line `"url": "/Users/andrew/webdev/craft_v3/*",` in `repostories` to point to your local plugin Git repositories for Craft CMS 3
* Edit the `cms_v4/composer.json` file and change the line `"url": "/Users/andrew/webdev/craft_v4/*",` in `repostories` to point to your local plugin Git repositories for Craft CMS 3
* Edit the `docker-composer.yaml` file and change the line `- /Users/andrew/webdev/craft_v3:/Users/andrew/webdev/craft_v3` to point to your local plugin Git repositories
* Edit the `docker-composer.yaml` file and change the line `- /Users/andrew/webdev/craft_v4:/Users/andrew/webdev/craft_v4` to point to your local plugin Git repositories

## Using nystudio107/plugindev

Start up the `plugindev` environment by typing `make dev` in a terminal window (the first build will be somewhat lengthy).

To stop the `plugindev` environment, type `Control-C` in the terminal window you used to start it, which terminates the Docker containers.

### Login

The default login is:
* Navigate to `http://localhost:8003` to use the Craft CMS 3 site
* Navigate to `http://localhost:8004` to use the Craft CMS 4 site

The default login for both sites is:

**User:** `admin` \
**Password:** `password`

### Updating
### Exposed ports & services

To update to the latest Composer packages (as constrained by the `cms/composer.json` semvers), do:
```
make update
```
The following ports are exposed on `localhost` while `plugindev` is running (these need to not be in use prior to starting up `plugindev`):

To start from scratch by removing `cms/vendor/`, then update to the latest Composer packages (as constrained by the `cms/composer.json` semvers), do:
```
make update-clean
```
* `8003` - The Craft CMS 3 website
* `8004` - The Craft CMS 4 website
* `5432` - The Postgres database server
* `3306` - The MySQL database server

The following databases are available in both the MySQL and Postgres database containers:

* `project_v3` - the database for Craft CMS 3. User: `project` Password: `project`
* `project_43` - the database for Craft CMS 4. User: `project` Password: `project`

Internally, there are also containers that run the Craft CMS queue automatically, a Redis container for caching.

## `make` Commands

This project uses Docker to shrink-wrap the devops it needs to run around the project.

To make using it easier, we're using a Makefile and the built-in `make` utility to create a CLI API both for the project as a whole, and for the individual Craft CMS 3 & Craft CMS 4 site.

You can read more about it in the [Using Make & Makefiles to Automate your Frontend Workflow](https://nystudio107.com/blog/using-make-makefiles-to-automate-your-frontend-workflow) article.

### `make` Project Commands

You can run the following from terminal in the root project directory:

- `make dev` - starts up the local dev server listening on `http://localhost:8003/` & `http://localhost:8004/`
- `make clean` - removes the `composer.lock` and the entire `vendor/` directory from both the `cms_v3` & `cms_v4` projects
- `make nuke` - restarts the project from scratch by running `make clean` (above), then shuts down the Docker containers, removes any mounted volumes (including the database), and then rebuilds the containers from scratch

### `make` CMS Commands

composer craft ecs mysql phpstan postgres rector ssh

You can run the following from terminal in the `cms_v3` or `cms_v4` CMS directories:

- `make ecs xxx` - runs [Easy Coding Standard](https://github.com/symplify/easy-coding-standard) using the [Craft CMS ECS config](https://github.com/craftcms/ecs), with the passed in path, e.g.: `make ecs vendor/nystudio107/craft-seomatic/src`. Additional settings are available in the `ecs.php` file
- `make composer xxx` - runs the `composer` command passed in, e.g. `make composer install` in the php container
- `make craft xxx` - runs the `craft` [console command](https://craftcms.com/docs/3.x/console-commands.html) passed in, e.g.: `make craft project-config/apply` in the php container
- `make mysql` - switches the project to use the MySQL database container; just reload the browser
- `make phpstan xxx` - runs [PHPStan](https://github.com/phpstan/phpstan) using the [Craft CMS PHPStan config](https://github.com/craftcms/phpstan), with the passed in path, e.g.: `make phpstan vendor/nystudio107/craft-seomatic/src`. Additional settings are available in the `phpstan.neon` file
- `make postgres` - switches the project to use the Postgres database container; just reload the browser
- `make rector xxx` - runs [Rector](https://github.com/rectorphp/rector) using the [Craft CMS Rector config](https://github.com/craftcms/rector), with the passed in path, e.g.: `make rector vendor/nystudio107/craft-seomatic/src`. Additional settings are available in the `rector.php` file
- `make ssh` - opens up a Unix shell inside the PHP container for the project

### Switching between MySQL & Postgres

The plugindev project supports both MySQL and Postgres out of the box. It spins up a container for each database, and seeds them with a starter db.
The `plugindev` environment supports both MySQL and Postgres out of the box. It spins up a container for each database, and seeds them with a starter db.

To use MySQL (the default) just type:
```bash
Expand Down Expand Up @@ -88,25 +140,9 @@ If however the `XDEBUG_SESSION` cookie is set (with any value), it routes the re

You can set this cookie with a [browser extension, your IDE](https://xdebug.org/docs/step_debug), or via a number of other methods. Here is the Xdebug Helper browser extension for your favorite browsers: [Chrome](https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc) - [Firefox](https://addons.mozilla.org/en-GB/firefox/addon/xdebug-helper-for-firefox/) - [Safari](https://apps.apple.com/app/safari-xdebug-toggle/id1437227804?mt=12)

You can read more about it in the Dual [An Annotated Docker Config for Frontend Web Development](https://nystudio107.com/blog/an-annotated-docker-config-for-frontend-web-development#xdebug-performance) article.

### Makefile Project Commands

This project uses Docker to shrink-wrap the devops it needs to run around the project.

To make using it easier, we're using a Makefile and the built-in `make` utility to create local aliases. You can run the following from terminal in the project directory:

- `make dev` - starts up the local dev server listening on `http://localhost:8000/`
- `make clean` - shuts down the Docker containers, removes any mounted volumes (including the database), and then rebuilds the containers from scratch
- `make mysql` - switches the project to use the MySQL database container; just reload the browser
- `make postgres` - switches the project to use the Postgres database container; just reload the browser
- `make update` - causes the project to update to the latest Composer dependencies
- `make update-clean` - completely removes `node_modules/` & `vendor/`, then causes the project to update to the latest Composer dependencies
- `make composer xxx` - runs the `composer` command passed in, e.g. `make composer install` in the php container
- `make craft xxx` - runs the `craft` [console command](https://craftcms.com/docs/3.x/console-commands.html) passed in, e.g. `make craft project-config/apply` in the php container
- `make ssh` - opens a shell inside the PHP container
You can read more about it in the [An Annotated Docker Config for Frontend Web Development](https://nystudio107.com/blog/an-annotated-docker-config-for-frontend-web-development#xdebug-performance) article.

### XDebug with VScode
## XDebug with VScode

To use Xdebug with VSCode install the [PHP Debug extension](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug ) and use the following configuration in your `.vscode/launch.json`:
```json
Expand Down

This file was deleted.

37 changes: 37 additions & 0 deletions cms_v3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
PROJECT_NAME?=$(shell basename $(dir $(CURDIR)))
PROJECT_DIR?=/var/www/project/
SERVICE_NAME?=php
CMS_ROOT_NAME?=cms_
CMS_VERSION:=v3
SEPARATOR:=-
CONTAINER:=$(PROJECT_NAME)$(SEPARATOR)$(SERVICE_NAME)_$(CMS_VERSION)$(SEPARATOR)1
CMS_DIR:=$(CMS_ROOT_NAME)$(CMS_VERSION)

.PHONY: composer craft ecs mysql phpstan postgres rector ssh

composer:
docker exec -it -w $(PROJECT_DIR)$(CMS_DIR) $(CONTAINER) su-exec www-data composer \
$(filter-out $@,$(MAKECMDGOALS))
craft:
docker exec -it -w $(PROJECT_DIR)$(CMS_DIR) $(CONTAINER) su-exec www-data php craft \
$(filter-out $@,$(MAKECMDGOALS))
ecs:
docker exec -it -w $(PROJECT_DIR)$(CMS_DIR) $(CONTAINER) su-exec www-data vendor/bin/ecs \
$(filter-out $@,$(MAKECMDGOALS))
mysql:
cp config/_configs/mysql/db.php config/db.php
cp config/_configs/mysql/general.php config/general.php
phpstan:
docker exec -it -w $(PROJECT_DIR)$(CMS_DIR) $(CONTAINER) su-exec www-data vendor/bin/phpstan --memory-limit=1G \
$(filter-out $@,$(MAKECMDGOALS))
postgres:
cp config/_configs/postgres/db.php config/db.php
cp config/_configs/postgres/general.php config/general.php
rector:
docker exec -it -w $(PROJECT_DIR)$(CMS_DIR) $(CONTAINER) su-exec www-data vendor/bin/rector \
$(filter-out $@,$(MAKECMDGOALS))
ssh:
docker exec -it -w $(PROJECT_DIR)$(CMS_DIR) $(CONTAINER) su-exec www-data /bin/sh
%:
@:
# ref: https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line
File renamed without changes.
20 changes: 12 additions & 8 deletions cms/composer.json → cms_v3/composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "nystudio107/plugindev",
"description": "This is a project scaffolding package for Craft 3 CMS plugin development.",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"craftcms/cms": "^3.7.26",
"craftcms/redactor": "^2.0.0",
"craftcms/commerce": "^3.0.0",
"craftcms/digital-products": "^2.0.0",
"vlucas/phpdotenv": "^5.4.0",
"yiisoft/yii2-redis": "^2.0.6",
"nystudio107/craft-connect": "^1.0.0",
Expand All @@ -30,13 +33,17 @@
"nystudio107/craft-twigprofiler": "^1.0.0",
"nystudio107/craft-typogrify": "^1.1.5",
"nystudio107/craft-units": "^1.0.0",
"nystudio107/craft-vanillaforums": "^1.0.0",
"nystudio107/craft-vanillaforums": "^3.0.0",
"nystudio107/craft-webperf": "^1.0.0",
"nystudio107/craft-youtubeliveembed": "^1.0.0",
"nystudio107/craft-vite": "^1.0.0"
"nystudio107/craft-vite": "^1.0.0",
"solspace/craft3-calendar": "^3.0.0"
},
"require-dev": {
"nystudio107/craft-autocomplete": "^1.0.0",
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main",
"craftcms/rector": "dev-main",
"nystudio107/craft-autocomplete": "^1.10.0",
"yiisoft/yii2-shell": "^2.0.3"
},
"autoload": {
Expand All @@ -50,15 +57,12 @@
"yiisoft/yii2-composer": true
},
"optimize-autoloader": true,
"sort-packages": true,
"platform": {
"php": "7.2.5"
}
"sort-packages": true
},
"repositories": [
{
"type": "path",
"url": "/Users/andrew/webdev/craft/*",
"url": "/Users/andrew/webdev/craft_v3/*",
"options": {
"symlink": true
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@
'omitScriptNameInUrls' => true,
'useEmailAsUsername' => false,
'usePathInfo' => true,
'useProjectConfigFile' => true,
];
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@
'omitScriptNameInUrls' => true,
'useEmailAsUsername' => false,
'usePathInfo' => true,
'useProjectConfigFile' => true,
];
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fieldLayouts:
warning: null
width: 100
-
fieldUid: 0242b54b-89fc-4bc4-b2ba-308cca715ba7 # Longform
fieldUid: 0242b54b-89fc-4bc4-b2ba-308cca715ba7
instructions: null
label: null
required: false
Expand Down
File renamed without changes.
Loading

0 comments on commit c10203b

Please sign in to comment.