Skip to content

Commit

Permalink
Scripts: Modify plugin-zip to add no-root-folder and root-folder options
Browse files Browse the repository at this point in the history
Require an argument for root-folder.
Add option no-root-folder to zip files without a root folder for backwards compatibility.
Update documentation, and changelog.
(WordPress#60481)
  • Loading branch information
nicolasgalvez committed Oct 26, 2024
1 parent c9ddd8d commit 84e28f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

### Enhancements

- Add BlueOak-1.0.0 the GPLv2-comatible licenses recognized by check-licenses ([#66139](https://github.com/WordPress/gutenberg/pull/66139)).
- Add an optional `--root-folder` argument to the `plugin-zip` command ([#61375](https://github.com/WordPress/gutenberg/pull/61375)). By default, the command will use the plugin's name as the root folder of the zip. If the change in the behavior impacted your workflow, you could pass `--root-folder=''` to remove the root folder.
- Add BlueOak-1.0.0 the GPLv2-compatible licenses recognized by check-licenses ([#66139](https://github.com/WordPress/gutenberg/pull/66139)).
- Add an optional `--root-folder` argument to the `plugin-zip` command ([#61375](https://github.com/WordPress/gutenberg/pull/61375)). By default, the command will use the plugin's name as the root folder of the zip. If the change in the behavior impacted your workflow, you could pass `--no-root-folder` to remove the root folder.

### Internal

Expand Down
6 changes: 3 additions & 3 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ It reuses the same logic as `npm pack` command to create an npm package tarball.
This is how you create a custom root folder inside the zip file.
- 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.
- `--root-folder` - Add a custom root folder to the zip file.
- `npm run plugin-zip` - By default, unzipping your plugin will result in a folder with the same name as your plugin.
- `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.
- `npm run plugin-zip --root-folder='custom-directory'` - Your plugin will be unzipped into a folder named `custom-directory`.
- `npm run plugin-zip` - By default, unzipping your plugin's zip file will result in a folder with the same name as your plugin.
- `npm run plugin-zip --root-folder='custom-directory'` - Your plugin's zip file will be unzipped into a folder named `custom-directory`.
- `npm run plugin-zip --no-root-folder` - This will create a zip file that has no folder inside, your plugin files will be unzipped directly into the target directory.

### `start`

Expand Down
21 changes: 12 additions & 9 deletions packages/scripts/scripts/plugin-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const name = getPackageProp( 'name' );
stdout.write( `Creating archive for \`${ name }\` plugin... 🎁\n\n` );
const zip = new AdmZip();
const zipRootFolderArg = getArgFromCLI( '--root-folder' );
const noRootFolderArg = getArgFromCLI( '--no-root-folder' );
let zipRootFolder = `${ name }/`;
let files = [];

Expand Down Expand Up @@ -49,20 +50,22 @@ if ( hasPackageProp( 'files' ) ) {
);
}

if ( zipRootFolderArg !== undefined ) {
if ( noRootFolderArg !== undefined ) {
zipRootFolder = '';
stdout.write( 'Plugin files will be zipped without a root folder.\n\n' );
} else if ( zipRootFolderArg !== undefined ) {
const trimmedZipRootFolderArg =
typeof zipRootFolderArg === 'string' ? zipRootFolderArg.trim() : null;
if ( ! trimmedZipRootFolderArg ) {
if ( trimmedZipRootFolderArg === null ) {
stdout.write(
'Plugin files will be zipped without a root folder.\n\n'
);
zipRootFolder = '';
} else {
zipRootFolder = `${ trimmedZipRootFolderArg }/`;
stdout.write(
`Adding the provided folder \`${ zipRootFolder }\` to the root of the package.\n\n`
'Please provide a `--root-folder` name or use `--no-root-folder.`\n\n'
);
process.exit( 1 );
}
zipRootFolder = `${ trimmedZipRootFolderArg }/`;
stdout.write(
`Adding the provided folder \`${ zipRootFolder }\` to the root of the package.\n\n`
);
}
files.forEach( ( file ) => {
stdout.write( ` Adding \`${ file }\`.\n` );
Expand Down

0 comments on commit 84e28f8

Please sign in to comment.