Skip to content

Commit

Permalink
Convert to import statements, see #1465
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 14, 2024
1 parent db8a93a commit 86e0387
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
12 changes: 5 additions & 7 deletions js/grunt/generateThumbnails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

import * as grunt from 'grunt';
import IntentionalAny from '../../../phet-core/js/types/IntentionalAny.js';

// modules
const jimp = require( 'jimp' );
import Jimp from 'jimp';

/**
* @param repo - name of the repository
Expand All @@ -24,7 +22,7 @@ const jimp = require( 'jimp' );
* @param altSuffix - ending for the filename e.g. -alt1
* @returns Resolves to a {Buffer} with the image data
*/
module.exports = function( repo: string, width: number, height: number, quality: number, mime: string, altSuffix: string ): Promise<Buffer> {
export default function( repo: string, width: number, height: number, quality: number, mime: string, altSuffix: string | undefined = undefined ): Promise<Buffer> {
return new Promise( ( resolve, reject ) => {
const fullResImageName = `../${repo}/assets/${repo}-screenshot${altSuffix || ''}.png`;

Expand All @@ -33,8 +31,8 @@ module.exports = function( repo: string, width: number, height: number, quality:
return;
}

new jimp( fullResImageName, function( this: IntentionalAny ) { // eslint-disable-line no-new
if ( mime === jimp.MIME_JPEG ) {
new Jimp( fullResImageName, function( this: IntentionalAny ) { // eslint-disable-line no-new
if ( mime === Jimp.MIME_JPEG ) {
this.quality( quality );
}
this.resize( width, height ).getBuffer( mime, ( error: string, buffer: Buffer ) => {
Expand All @@ -47,4 +45,4 @@ module.exports = function( repo: string, width: number, height: number, quality:
} );
} );
} );
};
}
7 changes: 3 additions & 4 deletions js/grunt/generateTwitterCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
// modules
import IntentionalAny from '../../../phet-core/js/types/IntentionalAny.js';
import * as grunt from 'grunt';

const Jimp = require( 'jimp' ); // eslint-disable-line phet/require-statement-match
import Jimp from 'jimp';

/**
* @param repo - name of the repository
* @returns - Resolves with a PNG {Buffer}
*/
module.exports = function( repo: string ): Promise<Buffer> {
export default function( repo: string ): Promise<Buffer> {
return new Promise( ( resolve, reject ) => {
const fullResImageName = `../${repo}/assets/${repo}-screenshot.png`;

Expand All @@ -42,4 +41,4 @@ module.exports = function( repo: string ): Promise<Buffer> {
} );
} );
} );
};
}
16 changes: 7 additions & 9 deletions js/grunt/tasks/build-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
*/
import * as grunt from 'grunt';
import getRepo from '../../../../perennial-alias/js/grunt/tasks/util/getRepo';

const jimp = require( 'jimp' );

const generateThumbnails = require( '../generateThumbnails' );
const generateTwitterCard = require( '../generateTwitterCard' );
import Jimp from 'jimp';
import generateThumbnails from '../generateThumbnails';
import generateTwitterCard from '../generateTwitterCard';

const brand = 'phet';

Expand All @@ -29,18 +27,18 @@ const repo = getRepo();
{ width: 15, height: 10 }
];
for ( const size of thumbnailSizes ) {
grunt.file.write( `${buildDir}/${repo}-${size.width}.png`, await generateThumbnails( repo, size.width, size.height, 100, jimp.MIME_PNG ) );
grunt.file.write( `${buildDir}/${repo}-${size.width}.png`, await generateThumbnails( repo, size.width, size.height, 100, Jimp.MIME_PNG ) );
}

const altScreenshots = grunt.file.expand( { filter: 'isFile', cwd: `../${repo}/assets` }, [ `./${repo}-screenshot-alt[0123456789].png` ] );
for ( const altScreenshot of altScreenshots ) {
const imageNumber = Number( altScreenshot.substr( `./${repo}-screenshot-alt`.length, 1 ) );
grunt.file.write( `${buildDir}/${repo}-${600}-alt${imageNumber}.png`, await generateThumbnails( repo, 600, 394, 100, jimp.MIME_PNG, `-alt${imageNumber}` ) );
grunt.file.write( `${buildDir}/${repo}-${900}-alt${imageNumber}.png`, await generateThumbnails( repo, 900, 591, 100, jimp.MIME_PNG, `-alt${imageNumber}` ) );
grunt.file.write( `${buildDir}/${repo}-${600}-alt${imageNumber}.png`, await generateThumbnails( repo, 600, 394, 100, Jimp.MIME_PNG, `-alt${imageNumber}` ) );
grunt.file.write( `${buildDir}/${repo}-${900}-alt${imageNumber}.png`, await generateThumbnails( repo, 900, 591, 100, Jimp.MIME_PNG, `-alt${imageNumber}` ) );
}

if ( brand === 'phet' ) {
grunt.file.write( `${buildDir}/${repo}-ios.png`, await generateThumbnails( repo, 420, 276, 90, jimp.MIME_JPEG ) );
grunt.file.write( `${buildDir}/${repo}-ios.png`, await generateThumbnails( repo, 420, 276, 90, Jimp.MIME_JPEG ) );
grunt.file.write( `${buildDir}/${repo}-twitter-card.png`, await generateTwitterCard( repo ) );
}
}
Expand Down

0 comments on commit 86e0387

Please sign in to comment.