Ticket #5207: 5207-subdir-check.diff
File 5207-subdir-check.diff, 5.7 KB (added by , 4 years ago) |
---|
-
cli/class-block-plugin-checker.php
34 34 protected $headers = null; 35 35 protected $blocks = null; 36 36 protected $block_json_files = null; 37 protected $potential_block_directories = array(); 37 38 protected $asset_php_files = null; 38 39 protected $block_json_validation = array(); 39 40 protected $block_assets = array(); … … 70 71 public function get_results( $type = null, $check = null ) { 71 72 $out = array(); 72 73 foreach ( $this->results as $result ) { 73 if ( 74 if ( 74 75 ( is_null( $type ) || $type === $result->type ) && 75 76 ( is_null( $check ) || $check === $result->check_name ) 76 77 ) { … … 193 194 } else { 194 195 return $this->results; 195 196 } 196 197 197 198 } 198 199 199 200 function export_plugin( $svn_url ) { … … 284 285 foreach ( $this->block_json_files as $filename ) { 285 286 $blocks_in_file = Import::find_blocks_in_file( $filename ); 286 287 $relative_filename = $this->relative_filename( $filename ); 287 $ potential_block_directories[] = dirname( $relative_filename );288 $this->potential_block_directories[] = dirname( $relative_filename ); 288 289 foreach ( $blocks_in_file as $block ) { 289 290 $blocks[ $block->name ] = $block; 290 291 } … … 294 295 $blocks_in_file = Import::find_blocks_in_file( $filename ); 295 296 if ( ! empty( $blocks_in_file ) ) { 296 297 $relative_filename = $this->relative_filename( $filename ); 298 $this->potential_block_directories[] = dirname( $relative_filename ); 297 299 foreach ( $blocks_in_file as $block ) { 298 300 if ( preg_match( '!\.(?:js|jsx)$!i', $relative_filename ) && empty( $block->script ) ) 299 301 $block->script = $relative_filename; … … 307 309 } 308 310 309 311 public function find_block_assets( $base_dir ) { 310 $assets = Import::find_possible_block_assets( $base_dir );312 $assets = Import::find_possible_block_assets( $base_dir, $this->potential_block_directories ); 311 313 $assets = array_map( array( $this, 'relative_filename' ), $assets ); 312 314 313 315 $block_assets = array( … … 338 340 * 339 341 * @param string $file Path to a PHP file. 340 342 * @return array A list of functions found, in (function, line, file) form. 341 */ 343 */ 342 344 public static function find_called_functions_in_file($file) { 343 345 $source = file_get_contents($file); 344 346 $tokens = token_get_all($source, TOKEN_PARSE); … … 363 365 $context[] = ' '; 364 366 } else { 365 367 $context[] = $token[0]; 366 } 368 } 367 369 } 368 370 369 371 return $function_calls; … … 646 648 } 647 649 648 650 /** 651 * Did we find block assets? 652 */ 653 function check_block_assets() { 654 $js_asset_count = count( $this->block_assets['js'] ); 655 $js_asset_result_type = $js_asset_count > 0 ? 'info' : 'warning'; 656 $css_asset_count = count( $this->block_assets['css'] ); 657 $css_asset_result_type = $css_asset_count > 0 ? 'info' : 'warning'; 658 659 $this->record_result( 660 __FUNCTION__, 661 $js_asset_result_type, 662 sprintf( 663 _n( 664 'Found %d JS asset.', 665 'Found %d JS assets.', 666 $js_asset_count, 667 'wporg-plugins' 668 ), 669 number_format_i18n( $js_asset_count ) 670 ), 671 $this->block_assets['js'] 672 ); 673 $this->record_result( 674 __FUNCTION__, 675 $css_asset_result_type, 676 sprintf( 677 _n( 678 'Found %d CSS asset.', 679 'Found %d CSS assets.', 680 $css_asset_count, 681 'wporg-plugins' 682 ), 683 number_format_i18n( $css_asset_count ) 684 ), 685 $this->block_assets['css'] 686 ); 687 } 688 689 /** 649 690 * Do the script files all exist? 650 691 */ 651 692 function check_for_block_script_files() { -
cli/class-import.php
723 723 // There must be at least on JS file, so if only css was found, keep looking. 724 724 if ( empty( preg_grep( '!\.(?:js|jsx)$!i', $build_files ) ) ) { 725 725 // Then check for files in the current directory with "build" or "min" in the filename. 726 $build_files += Filesystem::list_files( "$base_dir/$block_dir", false, '![_\-\.]+(?:build|dist|min)[_\-\.]+!i' );726 $build_files += Filesystem::list_files( "$base_dir/$block_dir", true, '![_\-\.]+(?:build|dist|min)[_\-\.]+!i' ); 727 727 } 728 728 729 729 if ( empty( preg_grep( '!\.(?:js|jsx)$!i', $build_files ) ) ) { 730 730 // Finally, just grab whatever js/css files there are in the current directory. 731 $build_files += Filesystem::list_files( "$base_dir/$block_dir", false, '#(?<!webpack\.config)\.(?:js|jsx|css)$#i' );731 $build_files += Filesystem::list_files( "$base_dir/$block_dir", true, '#(?<!webpack\.config)\.(?:js|jsx|css)$#i' ); 732 732 } 733 733 } 734 734 -
shortcodes/class-block-validator.php
297 297 ]; 298 298 case 'check_for_block_json': 299 299 return __( 'Your plugin should contain at least one <code>block.json</code> file. This file contains metadata describing the block and its JavaScript and CSS assets. Make sure you include at least one <code>script</code> or <code>editorScript</code> item.', 'wporg-plugins' ); 300 case 'check_block_assets': 301 if ( count( $result->data ) > 0 ) { 302 return $result->data; 303 } 304 return __( 'The checker was not able to find any files for this type of asset.', 'wporg-plugins' ); 300 305 case 'check_for_block_script_files': 301 306 return [ 302 307 __( 'The value of <code>script</code>, <code>style</code>, <code>editorScript</code>, <code>editorStyle</code> must be a valid file path. This value was detected, but there is no file at this location in your plugin.', 'wporg-plugins' ),