-
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
- 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
"@wordpress/postcss-plugins-preset": "file:../postcss-plugins-preset", | ||
"@wordpress/prettier-config": "file:../prettier-config", | ||
"@wordpress/stylelint-config": "file:../stylelint-config", | ||
"adm-zip": "^0.5.9", | ||
"babel-jest": "^26.6.3", | ||
"babel-loader": "^8.2.3", | ||
"browserslist": "^4.17.6", | ||
|
@@ -70,6 +71,7 @@ | |
"mini-css-extract-plugin": "^2.1.0", | ||
"minimist": "^1.2.0", | ||
"npm-package-json-lint": "^5.0.0", | ||
"npm-packlist": "^3.0.0", | ||
"postcss": "^8.2.15", | ||
"postcss-loader": "^6.1.1", | ||
"prettier": "npm:[email protected]", | ||
|
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` ); |