Browse Source

Initial commit

Initial commit of code forked from
https://github.com/UFHealth/generator-wp
tags/1.0
Chris Wiegman 1 year ago
commit
97220f86f7
No known key found for this signature in database GPG Key ID: 449E180845071036
39 changed files with 6120 additions and 0 deletions
  1. +11
    -0
      .editorconfig
  2. +1
    -0
      .eslintignore
  3. +158
    -0
      .gitignore
  4. +158
    -0
      README.md
  5. +14
    -0
      generators/app/index.js
  6. +77
    -0
      generators/core/index.js
  7. +10
    -0
      generators/core/templates/_.htaccess
  8. +15
    -0
      generators/core/templates/_.htaccess-multisite
  9. +14
    -0
      generators/core/templates/_develop
  10. +55
    -0
      generators/core/templates/_docker-compose.yml
  11. +14
    -0
      generators/core/templates/_setup
  12. +4
    -0
      generators/core/templates/_shell
  13. +4
    -0
      generators/core/templates/_wp
  14. +354
    -0
      generators/plugin/index.js
  15. +213
    -0
      generators/plugin/templates/_.gitignore
  16. +0
    -0
      generators/plugin/templates/_.gitkeep
  17. +59
    -0
      generators/plugin/templates/_.gitlab-ci.yml
  18. +27
    -0
      generators/plugin/templates/_.jshintrc
  19. +212
    -0
      generators/plugin/templates/_Gruntfile.js
  20. +97
    -0
      generators/plugin/templates/_README.md
  21. +34
    -0
      generators/plugin/templates/_bootstrap.php
  22. +24
    -0
      generators/plugin/templates/_composer.json
  23. +14
    -0
      generators/plugin/templates/_develop
  24. +57
    -0
      generators/plugin/templates/_docker-compose.yml
  25. +30
    -0
      generators/plugin/templates/_index.php
  26. +152
    -0
      generators/plugin/templates/_install-wp-tests.sh
  27. +10
    -0
      generators/plugin/templates/_package.json
  28. +21
    -0
      generators/plugin/templates/_phpcs.xml
  29. +20
    -0
      generators/plugin/templates/_phpunit.xml
  30. +7
    -0
      generators/plugin/templates/_plugin.js
  31. +7
    -0
      generators/plugin/templates/_plugin.scss
  32. +22
    -0
      generators/plugin/templates/_setup
  33. +10
    -0
      generators/plugin/templates/_shell
  34. +74
    -0
      generators/plugin/templates/_uninstall.php
  35. +10
    -0
      generators/plugin/templates/_wp
  36. +10
    -0
      generators/plugin/templates/_xloff
  37. +10
    -0
      generators/plugin/templates/_xlon
  38. +4087
    -0
      package-lock.json
  39. +24
    -0
      package.json

+ 11
- 0
.editorconfig View File

@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

+ 1
- 0
.eslintignore View File

@@ -0,0 +1 @@
app/templates

+ 158
- 0
.gitignore View File

@@ -0,0 +1,158 @@
# Created by .ignore support plugin (hsz.mobi)
### Windows template
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Yeoman template
bower_components/

build/
dist/
### macOS template
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.idea

+ 158
- 0
README.md View File

@@ -0,0 +1,158 @@
UF Health WordPress Project Generator
=================

