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

Update plugin building #1008

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
69 changes: 69 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
############
## VCS and Vendors
############
.git
.github
.wordpress-org
.husky
node_modules
vendor

############
## Helpers
############
bin
docs
tests
plugin-tests

############
## OSes
############
[Tt]humbs.db
[Dd]esktop.ini
*.DS_store
.DS_store?

############
## Tools and CS
############
build-cs
.editorconfig
.eslintrc.js
.nvmrc
.wp-env.json
composer.json
composer.lock
package.json
package-lock.json
phpcs.xml.dist
phpstan.neon.dist
phpunit.xml.dist
webpack.config.js

############
## Community Files
############
CODE_OF_CONDUCT.md
CONTRIBUTING.md
SECURITY.md
README.md

############
## Ignore Files
############
.distignore
.gitignore
.gitattributes

############
## Build directories
############
build
dist

############
## Standalone Plugin Files
############
modules/**/readme.txt
modules/**/.wordpress-org
37 changes: 0 additions & 37 deletions .gitattributes

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/deploy-dotorg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ jobs:
- name: npm install
run: npm ci
- name: Build assets
run: npm run build
run: npm run build-plugin
- name: WordPress plugin deploy
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: performance-lab
BUILD_DIR: build
- name: Upload release assets
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"readme": "./bin/plugin/cli.js readme",
"translations": "./bin/plugin/cli.js translations",
"build": "wp-scripts build",
"build-plugin": "wp-scripts build --env build=plugin",
"build-plugins": "./bin/plugin/cli.js build-plugins",
Comment on lines 31 to 33
Copy link
Member

Choose a reason for hiding this comment

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

This is confusing to me. What is the purpose of build-plugin and build? We already have build-plugins which is for the modules to be built into plugins (which can soon be removed). Do we really need build-plugin or can it be combined somehow? If not, let's use a different name that clarifies what this is for.

"test-plugins": "./bin/plugin/cli.js test-plugins",
"test-plugins-multisite": "./bin/plugin/cli.js test-plugins --sitetype=multi",
Expand Down
68 changes: 67 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
const fs = require( 'fs' );
const path = require( 'path' );
const WebpackBar = require( 'webpackbar' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
Expand Down Expand Up @@ -36,6 +37,25 @@ const assetDataTransformer = ( content, absoluteFrom ) => {
return `<?php return array('dependencies' => array(), 'version' => '${ version }');`;
};

/**
* Delete a file or directory.
*
* @param {string} _path The path to the file or directory.
*
* @return {void}
*/
const deleteFileOrDirectory = ( _path ) => {
try {
if ( fs.existsSync( _path ) ) {
fs.rmSync( _path, { recursive: true } );
}
} catch ( error ) {
// eslint-disable-next-line no-console
console.error( error );
process.exit( 1 );
}
};

const webVitals = () => {
const source = path.resolve( __dirname, 'node_modules/web-vitals' );
const destination = path.resolve(
Expand All @@ -45,6 +65,7 @@ const webVitals = () => {

return {
...sharedConfig,
name: 'web-vitals',
plugins: [
new CopyWebpackPlugin( {
patterns: [
Expand All @@ -70,4 +91,49 @@ const webVitals = () => {
};
};

module.exports = [ webVitals ];
/**
* Webpack configuration for building the plugin.
* Note: Only works with the `--env build=plugin` flag.
*
* @param {*} env Webpack environment
* @return {Object} Webpack configuration
*/
const buildPlugin = ( env ) => {
if ( 'plugin' !== env.build ) {
return {
entry: {},
output: {},
};
}

const to = path.resolve( __dirname, 'build' );

// Delete the build directory if it exists.
deleteFileOrDirectory( to );

return {
...sharedConfig,
name: 'build-plugin',
plugins: [
new CopyWebpackPlugin( {
patterns: [
{
from: path.resolve( __dirname ),
to,
globOptions: {
dot: true,
ignoreFiles: '.distignore',
},
},
],
} ),
new WebpackBar( {
name: 'Plugin Distribution Build',
color: '#2393c1',
} ),
],
dependencies: [ 'web-vitals' ],
};
};

module.exports = [ webVitals, buildPlugin ];
Loading