Skip to content

Commit

Permalink
feat: add wp-assets
Browse files Browse the repository at this point in the history
  • Loading branch information
dobaniashish committed Oct 4, 2024
1 parent 91e6a31 commit b4c1144
Show file tree
Hide file tree
Showing 19 changed files with 680 additions and 4 deletions.
Binary file added .wordpress/assets/banner-1544x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress/assets/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress/assets/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress/assets/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .wordpress/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress/assets/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress/assets/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress/assets/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress/assets/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions build-scripts/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,112 @@ const copyConfig = [
'editor.css.asset.php'
),
},

// WP assets.
{
source: path.resolve(
process.cwd(),
'dist/wp-assets/',
'banner-1544x500.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'banner-1544x500.png'
),
},
{
source: path.resolve(
process.cwd(),
'dist/wp-assets/',
'banner-772x250.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'banner-772x250.png'
),
},
{
source: path.resolve(
process.cwd(),
'dist/wp-assets/',
'icon-256x256.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'icon-256x256.png'
),
},
{
source: path.resolve(
process.cwd(),
'dist/wp-assets/',
'icon-128x128.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'icon-128x128.png'
),
},
{
source: path.resolve( process.cwd(), 'src/wp-assets/', 'icon.svg' ),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'icon.svg'
),
},
{
source: path.resolve(
process.cwd(),
'src/wp-assets/',
'screenshot-1.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'screenshot-1.png'
),
},
{
source: path.resolve(
process.cwd(),
'src/wp-assets/',
'screenshot-2.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'screenshot-2.png'
),
},
{
source: path.resolve(
process.cwd(),
'src/wp-assets/',
'screenshot-3.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'screenshot-3.png'
),
},
{
source: path.resolve(
process.cwd(),
'src/wp-assets/',
'screenshot-4.png'
),
destination: path.resolve(
process.cwd(),
'.wordpress/assets/',
'screenshot-4.png'
),
},
];

// Add Blocks Json.
Expand Down
78 changes: 78 additions & 0 deletions build-scripts/wp-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const fs = require( 'fs-extra' );
const path = require( 'path' );
const sharp = require( 'sharp' );

const sharpConfig = [
// Banner.
{
source: path.resolve( process.cwd(), 'src/wp-assets/', 'banner.svg' ),
destination: path.resolve( process.cwd(), 'dist/wp-assets/' ),
name: 'banner-1544x500',
format: 'png',
size: {
width: 1544,
height: 500,
},
},
{
source: path.resolve( process.cwd(), 'src/wp-assets/', 'banner.svg' ),
destination: path.resolve( process.cwd(), 'dist/wp-assets/' ),
name: 'banner-772x250',
format: 'png',
size: {
width: 772,
height: 250,
},
},

// Icon.
{
source: path.resolve( process.cwd(), 'src/wp-assets/', 'icon.svg' ),
destination: path.resolve( process.cwd(), 'dist/wp-assets/' ),
name: 'icon-256x256',
format: 'png',
size: {
width: 256,
height: 256,
},
},
{
source: path.resolve( process.cwd(), 'src/wp-assets/', 'icon.svg' ),
destination: path.resolve( process.cwd(), 'dist/wp-assets/' ),
name: 'icon-128x128',
format: 'png',
size: {
width: 128,
height: 128,
},
},
];

run();

async function run() {
// Compile less.
for ( const config of sharpConfig ) {
await generate( config );
}

console.log( `WP asset images generated.` );
}

async function generate( config ) {
const source = path.resolve( config.source );
const destination = path.resolve(
config.destination,
`${ config.name }.${ config.format }`
);

console.log( `Generating image ${ source } to ${ destination } ...` );

// Make dir if does not exist.
await fs.mkdir( path.dirname( destination ), { recursive: true } );

await sharp( source )
.resize( { width: config.width, height: config.height } )
.toFormat( config.format )
.toFile( destination );
}
Loading

0 comments on commit b4c1144

Please sign in to comment.