Skip to content

Commit

Permalink
Merge pull request #40 from bigbite/release/0.7.0
Browse files Browse the repository at this point in the history
Release/0.7.0
  • Loading branch information
Liam Defty authored Aug 13, 2020
2 parents 3fe0504 + 0d5c4fc commit 8ddcd19
Show file tree
Hide file tree
Showing 32 changed files with 460 additions and 335 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ Dockerfile
docker-compose.yml
debug.log
config.json
lib/cypress-plugin/tmp
tmp
wp-content
9 changes: 8 additions & 1 deletion Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ RUN curl -o /bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/pha
&& wp --info --allow-root

RUN set -ex; \
for version in WP_VERSIONS; do curl https://wordpress.org/wordpress-${version}.tar.gz > wordpress-${version}.tar.gz && mkdir -p /var/www/${version} && tar -xzf wordpress-${version}.tar.gz -C /var/www/${version} && mv /var/www/${version}/wordpress/* /var/www/${version} && rm -rf /var/www/${version}/wordpress && chown -R www-data:www-data /var/www/${version}; done
for version in WP_VERSIONS; \
do curl https://wordpress.org/wordpress-${version}.tar.gz > wordpress-${version}.tar.gz && \
mkdir -p /var/www/${version} && \
tar -xzf wordpress-${version}.tar.gz -C /var/www/${version} && \
mv /var/www/${version}/wordpress/* /var/www/${version} && \
rm -rf /var/www/${version}/wordpress && \
chown -R www-data:www-data /var/www/${version}; \
done

EXPOSE 80

Expand Down
64 changes: 54 additions & 10 deletions lib/cli/commands/reset.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const fs = require('fs-extra');
const shell = require('shelljs');

const { wpcli, cli } = require('../modules/exec');
const run = require('../modules/run');
const configureWordPress = require('../modules/configureWordPress');
const packageConfig = require('../../utils/packageConfig');
const { wpcli, cli } = require('../../modules/exec');
const run = require('../../modules/run');

/**
* Restore the instance to its initial state.
* Restore WP to it's initial state.
*
* @param {String} packageDir - Path to the package directory.
* @param {Object} logFile - Logfile to output stdout and stderr.
* @param {Object} options - CLI options.
*/
const reset = async (packageDir, logFile, options) => {
const pkgConfig = await packageConfig();
const config = await pkgConfig.get();
const reset = async (packageDir, logFile, options = false) => {
const config = fs.readJsonSync(`${packageDir}/config.json`);

const version = typeof options.version === 'string' ? options.version : config.validVersions[0];
const version = (options && typeof options.version === 'string') ? options.version : config.validVersions[0];

shell.cd(packageDir);

Expand All @@ -33,6 +32,10 @@ const reset = async (packageDir, logFile, options) => {
--extra-php <<PHP
define( 'FS_METHOD', 'direct' ); ${wpConfigKeys.map((key) => `
define( '${key}', ${config.config[key]} );`).join('')}
${config.vip ? `
if ( file_exists( __DIR__ . '/wp-content/vip-config/vip-config.php' ) ) {
require_once( __DIR__ . '/wp-content/vip-config/vip-config.php' );
}` : ''}
PHP
`, logFile),
'Creating wp-config.php',
Expand Down Expand Up @@ -61,7 +64,48 @@ PHP
logFile,
);

await configureWordPress(config, logFile);
if (config.timezone) {
await run(
async () => wpcli(`option update timezone_string ${config.timezone}`, logFile),
'Updating timezone',
'Timezone updated',
logFile,
);
}

const plugins = config.plugins.map((x) => x.name).join(' ');

await run(
async () => wpcli(`plugin activate wp-cypress ${plugins}`, logFile),
'Activating plugins',
'Activated plugins',
logFile,
false,
);

if (config.themes.length > 0) {
await run(
async () => wpcli(`theme activate ${config.themes[0].name}`, logFile),
`Activating ${config.themes[0].name} theme`,
`Activated ${config.themes[0].name} theme`,
logFile,
false,
);
}

await run(
async () => wpcli('seed DefaultUsers', logFile),
'Creating default users',
'Default users created',
logFile,
);

await run(
async () => wpcli('seed DefaultSeeder', logFile),
'Running default seeder',
'Default seeder successfully ran',
logFile,
);
};

module.exports = reset;
20 changes: 10 additions & 10 deletions lib/cli/commands/start.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const shell = require('shelljs');

const retryCommand = require('../modules/retryCommand');
const createConfig = require('../modules/createConfig');
const { exec, cli } = require('../modules/exec');
const run = require('../modules/run');
const packageConfig = require('../../utils/packageConfig');
const maybeCopyWPContent = require('../../modules/maybeCopyWPContent');
const retryCommand = require('../../modules/retryCommand');
const createConfig = require('../../modules/createConfig');
const { exec, cli } = require('../../modules/exec');
const run = require('../../modules/run');
const reset = require('./reset');

/**
* Start the docker the test container and wait for the database to be connected.
* @param {Object} userConfig - Cypress configuration specific to this package.
* @param {String} packageDir - Path to the package directory.
* @param {Object} logFile - Logfile to output stdout and stderr.
*/
const start = async (userConfig, packageDir, logFile) => {
const config = await createConfig(userConfig, packageDir);
packageConfig(config);
const start = async (packageDir, logFile) => {
const config = await createConfig(packageDir);

await maybeCopyWPContent(config, packageDir, logFile);

shell.cd(packageDir);

Expand Down Expand Up @@ -46,7 +46,7 @@ const start = async (userConfig, packageDir, logFile) => {
logFile,
);

await reset(packageDir, logFile, {});
await reset(packageDir, logFile);
};

module.exports = start;
4 changes: 2 additions & 2 deletions lib/cli/commands/stop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const shell = require('shelljs');

const run = require('../modules/run');
const { exec } = require('../modules/exec');
const run = require('../../modules/run');
const { exec } = require('../../modules/exec');

/**
* Stop and remove the test container.
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/commands/wp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const shell = require('shelljs');
const { wpcli } = require('../modules/exec');
const { wpcli } = require('../../modules/exec');

const run = require('../modules/run');
const run = require('../../modules/run');

/**
* Execute the wordpress cli inside the test container.
Expand Down
5 changes: 2 additions & 3 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const fs = require('fs');
const { program } = require('commander');

const { version, name } = require('../../package.json');
// eslint-disable-next-line import/no-dynamic-require
const userConfig = require(`${process.cwd()}/cypress.json`).wp;

const packageDir = `${process.cwd()}/node_modules/${name}`;
const logFile = fs.createWriteStream(`${packageDir}/debug.log`);

Expand All @@ -19,7 +18,7 @@ program
program
.command('start')
.description('Start a test environment')
.action(() => start(userConfig, packageDir, logFile));
.action(() => start(packageDir, logFile));

program
.command('stop')
Expand Down
47 changes: 0 additions & 47 deletions lib/cli/modules/configureWordPress.js

This file was deleted.

119 changes: 0 additions & 119 deletions lib/cli/modules/createConfig.js

This file was deleted.

Loading

0 comments on commit 8ddcd19

Please sign in to comment.