const fg = require('fast-glob'); import * as path from 'path'; import * as bluebird from 'bluebird'; export { sync as read } from '@plastichub/fs/read'; export { sync as exists } from '@plastichub/fs/exists'; export { sync as dir } from '@plastichub/fs/dir'; export { sync as write } from '@plastichub/fs/write'; import { Helper } from '../process/index'; const IMAGES_GLOB = '*.+(JPG|jpg|png|PNG|gif)'; export const files = (dir, glob) => fg.sync(glob, { dot: true, cwd: dir, absolute: true }) as []; export const images = (source) => files(source, IMAGES_GLOB) as any[]; export const forward_slash = (path) => { const isExtendedLengthPath = /^\\\\\?\\/.test(path); const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex if (isExtendedLengthPath || hasNonAscii) { return path; } return path.replace(/\\/g, '/'); }; export async function resize_images(files) { return bluebird.mapSeries(files, (file: string) => { const inParts = path.parse(file); const promise = Helper.run(inParts.dir, 'convert', [ `"${inParts.base}"`, '-quality 70', '-resize 1980', '-sharpen 0x1.0', `"${inParts.name}${inParts.ext}"` ]); return promise; }); }