|
96 | 96 | } |
97 | 97 | } |
98 | 98 |
|
99 | | - if ( 'zip' === $assoc_args['format'] ) { |
100 | | - if ( is_null( $archive_file ) ) { |
101 | | - $archive_file = dirname( $path ) . '/' . $archive_base . $version . '.zip'; |
| 99 | + if ( is_null( $archive_file ) ) { |
| 100 | + $archive_file = dirname( $path ) . '/' . $archive_base . $version; |
| 101 | + if ( 'zip' === $assoc_args['format'] ) { |
| 102 | + $archive_file .= '.zip'; |
| 103 | + } else if ( 'targz' === $assoc_args['format'] ) { |
| 104 | + $archive_file .= '.tar.gz'; |
102 | 105 | } |
| 106 | + } |
| 107 | + |
| 108 | + chdir( dirname( $path ) ); |
| 109 | + |
| 110 | + if ( 'zip' === $assoc_args['format'] ) { |
103 | 111 | $excludes = implode( ' --exclude ', $ignored_files ); |
104 | 112 | if ( ! empty( $excludes ) ) { |
105 | 113 | $excludes = ' --exclude ' . $excludes; |
106 | 114 | } |
107 | | - chdir( dirname( $path ) ); |
108 | 115 | $cmd = "zip -r {$archive_file} {$archive_base} {$excludes}"; |
109 | | - WP_CLI::debug( "Running: {$cmd}", 'dist-archive' ); |
110 | | - $ret = WP_CLI::launch( escapeshellcmd( $cmd ), false, true ); |
111 | | - if ( 0 === $ret->return_code ) { |
112 | | - $filename = pathinfo( $archive_file, PATHINFO_BASENAME ); |
113 | | - WP_CLI::success( "Created {$filename}" ); |
114 | | - } else { |
115 | | - $error = $ret->stderr ? $ret->stderr : $ret->stdout; |
116 | | - WP_CLI::error( $error ); |
117 | | - } |
| 116 | + } else if ( 'targz' === $assoc_args['format'] ) { |
| 117 | + $excludes = array_map( function( $ignored_file ){ |
| 118 | + if ( '/*' === substr( $ignored_file, -2 ) ) { |
| 119 | + $ignored_file = substr( $ignored_file, 0, ( strlen( $ignored_file ) - 2 ) ); |
| 120 | + } |
| 121 | + return "--exclude='{$ignored_file}'"; |
| 122 | + }, $ignored_files ); |
| 123 | + $excludes = implode( ' ', $excludes ); |
| 124 | + $cmd = "tar {$excludes} -zcvf {$archive_file} {$archive_base}"; |
| 125 | + } |
| 126 | + |
| 127 | + WP_CLI::debug( "Running: {$cmd}", 'dist-archive' ); |
| 128 | + $ret = WP_CLI::launch( escapeshellcmd( $cmd ), false, true ); |
| 129 | + if ( 0 === $ret->return_code ) { |
| 130 | + $filename = pathinfo( $archive_file, PATHINFO_BASENAME ); |
| 131 | + WP_CLI::success( "Created {$filename}" ); |
| 132 | + } else { |
| 133 | + $error = $ret->stderr ? $ret->stderr : $ret->stdout; |
| 134 | + WP_CLI::error( $error ); |
118 | 135 | } |
119 | 136 |
|
120 | 137 | }; |
|
0 commit comments