[ci] format

This commit is contained in:
tony-sull 2022-08-22 19:15:35 +00:00 committed by fredkbot
parent c4af8723bd
commit 2c40fba0c8
3 changed files with 36 additions and 12 deletions

View file

@ -1,12 +1,12 @@
import { bgGreen, black, cyan, dim, green, bold } from 'kleur/colors'; import { bgGreen, black, cyan, dim, green } from 'kleur/colors';
import fs from 'node:fs/promises'; import fs from 'node:fs/promises';
import path from 'node:path'; import path from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { OUTPUT_DIR } from '../constants.js'; import { OUTPUT_DIR } from '../constants.js';
import type { SSRImageService, TransformOptions } from '../loaders/index.js'; import type { SSRImageService, TransformOptions } from '../loaders/index.js';
import { isRemoteImage, loadLocalImage, loadRemoteImage } from '../utils/images.js'; import { isRemoteImage, loadLocalImage, loadRemoteImage } from '../utils/images.js';
import { debug, info, LoggerLevel, warn } from '../utils/logger.js';
import { ensureDir } from '../utils/paths.js'; import { ensureDir } from '../utils/paths.js';
import { debug, info, warn, LoggerLevel } from '../utils/logger.js';
function getTimeStat(timeStart: number, timeEnd: number) { function getTimeStat(timeStart: number, timeEnd: number) {
const buildTime = timeEnd - timeStart; const buildTime = timeEnd - timeStart;
@ -24,7 +24,13 @@ export interface SSGBuildParams {
export async function ssgBuild({ loader, staticImages, srcDir, outDir, logLevel }: SSGBuildParams) { export async function ssgBuild({ loader, staticImages, srcDir, outDir, logLevel }: SSGBuildParams) {
const timer = performance.now(); const timer = performance.now();
info({ level: logLevel, prefix: false, message: `${bgGreen(black(` optimizing ${staticImages.size} image${staticImages.size > 1 ? 's' : ''} `))}` }); info({
level: logLevel,
prefix: false,
message: `${bgGreen(
black(` optimizing ${staticImages.size} image${staticImages.size > 1 ? 's' : ''} `)
)}`,
});
const inputFiles = new Set<string>(); const inputFiles = new Set<string>();
@ -65,7 +71,11 @@ export async function ssgBuild({ loader, staticImages, srcDir, outDir, logLevel
const timeChange = getTimeStat(timeStart, timeEnd); const timeChange = getTimeStat(timeStart, timeEnd);
const timeIncrease = `(+${timeChange})`; const timeIncrease = `(+${timeChange})`;
const pathRelative = inputFile.replace(fileURLToPath(srcDir), ''); const pathRelative = inputFile.replace(fileURLToPath(srcDir), '');
debug({ level: logLevel, prefix: false, message: ` ${cyan('└─')} ${dim(`(original) ${pathRelative}`)} ${dim(timeIncrease)}` }); debug({
level: logLevel,
prefix: false,
message: ` ${cyan('└─')} ${dim(`(original) ${pathRelative}`)} ${dim(timeIncrease)}`,
});
} }
// process each transformed versiono of the // process each transformed versiono of the
@ -91,9 +101,17 @@ export async function ssgBuild({ loader, staticImages, srcDir, outDir, logLevel
const timeChange = getTimeStat(timeStart, timeEnd); const timeChange = getTimeStat(timeStart, timeEnd);
const timeIncrease = `(+${timeChange})`; const timeIncrease = `(+${timeChange})`;
const pathRelative = outputFile.replace(fileURLToPath(outDir), ''); const pathRelative = outputFile.replace(fileURLToPath(outDir), '');
debug({ level: logLevel, prefix: false, message: ` ${cyan('└─')} ${dim(pathRelative)} ${dim(timeIncrease)}` }); debug({
level: logLevel,
prefix: false,
message: ` ${cyan('└─')} ${dim(pathRelative)} ${dim(timeIncrease)}`,
});
} }
} }
info({ level: logLevel, prefix: false, message: (dim(`Completed in ${getTimeStat(timer, performance.now())}.\n`)) }); info({
level: logLevel,
prefix: false,
message: dim(`Completed in ${getTimeStat(timer, performance.now())}.\n`),
});
} }

View file

@ -110,7 +110,13 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
const loader = globalThis?.astroImage?.loader; const loader = globalThis?.astroImage?.loader;
if (loader && 'transform' in loader && staticImages.size > 0) { if (loader && 'transform' in loader && staticImages.size > 0) {
await ssgBuild({ loader, staticImages, srcDir: _config.srcDir, outDir: dir, logLevel: resolvedOptions.logLevel }); await ssgBuild({
loader,
staticImages,
srcDir: _config.srcDir,
outDir: dir,
logLevel: resolvedOptions.logLevel,
});
} }
} }
}, },

View file

@ -60,15 +60,15 @@ function getPrefix(level: LoggerLevel, timestamp: boolean) {
return prefix; return prefix;
} }
const log = (_level: LoggerLevel, dest: (message: string) => void) => const log =
(_level: LoggerLevel, dest: (message: string) => void) =>
({ message, level, prefix = true, timestamp = true }: LogMessage) => { ({ message, level, prefix = true, timestamp = true }: LogMessage) => {
if (levels[_level] >= levels[level]) { if (levels[_level] >= levels[level]) {
dest(`${prefix ? getPrefix(level, timestamp) : ''}${message}`); dest(`${prefix ? getPrefix(level, timestamp) : ''}${message}`);
} }
} };
export const info = log('info', console.info); export const info = log('info', console.info);
export const debug = log('debug', console.debug); export const debug = log('debug', console.debug);
export const warn = log('warn', console.warn); export const warn = log('warn', console.warn);
export const error = log('error', console.error); export const error = log('error', console.error);