Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions src/output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { copyFile, writeFile } from 'node:fs/promises'
import { join, relative } from 'node:path'
import { copyFile, mkdir, writeFile } from 'node:fs/promises'
import { dirname, join, relative } from 'node:path'

import { logger } from './logger'

Expand Down Expand Up @@ -96,7 +96,12 @@ export const outputAssets = async (dest: string, assets: Map<string, string>): P
logger.log(`skipped copy '${name}' with same content`)
return
}
await copyFile(from, join(dest, name))
const destPath = join(dest, name)
const destDir = dirname(destPath)
if (destDir !== dest) {
await mkdir(destDir, { recursive: true })
}
await copyFile(from, destPath)
// logger.log(`copied '${name}' from '${from}'`)
emitted.set(name, from)
count++
Expand Down
19 changes: 12 additions & 7 deletions src/schemas/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ export interface ImageOptions {
* @default undefined
*/
absoluteRoot?: string
// /**
// * allow remote url
// * @default false
// */
// allowRemoteUrl?: boolean
/**
* Custom output name template for the asset
* Supports placeholders: [name], [hash], [hash:N], [ext]
* Can include subdirectories (e.g., 'logos/[name]-[hash:6].[ext]')
* @default undefined (uses global output.name from config)
* @example 'logo-[name]-[hash:6].[ext]'
* @example 'logos/[name]-[hash:6].[ext]'
*/
outputName?: string
}

/**
* Image schema
*/
export const image = ({ absoluteRoot }: ImageOptions = {}) =>
export const image = ({ absoluteRoot, outputName }: ImageOptions = {}) =>
string().transform<Image>(async (value, { meta, addIssue }) => {
try {
if (absoluteRoot && /^\//.test(value)) {
Expand All @@ -44,7 +48,8 @@ export const image = ({ absoluteRoot }: ImageOptions = {}) =>

const { output } = meta.config
// process asset as relative path
return await processAsset(value, meta.path, output.name, output.base, true)
const assetName = outputName ?? output.name
return await processAsset(value, meta.path, assetName, output.base, true)
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
addIssue({ fatal: true, code: 'custom', message })
Expand Down