diff --git a/.github/scripts/build-wp-env.js b/.github/scripts/build-wp-env.js index 9037a539..fc20901c 100644 --- a/.github/scripts/build-wp-env.js +++ b/.github/scripts/build-wp-env.js @@ -37,7 +37,7 @@ wpEnv.core = wpCore; if ( fs.existsSync( './tmp/hello-elementor' ) ) { wpEnv.themes = [ './tmp/hello-elementor' ]; // eslint-disable-next-line no-console - console.log( '✅ Using built Hello Theme from ./tmp/hello-elementor' ); + console.log( 'Using built Hello Theme from ./tmp/hello-elementor' ); } else { // eslint-disable-next-line no-console console.error( 'Built Hello Theme not found at ./tmp/hello-elementor' ); @@ -64,124 +64,19 @@ if ( HELLO_PLUS_VERSION && fs.existsSync( './tmp/hello-plus' ) ) { // Configure plugins wpEnv.plugins = []; -// Add Elementor plugin -if ( ELEMENTOR_VERSION ) { - // eslint-disable-next-line no-console - console.log( '🔍 =============================================' ); - // eslint-disable-next-line no-console - console.log( '🔍 BUILD-WP-ENV.JS ELEMENTOR DEBUG' ); - // eslint-disable-next-line no-console - console.log( '🔍 =============================================' ); - // eslint-disable-next-line no-console - console.log( `🎯 ELEMENTOR_VERSION: "${ ELEMENTOR_VERSION }"` ); - - if ( 'latest-stable' === ELEMENTOR_VERSION ) { - // Use WordPress.org directly for latest-stable (most reliable) - wpEnv.plugins.push( 'https://downloads.wordpress.org/plugin/elementor.latest-stable.zip' ); - // eslint-disable-next-line no-console - console.log( '✅ Using WordPress.org Elementor latest-stable (direct)' ); - } else if ( ELEMENTOR_VERSION.match( /^v?[0-9]+\.[0-9]+\.[0-9]+$/ ) ) { - // Use WordPress.org directly for semantic versions (e.g., 3.30.4, v3.30.4) - const cleanVersion = ELEMENTOR_VERSION.replace( /^v/, '' ); - wpEnv.plugins.push( `https://downloads.wordpress.org/plugin/elementor.${ cleanVersion }.zip` ); - // eslint-disable-next-line no-console - console.log( `✅ Using WordPress.org Elementor ${ cleanVersion } (direct)` ); - } else if ( fs.existsSync( './tmp/elementor' ) ) { - // GitHub branches (main, feature-branch) - expect built artifacts from workflow - // eslint-disable-next-line no-console - console.log( `🔍 Using GitHub built artifacts for Elementor ${ ELEMENTOR_VERSION }` ); - // Debug: Verify Elementor directory structure - // eslint-disable-next-line no-console - console.log( '🔍 DEBUG: Elementor directory found, verifying structure...' ); - try { - const elementorContents = fs.readdirSync( './tmp/elementor' ); - // eslint-disable-next-line no-console - console.log( `📁 Elementor directory contents (${ elementorContents.length } items):`, elementorContents.slice( 0, 10 ) ); - - // Check for main plugin file - if ( fs.existsSync( './tmp/elementor/elementor.php' ) ) { - // eslint-disable-next-line no-console - console.log( '✅ Main plugin file found: elementor.php' ); - - // Read plugin header for verification - try { - const pluginContent = fs.readFileSync( './tmp/elementor/elementor.php', 'utf8' ); - const headerMatch = pluginContent.match( /Plugin Name:\s*(.+)/i ); - const versionMatch = pluginContent.match( /Version:\s*(.+)/i ); - if ( headerMatch ) { - // eslint-disable-next-line no-console - console.log( `📄 Plugin Name: ${ headerMatch[ 1 ].trim() }` ); - } - if ( versionMatch ) { - // eslint-disable-next-line no-console - console.log( `🏷️ Plugin Version: ${ versionMatch[ 1 ].trim() }` ); - } - } catch ( error ) { - // eslint-disable-next-line no-console - console.log( '⚠️ Could not read plugin header:', error.message ); - } - } else { - // eslint-disable-next-line no-console - console.log( '❌ Main plugin file missing: elementor.php' ); - const phpFiles = elementorContents.filter( ( file ) => file.endsWith( '.php' ) ); - // eslint-disable-next-line no-console - console.log( `🔍 Available PHP files (${ phpFiles.length }):`, phpFiles.slice( 0, 5 ) ); - } - - // Check for essential directories - const essentialDirs = [ 'includes', 'assets' ]; - essentialDirs.forEach( ( dir ) => { - if ( fs.existsSync( `./tmp/elementor/${ dir }` ) ) { - // eslint-disable-next-line no-console - console.log( `✅ Essential directory found: ${ dir }` ); - } else { - // eslint-disable-next-line no-console - console.log( `⚠️ Essential directory missing: ${ dir }` ); - } - } ); - } catch ( error ) { - // eslint-disable-next-line no-console - console.error( '❌ Error reading Elementor directory:', error.message ); - } +const isValidLocalElementor = fs.existsSync( './tmp/elementor/elementor.php' ) && + fs.existsSync( './tmp/elementor/includes' ) && + fs.existsSync( './tmp/elementor/assets' ); - // Check if local Elementor installation is valid - const isValidElementor = fs.existsSync( './tmp/elementor/elementor.php' ) && - fs.existsSync( './tmp/elementor/includes' ) && - fs.existsSync( './tmp/elementor/assets' ); - - if ( isValidElementor ) { - // Use the GitHub built artifacts for branches - wpEnv.plugins.push( './tmp/elementor' ); - // eslint-disable-next-line no-console - console.log( `✅ Using GitHub built artifacts for Elementor ${ ELEMENTOR_VERSION }` ); - } else { - // GitHub artifacts should be valid - if not, something went wrong in workflow - // eslint-disable-next-line no-console - console.error( `❌ Invalid GitHub artifacts for Elementor ${ ELEMENTOR_VERSION }` ); - // eslint-disable-next-line no-console - console.error( 'Expected workflow to provide valid built artifacts in ./tmp/elementor' ); - process.exit( 1 ); - } - } else { - // eslint-disable-next-line no-console - console.error( `❌ Elementor directory not found at ./tmp/elementor for branch/commit: ${ ELEMENTOR_VERSION }` ); - // eslint-disable-next-line no-console - console.error( 'Note: Semantic versions (e.g., 3.30.4) and latest-stable are downloaded directly from WordPress.org' ); - // eslint-disable-next-line no-console - console.error( '🔄 Using WordPress.org latest-stable as fallback for CI stability' ); - - // Add fallback to WordPress.org for branches to prevent CI failures - wpEnv.plugins.push( 'https://downloads.wordpress.org/plugin/elementor.latest-stable.zip' ); - // eslint-disable-next-line no-console - console.log( `⚠️ Fallback: Using WordPress.org Elementor latest-stable for ${ ELEMENTOR_VERSION }` ); - } - - // eslint-disable-next-line no-console - console.log( '🔍 =============================================' ); - // eslint-disable-next-line no-console - console.log( '🔍 END BUILD-WP-ENV.JS ELEMENTOR DEBUG' ); - // eslint-disable-next-line no-console - console.log( '🔍 =============================================' ); +let elementorSource; +if ( isValidLocalElementor ) { + wpEnv.plugins.push( './tmp/elementor' ); + elementorSource = './tmp/elementor'; +} else { + const versionMatch = ( ELEMENTOR_VERSION || '' ).match( /^v?([0-9]+\.[0-9]+\.[0-9]+)$/ ); + const wpOrgVersion = versionMatch ? versionMatch[ 1 ] : 'latest-stable'; + wpEnv.plugins.push( `https://downloads.wordpress.org/plugin/elementor.${ wpOrgVersion }.zip` ); + elementorSource = `WordPress.org ${ wpOrgVersion }`; } // Test configuration @@ -213,7 +108,7 @@ console.log( `- Hello Theme: ${ HELLO_THEME_VERSION || 'current' }` ); // eslint-disable-next-line no-console console.log( `- Hello Plus: ${ HELLO_PLUS_VERSION || 'not included' }` ); // eslint-disable-next-line no-console -console.log( `- Elementor: ${ ELEMENTOR_VERSION || 'latest-stable' }` ); +console.log( `- Elementor: ${ elementorSource }` ); // eslint-disable-next-line no-console console.log( `- Themes: ${ wpEnv.themes.join( ', ' ) }` ); // eslint-disable-next-line no-console @@ -221,4 +116,4 @@ console.log( `- Plugins: ${ wpEnv.plugins.join( ', ' ) }` ); fs.writeFileSync( '.wp-env.json', JSON.stringify( wpEnv, null, 4 ) ); // eslint-disable-next-line no-console -console.log( '✅ wp-env.json updated successfully' ); +console.log( 'wp-env.json updated successfully' );