Skip to content

Commit

Permalink
Merge pull request #31 from bigbite/feature/mu-plugins
Browse files Browse the repository at this point in the history
Allow user to add mu-plugins folder
  • Loading branch information
Liam Defty authored May 21, 2020
2 parents b4131f0 + 94de86f commit c698361
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 28 additions & 9 deletions lib/cli/modules/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ const verifyWPVersion = require('./verifyWPVersion');
const createDockerComposeFile = require('./createDockerComposeFile');
const asyncMap = require('../../utils/asyncMap');

const defaultConfig = {
version: ['5.4'],
'mu-plugins': false,
plugins: [],
themes: [],
config: {},
port: false,
timezone: false,
};

const createConfig = async (userConfig, dir) => {
const config = {
...defaultConfig,
...userConfig,
};

const volumes = [
`${dir}/config.json:/var/www/html/config.json`,
`${dir}/config/php.ini:/usr/local/etc/php/php.ini`,
Expand All @@ -18,8 +33,12 @@ const createConfig = async (userConfig, dir) => {
const plugins = [];
const themes = [];

if (userConfig.plugins.length > 0) {
userConfig.plugins.forEach((x) => {
if (config['mu-plugins']) {
volumes.push(`${path.resolve(config['mu-plugins'])}:/var/www/html/wp-content/mu-plugins`);
}

if ((config.plugins || []).length > 0) {
config.plugins.forEach((x) => {
const location = path.resolve(x);

glob.sync(location).forEach((file) => {
Expand All @@ -36,8 +55,8 @@ const createConfig = async (userConfig, dir) => {
});
}

if (userConfig.themes.length > 0) {
userConfig.themes.forEach((x) => {
if (config.plugins || [].length > 0) {
config.themes.forEach((x) => {
const location = path.resolve(x);

glob.sync(location).forEach((file) => {
Expand All @@ -59,10 +78,10 @@ const createConfig = async (userConfig, dir) => {
let versions = [];

// Version could be an array|string
if (Array.isArray(userConfig.version)) {
versions = [...userConfig.version];
if (Array.isArray(config.version)) {
versions = [...config.version];
} else {
versions.push(userConfig.version);
versions.push(config.version);
}

versions = await asyncMap(versions, async (ver) => {
Expand All @@ -74,10 +93,10 @@ const createConfig = async (userConfig, dir) => {

shell.sed('-i', 'WP_VERSIONS', validVersions.join(' '), `${dir}/Dockerfile`);

createDockerComposeFile(dir, userConfig.port, volumes);
createDockerComposeFile(dir, config.port, volumes);

return {
...userConfig,
...config,
version: versions,
validVersions,
plugins,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bigbite/wp-cypress",
"version": "0.5.1",
"version": "0.5.2",
"description": "WordPress end to end testing with Cypress.io",
"repository": "https://github.com/bigbite/wp-cypress",
"author": {
Expand Down

0 comments on commit c698361

Please sign in to comment.