Generator-wp is a [Yeoman](http://yeoman.io) generator for generating a base WordPress plugin (with themes to come) or a test environment for WordPress itself for use on UF Health WordPress properties based, in part, on [generator-wp-make by 10up](https://github.com/10up/generator-wp-make).

## Installation

If you need it, install Yeoman through npm:

```
$ npm install -g yo
```

To install generator-wp clone this repository, enter the directory, and link it to npm:

```
$ git clone git@gitlab.ahc.ufl.edu:WebServices/generator-wp.git && cd generator-wp
$ npm install
$ npm link
```

Finally, in the desired project directory (where your plugin or theme will go), initiate the generator:

```
$ yo wp
```

## Usage

generator-wp currently ships with te default project type, it is invoked with a subgenerator.

For each project type you get:

- Composer to manage server-side dependencies
- NPM to manage development dependencies (like Grunt)
- Grunt to streamline JS and CSS assets
- phpunit for PHP unit testing
- A fully-fleshed out, name-spaced setup for WordPress plugin development
- A Docker configuration, compatible with [Ouroboros](https://github.com/UFHealth/ouroboros), to get you actually working on code quickly.

### Plugin

This subgenerator scaffolds out a standard WordPress plugin.

The project even includes some basic unit test examples to help get you started!

```
$ cd [my-plugin-dir]
$ yo wp:plugin
```

For information on developing and using a generated plugin see the README.md file within after generating.

### Core

This subgenerator sets up a quick WordPress environment for testing or other use.

```
$ cd [the directory where you want to install WordPress]
$ yo wp:core
```

After installation is complete bring up the local environment in Docker with the Develop script and run `./Docker/bin/setup`. WordPress will then be accessible at http://wordpress.test

**More project types coming soon**

## Changelog

##### 2.1.2
* Setup the appropriate domain for debugging with wp-cli

##### 2.1.1
* Use appropriate user for XDebug scripts

##### 2.1
* Add scripts to enable and disable full-time listening for XDebug
* Updated export to work in Linux as well as Mac

##### 2.0.2
* Fix .htaccess for multisite with a new apache image

##### 2.0.1
* Make sure WordPress' rewrite rules are in place

##### 2.0
* Added the wp:core command to install a quick test environment.

##### 1.4
* Allow plugin setup without CSS or JS support
* Add Ouroboros-compatible Docker configuration to setup
* Allow UF Health prefix to be optional on setup
* Better handle plugin name, slug and other variables throughout the templates

##### 1.3.4
* Add code coverage information

##### 1.3.3
* Cleanup of existing templates
* Auto-initialize GIT repository
* Enable wp-enforcer

#### 1.3.2
* Fix wp-enforcer
* Drop WordPress VIP standards
* Minor name fixes

#### 1.3.1
* Don't use grunt/phpunt

#### 1.3
* Remove WP_Mock and use standard WordPress coding standards
* Ensure NPM packages are always up to date
* install composer an npm modules on use
* run grunt on initial setup

#### 1.2.7
* Update default packages in package.json

#### 1.2.6
* Defined the path to the includes folder in the main plugin file.

#### 1.2.5
* Updated PHPUnit to 6.5.* to address updates to wp_mock.

#### 1.2.4
* Fixed languages information in plugin index file

#### 1.2.3
* Update default URLs and author to be more inline with UF Health Webservices

#### 1.2.2
* Updated generated package.json for more current packages
* Update yeoman and related JS dependencies

#### 1.2.1
* Updated prompt descriptions for better clarity.

#### 1.2
* Add Grunt clean to plugin grunt processes
* Add dev and prod versions of compiled JS with appropriate mappings

#### 1.1.1
* Cleanup package versions in package.json
* Ignore vendor folder in .pot generation

#### 1.1
* Added Full GIT repository address to generated plugin.
* Added usage and build instructions to the readme.md file of generated plugins.

#### 1.0.2
* Add unit to plugin display name for easier sorting in WordPress dashboard

#### 1.0.1
* Replace Travis template with GitLab CI template
* Fix: Make sure source assets are not caught up in .gitignore.

#### 1.0
* Initial release

+ 14
- 0
generators/app/index.js View File

@@ -0,0 +1,14 @@
let Base = require('extendable-yeoman').Base;
let chalk = require('chalk');

module.exports = Base.extend(
{
notify: function () {
// replace it with a short and sweet description of your generator
this.log(chalk.magenta('Invoke a subgenerator to get started!'));
this.log('Available Modules:');
this.log(chalk.green('\tyo wp:plugin'));
this.log(chalk.green('\tyo wp:core'));
}
}
);

+ 77
- 0
generators/core/index.js View File

@@ -0,0 +1,77 @@
'use strict'
const Generator = require('yeoman-generator')
const noCase = require('no-case')

module.exports = class extends Generator {

prompting () {

const done = this.async()

const questions = [
{
type: 'confirm',
name: 'multisite',
message: 'Do you need WordPress Multisite?',
}
]

this.prompt(questions, function (response) {}).then((answers) => {

this.multisite = answers.multisite

done()

})

}

writing () {

if (true === this.multisite) {

this.fs.copy(
this.templatePath('_.htaccess-multisite'),
this.destinationPath('Docker/wordpress/.htaccess')
)

} else {

this.fs.copy(
this.templatePath('_.htaccess'),
this.destinationPath('Docker/wordpress/.htaccess')
)

}

this.fs.copy(
this.templatePath('_wp'),
this.destinationPath('Docker/bin/wp')
)

this.fs.copy(
this.templatePath('_develop'),
this.destinationPath('develop')
)

this.fs.copy(
this.templatePath('_shell'),
this.destinationPath('Docker/bin/shell')
)

this.fs.copyTpl(
this.templatePath('_docker-compose.yml'),
this.destinationPath('docker-compose.yml'), {
multisite: this.multisite
}
)

this.fs.copyTpl(
this.templatePath('_setup'),
this.destinationPath('Docker/bin/setup'), {
multisite: this.multisite
}
)

}
}

+ 10
- 0
generators/core/templates/_.htaccess View File

@@ -0,0 +1,10 @@
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

+ 15
- 0
generators/core/templates/_.htaccess-multisite View File

@@ -0,0 +1,15 @@
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress

+ 14
- 0
generators/core/templates/_develop View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Set environment variables for dev
if [ "Darwin" == $(uname -s) ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0)
else
export XDEBUG_HOST=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi

if [ $# -gt 0 ]; then
docker-compose -p ${PWD##*/} "$@" # Specify project name based on current directory
else
docker-compose ps
fi

+ 55
- 0
generators/core/templates/_docker-compose.yml View File

@@ -0,0 +1,55 @@
version: '3'

networks:
default:
driver: bridge
ouroboros_default:
external: true

services:
mariadb:
image: mariadb
volumes:
- "./Docker/database:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: username
MYSQL_PASSWORD: password
networks:
- default
labels:
- 'traefik.enable=false'
phpfpm:
image: ufhweb/php:7.2-wordpress
depends_on:
- mariadb
volumes:
- "./Docker/wordpress:/var/www/html"
- "./Docker/debug:/data/debug"
- "./Docker/logs/php:/var/log/php-fpm"
restart: always
networks:
- default
- ouroboros_default
labels:
- 'traefik.enable=false'
environment:
XDEBUG_HOST: ${XDEBUG_HOST}
httpd:
depends_on:
- phpfpm
image: ufhweb/apache:2.4<% if (true === multisite) { %>-wp-multi-subdir<% } %>
volumes:
- "./Docker/wordpress:/var/www/html"
- "./Docker/logs/httpd:/var/log/apache2"
restart: always
networks:
- default
- ouroboros_default
labels:
- 'traefik.frontend.rule=Host:wordpress.test'
- 'traefik.domain=wordpress.test'
- 'traefik.enable=true'
- 'traefik.docker.network=ouroboros_default'

+ 14
- 0
generators/core/templates/_setup View File

@@ -0,0 +1,14 @@
#!/bin/bash

if [ -f "./wordpress/wp-config.php" ];
then
echo "WordPress config file found."
else
echo "WordPress config file not found. Installing..."
export XDEBUG_HOST=$(ipconfig getifaddr en0) # Specific to Macintosh
docker-compose exec --user www-data phpfpm wp core download
docker-compose exec --user www-data phpfpm wp core config --dbhost=mariadb --dbname=wordpress --dbuser=root --dbpass=password
docker-compose exec --user www-data phpfpm wp core <% if (true === multisite) { %>multisite-<% } %>install --url=wordpress.test --title="WordPress Development" --admin_user=admin --admin_password=password --admin_email=info@example.com
docker-compose exec --user www-data phpfpm wp plugin uninstall hello akismet
docker-compose exec --user www-data phpfpm wp plugin install any-ipsum debug-bar wp-inspect heartbeat-control query-monitor whats-running debug-bar-remote-requests wordpress-php-info wordpress-beta-tester
fi

+ 4
- 0
generators/core/templates/_shell View File

@@ -0,0 +1,4 @@
#!/bin/bash

export XDEBUG_HOST=$(ipconfig getifaddr en0) # Specific to Macintosh
docker-compose exec --user root phpfpm bash

+ 4
- 0
generators/core/templates/_wp View File

@@ -0,0 +1,4 @@
#!/bin/bash

export XDEBUG_HOST=$(ipconfig getifaddr en0) # Specific to Macintosh
docker-compose exec --user www-data phpfpm wp "$@"

+ 354
- 0
generators/plugin/index.js View File

@@ -0,0 +1,354 @@
'use strict'
const Generator = require('yeoman-generator')
const noCase = require('no-case')

module.exports = class extends Generator {

installingDependencies () {

this.npmInstall(['grunt'], {'save-dev': true})

if (true === this.needsJS) {
this.npmInstall(['grunt-contrib-jshint'], {'save-dev': true})
this.npmInstall(['grunt-contrib-uglify'], {'save-dev': true})
}

if (true === this.needsCSS) {
this.npmInstall(['grunt-autoprefixer'], {'save-dev': true})
this.npmInstall(['grunt-contrib-cssmin'], {'save-dev': true})
}

if (true === this.needsJS || true === this.needsCSS) {
this.npmInstall(['grunt-contrib-clean'], {'save-dev': true})
this.npmInstall(['grunt-contrib-watch'], {'save-dev': true})
this.npmInstall(['grunt-sass'], {'save-dev': true})
this.npmInstall(['node-sass'], {'save-dev': true})
}

this.npmInstall(['grunt-wp-i18n'], {'save-dev': true})
this.npmInstall(['load-grunt-tasks'], {'save-dev': true})
this.npmInstall(['time-grunt'], {'save-dev': true})

}

prompting () {

const done = this.async()

const questions = [
{
type: 'confirm',
name: 'forUFHealth',
message: 'Is this plugin for use on the UF Health multisite or Bridge network?',
},
{
when: function (response) {
return response.forUFHealth
},
type: 'input',
name: 'unitName',
message: 'Your unit name (use abbreviation, ie. ESE, if anything but UF Health). This will be prepended to the plugin name.',
default: 'UF Health'
},
{
type: 'input',
name: 'pluginName',
message: 'The Plugin Name.',
//Defaults to the project's folder name if the input is skipped
default: this.appname
},
{
type: 'input',
name: 'description',
message: 'Plugin Description',
default: 'My awesome WordPress plugin'
},
{
type: 'input',
name: 'repoLocation',
message: 'GIT Repository'
},
{
type: 'input',
name: 'projectHome',
message: 'Project homepage',
default: 'http://webservices.ufhealth.org/'
},
{
type: 'input',
name: 'authorName',
message: 'Author name',
default: 'UF Health',
store: true
},
{
type: 'input',
name: 'authorEmail',
message: 'Author email',
default: 'webservices@ahc.ufl.edu',
store: true
},
{
type: 'input',
name: 'authorUrl',
message: 'Author URL',
default: 'http://webservices.ufhealth.org/',
store: true
},
{
type: 'confirm',
name: 'needsDocker',
message: 'Does this plugin need a Docker environment for development?',
},
{
type: 'confirm',
name: 'needsJS',
message: 'Does this plugin need processing for JavaScript?',
},
{
type: 'confirm',
name: 'needsCSS',
message: 'Does this plugin need processing for CSS/SCSS?',
}
]

this.prompt(questions, function (response) {}).then((answers) => {

this.forUFHealth = answers.forUFHealth

// Set a unit name if we don't otherwise have it available.
if (false === this.forUFHealth) {
answers.unitName = ''
}

this.unitName = answers.unitName
this.pluginName = answers.pluginName
this.description = answers.description
this.projectHome = answers.projectHome
this.authorName = answers.authorName
this.authorEmail = answers.authorEmail
this.authorUrl = answers.authorUrl
this.repoLocation = answers.repoLocation
this.needsDocker = answers.needsDocker
this.needsJS = answers.needsJS
this.needsCSS = answers.needsCSS

let unitAbbr = answers.unitName.replace(/ /g, '')

this.pluginSlug = noCase(unitAbbr + '-' + this.pluginName, null, '_')
this.textDomain = noCase(unitAbbr + '-' + this.pluginName, null, '-')
this.pluginConst = noCase(unitAbbr + '_' + this.pluginName, null, '_').toUpperCase()
this.packageName = '\\' + this.pluginName.trim().replace(' ', '_')

if ('' === unitAbbr) {
this.packageName = '\\' + unitAbbr + this.packageName
}

done()

})

}

writing () {

this.fs.copy(
this.templatePath('_.gitignore'),
this.destinationPath('.gitignore')
)

if (true === this.needsJS) {

this.fs.copy(
this.templatePath('_.jshintrc'),
this.destinationPath('.jshintrc')
)
}

this.fs.copy(
this.templatePath('_.gitlab-ci.yml'),
this.destinationPath('.gitlab-ci.yml')
)

this.fs.copy(
this.templatePath('_phpunit.xml'),
this.destinationPath('phpunit.xml')
)

this.fs.copy(
this.templatePath('_phpcs.xml'),
this.destinationPath('phpcs.xml')
)

this.fs.copy(
this.templatePath('_.gitkeep'),
this.destinationPath('includes/.gitkeep')
)

this.fs.copy(
this.templatePath('_install-wp-tests.sh'),
this.destinationPath('tests/bin/install-wp-tests.sh')
)

if (true === this.needsDocker) {

this.fs.copy(
this.templatePath('_wp'),
this.destinationPath('Docker/bin/wp'), {
textDomain: this.textDomain
}
)

this.fs.copy(
this.templatePath('_develop'),
this.destinationPath('develop')
)

this.fs.copy(
this.templatePath('_shell'),
this.destinationPath('Docker/bin/shell')
)

this.fs.copy(
this.templatePath('_xlon'),
this.destinationPath('Docker/bin/xlon')
)

this.fs.copy(
this.templatePath('_xloff'),
this.destinationPath('Docker/bin/xloff')
)

this.fs.copyTpl(
this.templatePath('_setup'),
this.destinationPath('Docker/bin/setup'), {
textDomain: this.textDomain
}
)

this.fs.copyTpl(
this.templatePath('_docker-compose.yml'),
this.destinationPath('docker-compose.yml'), {
textDomain: this.textDomain
}
)
}

this.fs.copyTpl(
this.templatePath('_package.json'),
this.destinationPath('package.json'), {
textDomain: this.textDomain,
authorName: this.authorName,
repoLocation: this.repoLocation
}
)

this.fs.copyTpl(
this.templatePath('_bootstrap.php'),
this.destinationPath('tests/bootstrap.php'), {
pluginConst: this.pluginConst,
textDomain: this.textDomain,
}
)

this.fs.copyTpl(
this.templatePath('_index.php'),
this.destinationPath(this.textDomain + '.php'), {
unitName: this.unitName,
pluginName: this.pluginName,
description: this.description,
projectHome: this.projectHome,
textDomain: this.textDomain,
pluginSlug: this.pluginSlug,
authorName: this.authorName,
authorUrl: this.authorUrl,
pluginConst: this.pluginConst,
packageName: this.packageName
}
)

this.fs.copyTpl(
this.templatePath('_composer.json'),
this.destinationPath('composer.json'), {
description: this.description,
textDomain: this.textDomain,
authorName: this.authorName,
authorUrl: this.authorUrl,
authorEmail: this.authorEmail
}
)

this.fs.copyTpl(
this.templatePath('_Gruntfile.js'),
this.destinationPath('Gruntfile.js'), {
textDomain: this.textDomain,
needsCSS: this.needsCSS,
needsJS: this.needsJS
}
)

this.fs.copyTpl(
this.templatePath('_README.md'),
this.destinationPath('README.md'), {
unitName: this.unitName,
pluginName: this.pluginName,
description: this.description,
needsDocker: this.needsDocker,
textDomain: this.textDomain,
}
)

this.fs.copyTpl(
this.templatePath('_uninstall.php'),
this.destinationPath('uninstall.php'), {
unitName: this.unitName,
pluginName: this.pluginName,
packageName: this.packageName,
authorName: this.authorName,
authorEmail: this.authorEmail
}
)

if (true === this.needsCSS) {
this.fs.copyTpl(
this.templatePath('_plugin.scss'),
this.destinationPath('assets/css/scss/' + this.textDomain + '.scss'), {
unitName: this.unitName,
pluginName: this.pluginName,
projectHome: this.projectHome,
authorName: this.authorName
}
)
}

if (true === this.needsJS) {
this.fs.copyTpl(
this.templatePath('_plugin.js'),
this.destinationPath('assets/js/src/' + this.textDomain + '.js'), {
unitName: this.unitName,
pluginName: this.pluginName,
projectHome: this.projectHome,
authorName: this.authorName
}
)
}

}

install () {
this.spawnCommandSync('composer', ['require', 'phpunit/phpunit:6.5.*', '--dev'])
this.spawnCommandSync('composer', ['require', 'wp-cli/wp-cli', '--dev'])
this.spawnCommandSync('composer', ['require', 'stevegrunwell/wp-enforcer', '--dev'])

}

end () {

this.spawnCommandSync('grunt', [])
if ( '' !== this.repoLocation ) {
this.spawnCommandSync('git', ['init'])
}
this.spawnCommandSync('./vendor/bin/wp-enforcer', [])

}
}

+ 213
- 0
generators/plugin/templates/_.gitignore View File

@@ -0,0 +1,213 @@
### Vim template
# swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags
### Vagrant template
.vagrant/
### SublimeText template
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache

# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
### Eclipse template

.metadata
bin/
!tests/bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
### macOS template
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Linux template

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Windows template
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk
### TextMate template
*.tmproj
*.tmproject
tmtags

# Build Assets
node_modules
vendor
languages/*.pot
assets/css/*.css
assets/css/*.map
assets/js/*.js
assets/js/*.map

# Docker files
Docker/database
Docker/wordpress
Docker/logs
Docker/debug
!Docker/bin

# Leftovers
.yo-rc.json

+ 0
- 0
generators/plugin/templates/_.gitkeep View File


+ 59
- 0
generators/plugin/templates/_.gitlab-ci.yml View File

@@ -0,0 +1,59 @@
variables:
MYSQL_DATABASE: wordpress_tests
MYSQL_ROOT_PASSWORD: mysql
WP_VERSION: latest
WP_MULTISITE: "0"
GIT_SSL_NO_VERIFY: 'true'

services:
# We need MySQL to run our unit tests
- mysql:5.7

before_script:
# Install git, and php libraries the php image doesn't have installed
- apt-get update -yqq
- apt-get install git wget gnupg -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php

stages:
- build
- test

# Let's get assets, language files and compoaser and node builds
build_assets:
stage: build
image: php:7.2
script:
- php composer.phar install
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
- apt-get install nodejs -yqq
- npm -g install grunt grunt-cli
- npm install
- grunt
artifacts:
expire_in: 1 day
paths:
- vendor/
- languages/
cache:
paths:
- node_modules/
- vendor/

# Test PHP 7.2
test:7.2:
stage: test
image: php:7.2
script:
# Install required packages
- apt-get install libxml2-dev unzip zip unzip subversion mysql-client libmcrypt-dev --fix-missing -yqq
# Install PHP libs
- docker-php-ext-install mysqli pdo_mysql mbstring
- docker-php-ext-enable mysqli pdo_mysql mbstring
# Install Xdebug
- pecl install xdebug
- docker-php-ext-enable xdebug
# Install and run unit tests
- bash tests/bin/install-wp-tests.sh wordpress_test root mysql mysql $WP_VERSION
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --colors=never

+ 27
- 0
generators/plugin/templates/_.jshintrc View File

@@ -0,0 +1,27 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"es3": true,
"expr": true,
"immed": true,
"noarg": true,
"nonbsp": true,
"onevar": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,
"browser": true,
"globals": {
"_": false,
"Backbone": false,
"jQuery": false,
"JSON": false,
"wp": false,
"export": false,
"module": false,
"require": false
}
}

+ 212
- 0
generators/plugin/templates/_Gruntfile.js View File

@@ -0,0 +1,212 @@
module.exports = function (grunt) {

const sass = require('node-sass');

// Start out by loading the grunt modules we'll need
require('load-grunt-tasks')(grunt);

// Show elapsed time
require('time-grunt')(grunt);

grunt.initConfig(
{

<% if (true === needsCSS) { %>

/**
* Auto-prefix CSS Elements after SASS is processed.
*/
autoprefixer: {

options: {
browsers: ['last 5 versions'],
map: true
},

files: {
expand: true,
flatten: true,
src: ['assets/css/<%= textDomain %>.css'],
dest: 'assets/css'
}
},

/**
* Minify CSS after prefixes are added
*/
cssmin: {

target: {

files: [{
expand: true,
cwd: 'assets/css',
src: ['<%= textDomain %>.css'],
dest: 'assets/css',
ext: '.min.css'
}]

}
},

/**
* Process SASS
*/
sass: {

dist: {

options: {
style: 'expanded',
sourceMap: true,
implementation: sass
},

files: {
'assets/css/<%= textDomain %>.css': 'assets/css/scss/<%= textDomain %>.scss'
}
}
},

/**
* Clean existing files
*/
clean: {
styles: {
src: [
'assets/css/*.css',
'assets/css/*.map'
]
},
scripts: {
src: [
'assets/js/*.js',
'assets/js/*.map'
]
}
},

<% } %>

<% if (true === needsJS) { %>

/**
* Processes and compresses JavaScript.
*/
uglify: {

production: {

options: {
beautify: false,
preserveComments: false,
sourceMap: false,
mangle: {
reserved: ['jQuery']
}
},

files: {
'assets/js/<%= textDomain %>.min.js': [
'assets/js/src/<%= textDomain %>.js'
]
}
},

dev: {

options: {
beautify: true,
preserveComments: true,
sourceMap: true,
mangle: {
reserved: ['jQuery']
}
},

files: {
'assets/js/<%= textDomain %>.js': [
'assets/js/src/<%= textDomain %>.js'
]
}
}
},

/**
* Clean up the JavaScript
*/
jshint: {
options: {
jshintrc: true
},
all: ['assets/js/src/<%= textDomain %>.js']
},

<% } %>

<% if (true === needsCSS || true === needsJS) { %>

/**
* Watch scripts and styles for changes
*/
watch: {

options: {
livereload: true
},

<% if (true === needsJS) { %>

scripts: {

files: [
'assets/js/src/*'
],

tasks: ['uglify:production']

}<% if (true === needsCSS) { %>,<% } %>

<% } %>

<% if (true === needsCSS) { %>

styles: {

files: [
'assets/css/scss/*'
],

tasks: ['sass', 'autoprefixer', 'cssmin']

}

<% } %>
},
<% } %>

/**
* Update translation file.
*/
makepot: {

target: {
options: {
type: 'wp-plugin',
domainPath: '/languages',
mainFile: '<%= textDomain %>.php',
potFilename: '<%= textDomain %>.pot',
exclude: ['vendor']
}
}
}
}
);

// A very basic default task.
grunt.registerTask('default', [<% if (true === needsJS) { %>'jshint', 'uglify:production', 'uglify:dev', <% } %><% if (true === needsCSS) { %>'sass', 'autoprefixer', 'cssmin', <% } %>'makepot']);
<% if (true === needsCSS || true === needsJS) { %>
grunt.registerTask('dev', ['default', 'watch']);
<% } %>

};

