From 3e4cb8d6990fc41d0bc7570286585f4aa2d4822a Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sat, 18 Jul 2026 13:40:17 +0800 Subject: [PATCH] feat(post-encrypt): add elapsed time and scanned file count to output --- packages/post-encrypt/src/index.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/post-encrypt/src/index.ts b/packages/post-encrypt/src/index.ts index d6feecae..87baca0b 100644 --- a/packages/post-encrypt/src/index.ts +++ b/packages/post-encrypt/src/index.ts @@ -3,6 +3,7 @@ import { Buffer } from 'node:buffer' import { createCipheriv, pbkdf2Sync, randomBytes } from 'node:crypto' import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs' import path from 'node:path' +import { performance } from 'node:perf_hooks' import process from 'node:process' import consola from 'consola' @@ -261,6 +262,13 @@ function hasUnencryptedTemplate(matches: TemplateMatch[]): boolean { }) } +function formatElapsed(ms: number): string { + if (ms < 1000) { + return `${Math.round(ms)}ms` + } + return `${(ms / 1000).toFixed(2)}s` +} + function main() { const options = parseArgs(process.argv.slice(2)) if (options.helpRequested) { @@ -271,6 +279,8 @@ function main() { ? options.input : path.resolve(options.cwd, options.input) + const startTime = performance.now() + let htmlFiles: string[] = [] try { htmlFiles = collectHtmlFiles(targetDir) @@ -310,31 +320,34 @@ function main() { } } + const elapsed = formatElapsed(performance.now() - startTime) + const scanned = `${htmlFiles.length} files scanned` + if (options.verifyOnly) { if (unencryptedFiles > 0) { - consola.warn(`Verification failed: ${unencryptedFiles} HTML files still contain unencrypted templates`) + consola.warn(`Verification failed: ${unencryptedFiles} HTML files still contain unencrypted templates (${scanned}, ${elapsed})`) process.exit(1) } if (totalTemplates === 0) { - consola.info('No encryption templates found.') + consola.info(`No encryption templates found. (${scanned}, ${elapsed})`) } else { - consola.info(`Verification passed: all ${totalTemplates} encryption templates use ${AES_MARKER}`) + consola.info(`Verification passed: all ${totalTemplates} encryption templates use ${AES_MARKER} (${scanned}, ${elapsed})`) } return } if (changedFiles === 0) { - consola.info('No encryption templates found or all already encrypted.') + consola.info(`No encryption templates found or all already encrypted. (${scanned}, ${elapsed})`) return } if (options.dryRun) { - consola.info(`Dry run complete: ${changedFiles} HTML files would be updated (${AES_MARKER})`) + consola.info(`Dry run complete: ${changedFiles} HTML files would be updated (${AES_MARKER}) (${scanned}, ${elapsed})`) return } - consola.info(`Post-build encryption completed: ${changedFiles} HTML files updated (${AES_MARKER})`) + consola.info(`Post-build encryption completed: ${changedFiles} HTML files updated (${AES_MARKER}) (${scanned}, ${elapsed})`) } main()