Making WordPress.org

Changeset 9119


Ignore:
Timestamp:
08/28/2019 09:12:29 AM (5 years ago)
Author:
tellyworth
Message:

Plugin directory: guess more block asset files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r9052 r9119  
    443443        // Find blocks
    444444        $blocks = array();
     445        $files_with_blocks = array();
    445446        foreach ( Filesystem::list_files( "$tmp_dir/export/", true /* recursive */, '!\.(?:php|js|jsx|json)$!i' ) as $filename ) {
    446447            $file_blocks = $this->find_blocks_in_file( $filename );
    447448            if ( $file_blocks ) {
     449                $files_with_blocks[] = str_replace( "$tmp_dir/export/", '', $filename );
    448450                foreach ( $file_blocks as $block ) {
    449451                    // If the info came from a block.json file with more metadata (like description) then we want it to override less detailed info scraped from php/js.
     
    461463
    462464        foreach ( $dist_files as $file ) {
    463             #$block_files[] = 'https://plugins.svn.wordpress.org' . "/{$plugin_slug}/trunk/dist/" . $file;
    464465            $block_files[] = '/trunk/dist/' . $file;
    465466        }
    466467
    467468        foreach ( $build_files as $file ) {
    468             #$block_files[] = 'https://plugins.svn.wordpress.org' . "/{$plugin_slug}/trunk/build/" . $file;
    469469            $block_files[] = '/trunk/build/' . $file;
    470470        }
     471
     472        if ( empty( $block_files ) ) {
     473            foreach ( $files_with_blocks as $file ) {
     474                $block_files[] = '/trunk/' . $file;
     475            }
     476        }
     477
     478        // Only allow js or css files
     479        $block_files = array_unique( array_filter( $block_files, function( $filename ) {
     480            return preg_match( '!\.(?:js|jsx|css)$!i', $filename );
     481        } ) );
    471482
    472483        return compact( 'readme', 'stable_tag', 'tmp_dir', 'plugin_headers', 'assets', 'tagged_versions', 'blocks', 'block_files' );
Note: See TracChangeset for help on using the changeset viewer.