+ 97
- 0
generators/plugin/templates/_README.md View File

@@ -0,0 +1,97 @@
<%if ( '' !== unitName ) { %><%= unitName %> <% } %><%= pluginName %>
=============

<%= description %>

## Installation and Usage

In order to improve efficiency processed files such as minified JS, CSS and .pot files are not stored in this repository. To use this plugin:

1. Clone the repository
2. Change to the repository directory
3. Run ```composer install```
4. Run ```npm install```
5. Run ```grunt```
6. Map or copy the plugin folder to your WordPress plugins folder to activate like a regular plugin.

*Note: you might have to install Grunt globally first with ```npm -g install grunt```*

## Recommended Developer Workflow

1. Commit the initial plugin scaffolding to the *master* branch in a new repository
2. Branch to develop to work
3. Merge back to master and tag with the plugin version for release

##### Anatomy of the plugin scaffold

- assets - Asset files including CSS, JS, images, etc
- assets/css - Holds processed CSS files
- assets/css/scss - Holds the SCSS files for editing and processing. All your editing of CSS/SCSS files should be in this folder.
- assets/js - Holds the processed JS files
- assets/js/src - Hold the JavaScript source files to be processed. All your editing of JavaScript files should be in this folder.
- includes - All PHP functionality should go in here
- tests - Holds all PhpUnit tests

