misc: convert all internal scripts to ESM (#6286)

* misc: convert all internal scripts to ESM

* fixes

* fix

* fixes

* fix!

* complete eslint

* more move

* fix!

* This looks better?

* Final ones
This commit is contained in:
Joshua Chen 2022-01-08 12:59:28 +08:00 committed by GitHub
parent bcc05e243f
commit 4fad1ce0cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 412 additions and 374 deletions

View file

@ -5,26 +5,26 @@
* LICENSE file in the root directory of this source tree.
*/
// eslint-disable-next-line import/no-extraneous-dependencies
/* eslint-disable import/no-extraneous-dependencies */
import sharp from 'sharp';
import fs from 'fs/promises';
import fs from 'fs-extra';
import path from 'path';
// eslint-disable-next-line import/no-extraneous-dependencies
import imageSize from 'image-size';
import {fileURLToPath} from 'url';
const allImages = (
await fs.readdir(new URL('../../website/src/data/showcase', import.meta.url))
).filter((file) => ['.png', 'jpg', '.jpeg'].includes(path.extname(file)));
const [,,...selectedImages] = process.argv;
const [, , ...selectedImages] = process.argv;
const images = selectedImages.length > 0 ? selectedImages : allImages;
await Promise.all(
images.map(async (img) => {
const imgPath = new URL(
`../../website/src/data/showcase/${img}`,
import.meta.url,
).pathname;
const imgPath = fileURLToPath(
new URL(`../../website/src/data/showcase/${img}`, import.meta.url),
);
const {width, height} = imageSize(imgPath);
if (width === 640 && height === 320) {
// Do not emit if no resized. Important because we