Skip to content

Commit 0c59cbe

Browse files
committed
Scripts: Change the plugin-zip command to add a folder in the plugin zip file by default
1. The plugin-zip command will now create a root folder in the zip file matching the name of the plugin. This aligns with the documentation stating that "By default, it uses Plugin Handbook best practices to discover files." 2. `--zip-root-folder` argument from my previous commit is now named `--root-folder` 3. The --root-folder argument will allow specifying a custom folder, or no folder for backwards compatibility. Example usage: {{{ npm run plugin-zip --root-folder='foo' }}} Follow-up to [61375], [60481]. Props justlevine, gziolo.
1 parent e5ffad2 commit 0c59cbe

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

packages/scripts/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,12 @@ In the case where the plugin author wants to customize the files included in the
378378

379379
It reuses the same logic as `npm pack` command to create an npm package tarball.
380380

381-
This is how you create a zip for use with a custom plugin update system
382-
383-
- `--zip-root-folder` - When updating a plugin, WordPress expects a folder in the root of the zip file which matches the plugin name. The `--zip-root-folder` parameter will create a folder in the root of the zip file that matches your plugin name instead of adding all files to the root.
384-
385-
- `npm run plugin-zip --zip-root-folder` - which will use your plugin name as the folder.
386-
- `npm run plugin-zip --zip-root-folder=plugin-name` - which will allow you to specify a plugin name.
381+
This is how you create a custom root folder inside the zip file.
382+
- When updating a plugin, WordPress expects a folder in the root of the zip file which matches the plugin name. So be aware that this may affect the plugin update process.
383+
- `--root-folder` - Add a custom root folder to the zip file.
384+
- `npm run plugin-zip` - By default, unzipping your plugin will result in a folder with the same name as your plugin.
385+
- `npm run plugin-zip --root-folder=''` - This will create a zip file that has no folder inside, your plugin files will be unzipped directly into the target directory.
386+
- `npm run plugin-zip --root-folder='custom-directory'` - Your plugin will be unzipped into a folder named `custom-directory`.
387387

388388
### `start`
389389

packages/scripts/scripts/plugin-zip.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const { hasPackageProp, getPackageProp, getArgFromCLI } = require( '../utils' );
1515
const name = getPackageProp( 'name' );
1616
stdout.write( `Creating archive for \`${ name }\` plugin... 🎁\n\n` );
1717
const zip = new AdmZip();
18-
const zipRootFolderArg = getArgFromCLI( '--zip-root-folder' );
19-
let zipRootFolder = null;
18+
const zipRootFolderArg = getArgFromCLI( '--root-folder' );
19+
let zipRootFolder = `${ name }/`;
2020
let files = [];
2121

2222
if ( hasPackageProp( 'files' ) ) {
@@ -50,21 +50,20 @@ if ( hasPackageProp( 'files' ) ) {
5050
}
5151

5252
if ( zipRootFolderArg !== undefined ) {
53-
if ( zipRootFolderArg === null ) {
53+
const trimmedZipRootFolderArg =
54+
typeof zipRootFolderArg === 'string' ? zipRootFolderArg.trim() : null;
55+
if ( ! trimmedZipRootFolderArg ) {
5456
stdout.write(
55-
'No value provided for `--zip-root-folder`. Using the plugin name as the root folder.\n\n'
57+
'Plugin files will be zipped without a root folder.\n\n'
5658
);
57-
zipRootFolder = `${ name }/`;
59+
zipRootFolder = '';
5860
} else {
59-
zipRootFolder = `${ zipRootFolderArg }/`;
61+
zipRootFolder = `${ trimmedZipRootFolderArg }/`;
62+
stdout.write(
63+
`Adding the provided folder \`${ zipRootFolder }\` to the root of the package.\n\n`
64+
);
6065
}
61-
stdout.write(
62-
`Adding the provided folder \`${ zipRootFolder }\` to the root of the package.\n\n`
63-
);
64-
} else {
65-
zipRootFolder = '';
6666
}
67-
6867
files.forEach( ( file ) => {
6968
stdout.write( ` Adding \`${ file }\`.\n` );
7069
const zipDirectory = dirname( file );

0 commit comments

Comments
 (0)