Skip to content
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

Add zip-plugin-builds command #1228

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bin/webpack/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require( 'fs' );
const path = require( 'path' );
const { execSync } = require( 'child_process' );

/**
* Return plugin root path.
Expand Down Expand Up @@ -97,10 +98,24 @@
return `<?php return array('dependencies' => array(), 'version' => '${ version }');`;
};

/**
* Create plugins zip file using `zip` command.
*
* @param {string} pluginPath The path where the plugin build is located.
* @param {string} pluginName The name of the plugin.
*
* @return {void}
*/
const createPluginZip = ( pluginPath, pluginName ) => {
const command = `cd ${ pluginPath } && zip -r ${ pluginName }.zip ${ pluginName }`;
execSync( command );
Fixed Show fixed Hide fixed
};

module.exports = {
getPluginRootPath,
deleteFileOrDirectory,
getPluginVersion,
generateBuildManifest,
assetDataTransformer,
createPluginZip,
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"versions": "./bin/plugin/cli.js versions",
"build": "wp-scripts build",
"build-plugins": "npm-run-all 'build:plugin:!(performance-lab)'",
"build:plugin:performance-lab": "rm -rf build/performance-lab && mkdir -p build/performance-lab && git archive HEAD | tar -x -C build/performance-lab",
"build-plugins:zip": "npm-run-all 'build:plugin:!(performance-lab) --env zip=true' 'build:plugin:performance-lab'",
"build:plugin:performance-lab": "rm -rf build/performance-lab && mkdir -p build/performance-lab && git archive HEAD | tar -x -C build/performance-lab && cd build && zip -qr performance-lab.zip performance-lab",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Remove it once #1182 is merged.

"build:plugin:auto-sizes": "webpack --mode production --env plugin=auto-sizes",
"build:plugin:dominant-color-images": "webpack --mode production --env plugin=dominant-color-images",
"build:plugin:embed-optimizer": "webpack --mode production --env plugin=embed-optimizer",
Expand Down
9 changes: 8 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
*/
const { plugins: standalonePlugins } = require( './plugins.json' );
const {
createPluginZip,
assetDataTransformer,
deleteFileOrDirectory,
generateBuildManifest,
Expand Down Expand Up @@ -102,7 +103,8 @@ const buildPlugin = ( env ) => {
};
}

const to = path.resolve( __dirname, 'build', env.plugin );
const buildDir = path.resolve( __dirname, 'build' );
const to = path.resolve( buildDir, env.plugin );
const from = path.resolve( __dirname, 'plugins', env.plugin );
const dependencies = pluginsWithBuild.includes( env.plugin )
? [ `${ env.plugin }` ]
Expand Down Expand Up @@ -138,6 +140,11 @@ const buildPlugin = ( env ) => {
// After emit, generate build manifest.
compiler.hooks.afterEmit.tap( 'AfterEmitPlugin', () => {
generateBuildManifest( env.plugin, from );

// If zip flag is passed, create a zip file.
if ( env.zip ) {
createPluginZip( buildDir, env.plugin );
}
} );
},
},
Expand Down