##### Anatomy of the Grunt file

The Grunt process performs the following y default

1. Runs unit tests with PhpUnit
2. Runs jshint to link all JavaScript source files (WP-enforcer checks PHP on commit)
3. Minifies all JS source files
4. Processes SASS files to un-minified CSS
5. Auto-prefixes the processed CSS files
6. Creates minified versions of the CSS files
7. Creates a .pot file with all translatable strings from PHP

By default the Gruntfile only looks at a single JS and SCSS file. If you need to add more simply modify the Gruntfile to add additional files for processing.

##### Using minified CSS and JS in your plugin

Minified JS and CSS is great in production but it can make development much harder. Fortunately Grunt helps us by building oth minified versions as well as development versions of all of our CSS and JS. To best utilize these in your plugin it is recommended to swap between using SCRIPT_DEBUG. Here's a great article to help you utilize this in your plugin: [https://pippinsplugins.com/use-script_debug-enable-non-minified-asset-files/](https://pippinsplugins.com/use-script_debug-enable-non-minified-asset-files/)

<% if (true === needsDocker) { %>
##### Developing your plugin locally

Bundled with this plugin is a Docker configuration compatible with our [Ouroboros](https://github.com/UFHealth/ouroboros) Docker hub. Here's how do get it running.

1. Clone and bring up [Ouroboros](https://github.com/UFHealth/ouroboros) using the instructions on its page
2. Run `./develop up -d` in this repo
3. Run the setup script using the following `./Docker/bin/setup`
4. Visit the site at [https://<%= textDomain %>.test]

To access the WordPress Dashboard for the development site use the username `admin` and the password `password`

###### Accessing the PHP server

Should you need to access the PHP server directly you can do so in the terminal by running ```./Docker/bin/shell```

###### Running WP-cli commands

You can run WP-cli commands directly against the system by running the *wp* script in *Docker/bin*. For example: ```./Docker/bin/wp site list``` will give you a site list.

###### Setting up Xdebug

[Xdebug](https://xdebug.org/) is available. To access you'll need to set the *XDEBUG_SESSION* cookie to *DOCKER_DEBUG* and listen for the connection in your ide (map your local files to */var/www/html/wp-content/plugins/<%= textDomain %>* in the IDE to get correct path mappings). A plugin such as [https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc can make setting the cookie easy]

*Note: If you don't use the "develop" script to bring up the environment you'll need to manually setup the correct environment variable to get XDebug to work correctly*

## Accessing the Database Directly

By default the database ports aren't exposed to your host machine as doing so can cause conflicts if multiple projects are run at the same time. To access the database directly first bring down your server `./develop down`, then create `docker-compose.override.yml` and add the following to it:

```
version: '3'

services:
mariadb:
ports:
- "3306:3306"
```

Then bring up the environment again with the develop script. You can then access the database with the username `root` and the password `password` on `127.0.0.1`. Use Navicat, Sequel Pro, or any tool to import the starter database.
<% } %>
## Changelog

##### 1.0
* Initial Release

+ 34
- 0
generators/plugin/templates/_bootstrap.php View File

@@ -0,0 +1,34 @@
<?php
/**
* PHPUnit bootstrap file
*
* @package Chriswiegman_Plugin
*/

$_tests_dir = getenv( 'WP_TESTS_DIR' );

if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}

if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
echo "Could not find $_tests_dir/includes/functions.php, have you run tests/bin/install-wp-tests.sh ?" . PHP_EOL;
exit( 1 );
}

// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';

/**
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {

require dirname( dirname( __FILE__ ) ) . '/<%= textDomain %>.php';
}

tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';


+ 24
- 0
generators/plugin/templates/_composer.json View File

@@ -0,0 +1,24 @@
{
"name": "WordPress-Plugins/<%= textDomain %>",
"description": "<%= description %>",
"type": "wordpress-plugin",
"keywords": [],
"authors": [
{
"name": "<%= authorName %>",
"email": "<%= authorEmail %>",
"homepage": "<%= authorUrl %>",
"role": "Developer"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=7.2"
},
"post-install-cmd": [
"wp-enforcer"
],
"post-update-cmd": [
"wp-enforcer"
]
}

+ 14
- 0
generators/plugin/templates/_develop View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Set environment variables for dev
if [ "Darwin" == $(uname -s) ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0)
else
export XDEBUG_HOST=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi

if [ $# -gt 0 ]; then
docker-compose -p ${PWD##*/} "$@" # Specify project name based on current directory
else
docker-compose ps
fi

+ 57
- 0
generators/plugin/templates/_docker-compose.yml View File

@@ -0,0 +1,57 @@
version: '3'

networks:
default:
driver: bridge
ouroboros_default:
external: true

services:
mariadb:
image: mariadb
volumes:
- "./Docker/database:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: username
MYSQL_PASSWORD: password
networks:
- default
labels:
- 'traefik.enable=false'
phpfpm:
image: ufhweb/php:7.2-wordpress
depends_on:
- mariadb
volumes:
- "./Docker/wordpress:/var/www/html"
- "./:/var/www/html/wp-content/plugins/<%= textDomain %>"
- "./Docker/debug:/data/debug"
- "./Docker/logs/php:/var/log/php-fpm"
restart: always
networks:
- default
- ouroboros_default
labels:
- 'traefik.enable=false'
environment:
XDEBUG_HOST: ${XDEBUG_HOST}
httpd:
depends_on:
- phpfpm
image: ufhweb/apache:2.4
volumes:
- "./Docker/wordpress:/var/www/html"
- "./:/var/www/html/wp-content/plugins/<%= textDomain %>"
- "./Docker/logs/httpd:/var/log/apache2"
restart: always
networks:
- default
- ouroboros_default
labels:
- 'traefik.frontend.rule=Host:<%= textDomain %>.test'
- 'traefik.domain=<%= textDomain %>.test'
- 'traefik.enable=true'
- 'traefik.docker.network=ouroboros_default'

+ 30
- 0
generators/plugin/templates/_index.php View File

@@ -0,0 +1,30 @@
<?php
/**
* Plugin Name: <%if ( '' !== unitName ) { %><%= unitName %> <% } %><%= pluginName %>
* Plugin URI: <%= projectHome %>
* Description: <%= description %>
* Version: 1.0
* Text Domain: <%= textDomain %>
* Domain Path: /languages
* Author: <%= authorName %>
* Author URI: <%= authorUrl %>
* License: GPLv2
*
* @package <%= packageName %>
*/

define( '<%= pluginConst %>_VERSION', '1.0' );
define( '<%= pluginConst %>_URL', plugin_dir_url( __FILE__ ) );
define( '<%= pluginConst %>_INCLUDES', trailingslashit( plugin_dir_path( __FILE__ ) ) . 'includes/' );

add_action( 'plugins_loaded', '<%= pluginSlug %>_loader' );

/**
* Load plugin functionality.
*/
function <%= pluginSlug %>_loader() {

// Remember the text domain.
load_plugin_textdomain( '<%= textDomain %>', false, dirname( dirname( __FILE__ ) ) . '/languages' );

}

+ 152
- 0
generators/plugin/templates/_install-wp-tests.sh View File

@@ -0,0 +1,152 @@
#!/usr/bin/env bash

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
exit 1
fi

DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}

TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}

download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}

if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
exit 1
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi

set -ex

install_wp() {

if [ -d $WP_CORE_DIR ]; then
return;
fi

mkdir -p $WP_CORE_DIR

if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p $TMPDIR/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi

download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi

}

install_db() {

if [ ${SKIP_DB_CREATE} = "true" ]; then
return 0
fi

# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}

install_wp
install_test_suite
install_db

+ 10
- 0
generators/plugin/templates/_package.json View File

@@ -0,0 +1,10 @@
{
"name": "<%= textDomain %>",
"private": true,
"author": "<%= authorName %>"<% if (repoLocation != "") { %>,
"repository": {
"type": "git",
"url": "<%= repoLocation %>"
}
<% } %>
}

+ 21
- 0
generators/plugin/templates/_phpcs.xml View File

@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="WP-Enforcer">
<description>Coding standards from WP Enforcer.</description>

<!-- FILES -->
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*.xml</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*.js</exclude-pattern>


<!-- Rules -->
<rule ref="WordPress-Core"/>
<rule ref="WordPress-Docs"/>
<rule ref="WordPress-Extra"/>

<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>
</ruleset>

+ 20
- 0
generators/plugin/templates/_phpunit.xml View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./includes</directory>
</whitelist>
</filter>
</phpunit>

+ 7
- 0
generators/plugin/templates/_plugin.js View File

@@ -0,0 +1,7 @@
/**
* <%if ( '' !== unitName ) { %><%= unitName %> <% } %><%= pluginName %>
* <%= projectHome %>
*
* Copyright (c) <%= new Date().getFullYear() %> <%= authorName %>
* Licensed under the GPLv2+ license.
*/

+ 7
- 0
generators/plugin/templates/_plugin.scss View File

@@ -0,0 +1,7 @@
/**
* <%if ( '' !== unitName ) { %><%= unitName %> <% } %><%= pluginName %>
* <%= projectHome %>
*
* Copyright (c) <%= new Date().getFullYear() %> <%= authorName %>
* Licensed under the GPLv2+ license.
*/

+ 22
- 0
generators/plugin/templates/_setup View File

@@ -0,0 +1,22 @@
#!/bin/bash

# Set environment variables for dev
if [ "Darwin" == $(uname -s) ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0)
else
export XDEBUG_HOST=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi

if [ -f "./wordpress/wp-config.php" ];
then
echo "WordPress config file found."
else
echo "WordPress config file not found. Installing..."
export XDEBUG_HOST=$(ipconfig getifaddr en0) # Specific to Macintosh
docker-compose exec --user www-data phpfpm wp core download
docker-compose exec --user www-data phpfpm wp core config --dbhost=mariadb --dbname=wordpress --dbuser=root --dbpass=password
docker-compose exec --user www-data phpfpm wp core install --url=<%= textDomain %>.test --title="WordPress Development" --admin_user=admin --admin_password=password --admin_email=info@example.com
docker-compose exec --user www-data phpfpm wp plugin uninstall hello akismet
docker-compose exec --user www-data phpfpm wp plugin install any-ipsum debug-bar wp-inspect heartbeat-control query-monitor whats-running debug-bar-remote-requests wordpress-php-info wordpress-beta-tester
docker-compose exec --user www-data phpfpm wp plugin activate <%= textDomain %>
fi

+ 10
- 0
generators/plugin/templates/_shell View File

@@ -0,0 +1,10 @@
#!/bin/bash

# Set environment variables for dev
if [ "Darwin" == $(uname -s) ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0)
else
export XDEBUG_HOST=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi

docker-compose exec --user root phpfpm bash

+ 74
- 0
generators/plugin/templates/_uninstall.php View File

@@ -0,0 +1,74 @@
<?php
/**
* <%if ( '' !== unitName ) { %><%= unitName %> <% } %><%= pluginName %> uninstaller
*
* Used when clicking "Delete" from inside of WordPress's plugins page.
*
* @package <%= packageName %>
*
* @since 1.0
*
* @author <%= authorName %> <<%= authorEmail %>>
*/

namespace <%= packageName %>\Uninstall;

/**
* Initialize uninstaller
*
* Perform some checks to make sure plugin can/should be uninstalled
*
* @since 1.0
*/
function perform_uninstall() {

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit_uninstaller();
}

// Not uninstalling.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit_uninstaller();
}

