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

Compatibility with Node 16 #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions tasks/resize-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const fs = require('fs').promises
const debug = require('debug')('resize-images')
const { getCommunityMembersData } = require('./lib/data.js')

async function removeDir(dir) {
return typeof fs.rm === 'function'
// Introduced in Node 14.14.0
? fs.rm(dir, { recursive: true, force: true })
// The recursive option is deprecated, using it triggers a deprecation warning in Node 16
: fs.rmdir(dir, { recursive: true, force: true })
}

async function resizeImages(buildImagesDirectory, issueDate) {
try {
execSync(`"mogrify" "--version"`)
Expand All @@ -15,7 +23,7 @@ async function resizeImages(buildImagesDirectory, issueDate) {
}
const communityMemberJson = await getCommunityMembersData(issueDate)
const thumbsDirectory = ospath.join(buildImagesDirectory, 'thumbs')
await fs.rmdir(thumbsDirectory, { recursive: true, force: true })
await removeDir(thumbsDirectory)
const originalImages = await fs.readdir(buildImagesDirectory)
await fs.mkdir(thumbsDirectory)
execSync(`"mogrify" "-path" "thumbs/" "-thumbnail" "800x418>" ${originalImages.map(image => `"${image}"`).join(' ')}`, { cwd: buildImagesDirectory })
Expand All @@ -27,7 +35,7 @@ async function resizeImages(buildImagesDirectory, issueDate) {
await fs.copyFile(ospath.join(thumbsDirectory, image), ospath.join(buildImagesDirectory, image))
}
// cleanup
await fs.rmdir(thumbsDirectory, { recursive: true, force: true })
await removeDir(thumbsDirectory)
}

module.exports = {
Expand Down