-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91e6a31
commit b4c1144
Showing
19 changed files
with
680 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -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 ); | ||
} |
Oops, something went wrong.