// Not uninstalling.
if ( ! WP_UNINSTALL_PLUGIN ) {
exit_uninstaller();
}

// Not uninstalling this plugin.
if ( dirname( WP_UNINSTALL_PLUGIN ) !== dirname( plugin_basename( __FILE__ ) ) ) {
exit_uninstaller();
}

// Uninstall <%if ( '' !== unitName ) { %><%= unitName %> <% } %><%= pluginName %>.
clean_data();
}

/**
* Cleanup options
*
* Deletes plugin options and post_meta.
*
* @since 1.0
*/
function clean_data() {

}

/**
* Exit uninstaller
*
* Gracefully exit the uninstaller if we should not be here
*
* @since 1.0
*/
function exit_uninstaller() {

status_header( 404 );
exit;

}

perform_uninstall();

+ 10
- 0
generators/plugin/templates/_wp View File

@@ -0,0 +1,10 @@
#!/bin/bash

# Set environment variables for dev
if [ "Darwin" == $(uname -s) ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0)
else
export XDEBUG_HOST=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi

docker-compose exec --env "PHP_IDE_CONFIG=serverName=<%= textDomain %>.test" --user www-data phpfpm wp "$@"

+ 10
- 0
generators/plugin/templates/_xloff View File

@@ -0,0 +1,10 @@
#!/bin/bash

# Set environment variables for dev
if [ "Darwin" == $(uname -s) ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0)
else
export XDEBUG_HOST=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi

docker-compose exec phpfpm /usr/local/bin/xloff.sh "$@"

+ 10
- 0
generators/plugin/templates/_xlon View File

@@ -0,0 +1,10 @@
#!/bin/bash

# Set environment variables for dev
if [ "Darwin" == $(uname -s) ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0)
else
export XDEBUG_HOST=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
fi

docker-compose exec phpfpm /usr/local/bin/xlon.sh "$@"

+ 4087
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 24
- 0
package.json View File

@@ -0,0 +1,24 @@
{
"name": "generator-wp",
"description": "WordPress scaffolding generator for use within UF Health properties.",
"keywords": [
"yeoman-generator",
"wordpress"
],
"dependencies": {
"chalk": "2.4.1",
"extendable-yeoman": "0.3.1",
"no-case": "2.3.2",
"yeoman-generator": "3.0.0"
},
"files": [
"generators"
],
"author": {
"name": "Chris Wiegman",
"email": "cwiegman@ufl.edu",
"url": "https://ufhealth.org/"
},
"repository": "https://github.com/UFHealth/generator-wp",
"license": "MIT"
}