ucomm / wp-plugin-project-boilerplate
用于搭建新WordPress插件的样板。
Requires (Dev)
- brain/monkey: ^2
- composer/installers: ^2
- johnpbloch/wordpress: @stable
- pestphp/pest: ^2
- pestphp/pest-plugin-faker: ^2
- pestphp/pest-plugin-watch: ^2
- wpackagist-plugin/query-monitor: ^3
- wpackagist-plugin/wordpress-importer: dev-trunk
- wpackagist-theme/twentytwentyfour: ^1
README
本仓库是一个用于快速创建由composer和docker管理的本地开发环境的样板。默认情况下,它将创建用于安装wordpress/mysql的镜像。Webpack用于捆绑和管理资产。
git flow
我们使用git flow。Git flow鼓励使用几种类型的分支的git分支策略
- master(用于生产)
- develop(预生产)
- feature/*(新功能)
- hotfix/*(错误修复)
- release/*(标记的发布版本合并到master)
典型开发工作流程开始
- 使用composer创建新项目
git clone git@bitbucket.org:ucomm/wp-plugin-project-boilerplate.git <new-plugin-name>- 在composer.json文件中更改项目的
name和description。名称尤其重要,因为它将用作通过composer使用此项目的名称。
git flow init -d- 在ucomm团队账户下创建一个新的bitbucket仓库
git flow feature start {feature_name}这将启动一个新的分支- 在...上工作...
git flow feature finish {feature_name}这将分支合并到develop- 测试
develop分支并与他人分享以获得批准
以下为创建jenkins和bitbucket管道的钩子以实现自动部署/包管理的说明
创建发布版本
标签必须遵循semver系统。按照以下步骤完成发布
- 在
develop分支上- 使用
git tag检查最新的版本号 - 在
./{plugin-name}.php中增加版本号 - 在
./changelog.md中添加更改日志说明
- 使用
- 提交这些更改(通常使用类似
git -m 'version bump [skip ci]'的命令) - 按照以下步骤创建新的标记发布版本。
$ git flow release start {new_tag} $ git flow release finish {new_tag} $ # in the first screen add new info or just save the commit message as is $ # in the second screen type in the same tag you just used and save. $ git push --tags && git push origin master $ git checkout develop
用法
入门
本项目的目的是快速开始开发。在开发您的个人项目时,请更新此readme以包含项目特定细节。如果您愿意,可以使用parcel、vite或其他构建系统代替webpack。这是完全可以接受的,您只需添加文档即可。此外,请更新更改日志以包含关于新版本的信息。
注意 - 如果您预计需要使用需要访问vendor目录的插件,请按照以下方式映射它。在docker-compose.yml中,找到web镜像,并在volumes下写入- ./vendor:/var/www/html/content/plugins/{plugin_name}/vendor。这将同时为当前主题和插件提供vendor文件夹。
要运行项目。
$ composer install # <- first time only
$ nvm use
$ npm install
$ docker-compose up # <- in one terminal
$ npm run dev # <- in another terminal
UComm composer依赖项
要添加我们的任何项目(插件、主题等...),它们需要作为依赖项添加。为此,您首先需要将它们添加到composer.json的"repositories"数组中。为此,添加vcs类型键和项目的git URL。例如
{
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
},
{
"type": "vcs",
"url": "git@bitbucket.org:ucomm/uconn-health-clinical.git"
}
// other dependencies
]
}
然后可以使用composer require ucomm/project-name进行要求。
本地资产开发
此模板包含一个最小的webpack配置文件,用于打包JS和CSS资源。你可能需要根据需要调整配置。没关系,如果有任何独特之处,就(像往常一样)对代码进行注释。
查看项目。
此项目将在localhost可用。
访问容器
要访问特定的Docker容器,找到容器名称,然后进入交互式终端。
$ docker ps # to get the container name
$ docker exec -it container_name bash
调试Wordpress
Wordpress调试日志可以在web容器中的/etc/httpd/logs/error_log找到。
Bitbucket
创建发布版本
假设你正在使用git flow,使用命令git flow release start {版本号}标记发布。标签必须遵循semver系统。按照以下步骤完成发布
$ git tag # check the current tags/versions on the project
$ git flow release start {new_tag}
$ git flow release finish {new_tag}
$ # in the first screen add new info or just save the commit message as is
$ # in the second screen type in the same tag you just used and save.
$ git push --tags && git push origin master
$ git checkout develop
管道
此存储库附带了bitbucket管道,以防你需要为标签/分支创建zip文件下载。你还可以在管道中创建构建的CSS/JS资源。按照bitbucket-pipelines.yml文件查看。*你可以通过将它们添加到composer.json中来排除zip存档中的文件/文件夹。语法与gitignore相同。你也可以显式包含文件/目录(例如,! .gitignore,! vendor/)。**要在bitbucket上启用管道,只需访问项目存储库,在repo -> settings -> Pipelines/settings中启用管道。
访问密钥
许多项目需要与Jenkins(如下所示)或我们的Satis/composer包存储库集成。这些需要ssh密钥。要将密钥添加到项目中...
- 找到另一个有密钥的项目(castor是一个很好的例子)
- 在那个项目中,转到
Settings -> General -> Access Keys - 复制所需的密钥
- 在你正在工作的项目中,添加新的密钥(通常称为Jenkins和Composer以保持清晰)
Jenkins
构建
如果你需要在Jenkins服务器上构建JS/CSS资源,可以通过在shell脚本中添加以下内容来实现。
#!/bin/bash
# load nvm and choose a version
source ~/.nvm/nvm.sh
nvm use
# install dependencies
npm ci # NB ci is used instead of install on CI/CD platforms
# build your assets. it will set the NODE_ENV process to production.
npm run build
使用wp-project-boilerplate插件
将UComm/WordPress依赖项保留在require-dev中,只将功能依赖项保留在"require"中,这会是一个好主意。这样,你的包将只导出插件/主题运行所需的文件,而不是包含完整的WP安装。请参阅使用这两个的Castor插件示例。