Skip to content

Commit 499ae93

Browse files
Merge pull request #7 from runcommand/arbitrary-path
Support specifying a custom artifact path
2 parents a337d6a + 719c20f commit 499ae93

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contr
1010
## Using
1111

1212
~~~
13-
wp dist-archive <path> [--format=<format>]
13+
wp dist-archive <path> [<target>] [--format=<format>]
1414
~~~
1515

1616
For a plugin in a directory 'wp-content/plugins/hello-world', this command
@@ -36,6 +36,9 @@ script in each project.
3636
<path>
3737
Path to the project that includes a .distignore file.
3838

39+
[<target>]
40+
Path and file name for the distribution archive. Defaults to project directory name plus version, if discoverable.
41+
3942
[--format=<format>]
4043
Choose the format for the archive.
4144
---

command.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
* <path>
3131
* : Path to the project that includes a .distignore file.
3232
*
33+
* [<target>]
34+
* : Path and file name for the distribution archive. Defaults to project directory name plus version, if discoverable.
35+
*
3336
* [--format=<format>]
3437
* : Choose the format for the archive.
3538
* ---
@@ -44,6 +47,15 @@
4447
$dist_archive_command = function( $args, $assoc_args ) {
4548

4649
list( $path ) = $args;
50+
if ( isset( $args[1] ) ) {
51+
$archive_file = $args[1];
52+
$info = pathinfo( $archive_file );
53+
if ( '.' === $info['dirname'] ) {
54+
$archive_file = getcwd() . '/' . $info['basename'];
55+
}
56+
} else {
57+
$archive_file = null;
58+
}
4759
$path = rtrim( realpath( $path ), '/' );
4860
if ( ! is_dir( $path ) ) {
4961
WP_CLI::error( 'Provided path is not a directory.' );
@@ -78,7 +90,9 @@
7890
}
7991

8092
if ( 'zip' === $assoc_args['format'] ) {
81-
$archive_file = $archive_base . $version . '.zip';
93+
if ( is_null( $archive_file ) ) {
94+
$archive_file = dirname( $path ) . '/' . $archive_base . $version . '.zip';
95+
}
8296
$excludes = implode( ' --exclude ', $ignored_files );
8397
if ( ! empty( $excludes ) ) {
8498
$excludes = ' --exclude ' . $excludes;
@@ -88,7 +102,8 @@
88102
WP_CLI::debug( "Running: {$cmd}", 'dist-archive' );
89103
$ret = WP_CLI::launch( escapeshellcmd( $cmd ), false, true );
90104
if ( 0 === $ret->return_code ) {
91-
WP_CLI::success( "Created {$archive_file}" );
105+
$filename = pathinfo( $archive_file, PATHINFO_BASENAME );
106+
WP_CLI::success( "Created {$filename}" );
92107
} else {
93108
$error = $ret->stderr ? $ret->stderr : $ret->stdout;
94109
WP_CLI::error( $error );

features/dist-archive.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ Feature: Generate a distribution archive of a project
2020
And the wp-content/plugins/hello-world/hello-world.php file should exist
2121
And the wp-content/plugins/hello-world/.travis.yml file should not exist
2222
And the wp-content/plugins/hello-world/bin directory should not exist
23+
24+
Scenario: Generate a ZIP archive to a custom path
25+
Given a WP install
26+
27+
When I run `wp scaffold plugin hello-world`
28+
Then the wp-content/plugins/hello-world directory should exist
29+
And the wp-content/plugins/hello-world/hello-world.php file should exist
30+
And the wp-content/plugins/hello-world/.travis.yml file should exist
31+
And the wp-content/plugins/hello-world/bin directory should exist
32+
33+
When I run `wp dist-archive wp-content/plugins/hello-world hello-world.zip`
34+
Then STDOUT should be:
35+
"""
36+
Success: Created hello-world.zip
37+
"""
38+
And the hello-world.zip file should exist
39+
And the wp-content/plugins/hello-world.0.1.0.zip file should not exist

0 commit comments

Comments
 (0)