From 729c1ac2ceeefadea41bd09ccdbb140fe3354914 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Wed, 3 May 2023 15:57:33 +0100 Subject: [PATCH] Allow admin username to set from config adminUsername --- lib/cli/commands/reset.js | 8 ++++---- lib/cli/commands/softReset.js | 6 +++--- lib/modules/createConfig.js | 1 + lib/schemas/config-validation.json | 4 ++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/cli/commands/reset.js b/lib/cli/commands/reset.js index a62405c..2f14d7d 100644 --- a/lib/cli/commands/reset.js +++ b/lib/cli/commands/reset.js @@ -86,7 +86,7 @@ if( file_exists ( ABSPATH . '.userid' ) ) { wpcli( `core ${getWPInstallType(config.multisite)} --url=${ config.url - } --title="WP Cypress" --admin_user=admin --admin_password=password --admin_email="admin@test.com" --skip-email`, + } --title="WP Cypress" --admin_user=${config.adminUsername} --admin_password=password --admin_email="admin@test.com" --skip-email`, logFile, ), 'Installing WordPress', @@ -118,9 +118,9 @@ if( file_exists ( ABSPATH . '.userid' ) ) { ); await run( - async () => wpcli('wp-cypress-set-user admin', logFile), - 'Set user to admin', - 'User set to admin', + async () => wpcli(`wp-cypress-set-user ${config.adminUsername}`, logFile), + `Set user to ${config.adminUsername}`, + `User set to ${config.adminUsername}`, logFile, ); diff --git a/lib/cli/commands/softReset.js b/lib/cli/commands/softReset.js index edda68f..a71a813 100644 --- a/lib/cli/commands/softReset.js +++ b/lib/cli/commands/softReset.js @@ -22,9 +22,9 @@ const softReset = async (packageDir, logFile, options = false) => { await cli(`bash update.sh ${version} false`, logFile); await run( - async () => wpcli('wp-cypress-set-user admin', logFile), - 'Set user to admin', - 'User set to admin', + async () => wpcli(`wp-cypress-set-user ${config.adminUsername}`, logFile), + `Set user to ${config.adminUsername}`, + `User set to ${config.adminUsername}`, logFile, ); diff --git a/lib/modules/createConfig.js b/lib/modules/createConfig.js index a60945b..cac4f5d 100644 --- a/lib/modules/createConfig.js +++ b/lib/modules/createConfig.js @@ -48,6 +48,7 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => { multisite: false, url: false, phpMemoryLimit: '128M', + adminUsername: 'admin', }); const schema = await fs.readJSON(`${packageDir}/lib/schemas/config-validation.json`); diff --git a/lib/schemas/config-validation.json b/lib/schemas/config-validation.json index ae3fdf6..d13cd03 100644 --- a/lib/schemas/config-validation.json +++ b/lib/schemas/config-validation.json @@ -20,6 +20,10 @@ "type": "string", "errorMessage": "wp.seedsPath is not a string" }, + "adminUsername": { + "type": "string", + "errorMessage": "wp.adminUsername is not a string" + }, "multisite": { "type": ["boolean", "string"], "errorMessage": "multisite is not set to false, true or subdomains"