-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Scripts: Add plugin-zip
command to create a zip file for a WordPress plugin
#37687
Merged
+184
−14
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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` ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea here, but could we have the
files
entry merge with the existing defaults? This would make it much easier to add a new directory/file without needing to also provide all of the defaults.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to check our existing configs but I remember one of the tools exposing
…
shortcut that brings all the default settings if you want to extend them. This should do the trick.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that exists already? That would be great to add to the docs in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not here, but it would be simple to replicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it as is for now. It's a bit tricky to handle with
files
because it is used also when publishing to npm. The good news is that when you setfiles
then you don't need to list files like readme, changelog, or license because they are always included. I figured out that we can't add any custom items infiles
because it would breaknpm publish
if someone is using it.