-
Notifications
You must be signed in to change notification settings - Fork 4.9k
WP Scripts: Add a --root-folder argument to the plugin-zip command
#61375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
e5ffad2
0c59cbe
f720100
c9ddd8d
84e28f8
5f5054b
d4fe8f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,16 @@ const { stdout } = require( 'process' ); | |
| /** | ||
| * Internal dependencies | ||
| */ | ||
| const { hasPackageProp, getPackageProp } = require( '../utils' ); | ||
| const { hasPackageProp, getPackageProp, getArgFromCLI } = require( '../utils' ); | ||
|
|
||
| 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 = []; | ||
|
|
||
| if ( hasPackageProp( 'files' ) ) { | ||
| stdout.write( | ||
| 'Using the `files` field from `package.json` to detect files:\n\n' | ||
|
|
@@ -47,10 +50,30 @@ if ( hasPackageProp( 'files' ) ) { | |
| ); | ||
| } | ||
|
|
||
| if ( noRootFolderArg !== undefined ) { | ||
| zipRootFolder = ''; | ||
| stdout.write( 'Plugin files will be zipped without a root folder.\n\n' ); | ||
|
nicolasgalvez marked this conversation as resolved.
Outdated
|
||
| } else if ( zipRootFolderArg !== undefined ) { | ||
| const trimmedZipRootFolderArg = | ||
| typeof zipRootFolderArg === 'string' ? zipRootFolderArg.trim() : null; | ||
| if ( trimmedZipRootFolderArg === null ) { | ||
| stdout.write( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this could use some formatting to better indicate that the param was misconfigured and the zip wasn't created.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the message to Unable to create zip package: please provide a |
||
| 'Please provide a `--root-folder` name or use `--no-root-folder.`\n\n' | ||
|
nicolasgalvez marked this conversation as resolved.
Outdated
|
||
| ); | ||
| process.exit( 1 ); | ||
| } | ||
| zipRootFolder = `${ trimmedZipRootFolderArg }/`; | ||
| stdout.write( | ||
| `Adding the provided folder \`${ zipRootFolder }\` to the root of the package.\n\n` | ||
|
nicolasgalvez marked this conversation as resolved.
Outdated
|
||
| ); | ||
| } | ||
| files.forEach( ( file ) => { | ||
| stdout.write( ` Adding \`${ file }\`.\n` ); | ||
| const zipDirectory = dirname( file ); | ||
| zip.addLocalFile( file, zipDirectory !== '.' ? zipDirectory : '' ); | ||
| zip.addLocalFile( | ||
| file, | ||
| zipRootFolder + ( zipDirectory !== '.' ? zipDirectory : '' ) | ||
| ); | ||
| } ); | ||
|
|
||
| zip.writeZip( `./${ name }.zip` ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.