-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts: Add
plugin-zip
command to create a zip file for a WordPres…
…s plugin (#37687)
- Loading branch information
Showing
9 changed files
with
184 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const AdmZip = require( 'adm-zip' ); | ||
const { sync: glob } = require( 'fast-glob' ); | ||
const { sync: packlist } = require( 'npm-packlist' ); | ||
const { dirname } = require( 'path' ); | ||
const { stdout } = require( 'process' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { hasPackageProp, getPackageProp } = require( '../utils' ); | ||
|
||
const name = getPackageProp( 'name' ); | ||
stdout.write( `Creating archive for \`${ name }\` plugin... 🎁\n\n` ); | ||
const zip = new AdmZip(); | ||
|
||
let files = []; | ||
if ( hasPackageProp( 'files' ) ) { | ||
stdout.write( | ||
'Using the `files` field from `package.json` to detect files:\n\n' | ||
); | ||
files = packlist(); | ||
} else { | ||
stdout.write( | ||
'Using Plugin Handbook best practices to discover files:\n\n' | ||
); | ||
// See https://developer.wordpress.org/plugins/plugin-basics/best-practices/#file-organization. | ||
files = glob( | ||
[ | ||
'admin/**', | ||
'build/**', | ||
'includes/**', | ||
'languages/**', | ||
'public/**', | ||
`${ name }.php`, | ||
'uninstall.php', | ||
'block.json', | ||
'changelog.*', | ||
'license.*', | ||
'readme.*', | ||
], | ||
{ | ||
caseSensitiveMatch: false, | ||
} | ||
); | ||
} | ||
|
||
files.forEach( ( file ) => { | ||
stdout.write( ` Adding \`${ file }\`.\n` ); | ||
zip.addLocalFile( file, dirname( file ) ); | ||
} ); | ||
|
||
zip.writeZip( `./${ name }.zip` ); | ||
stdout.write( `\nDone. \`${ name }.zip\` is ready! 🎉\n` ); |