28 lines
777 B
JavaScript
28 lines
777 B
JavaScript
![]() |
import { z } from "zod";
|
||
|
import { emitESMImage } from "../assets/utils/emitAsset.js";
|
||
|
function createImage(pluginContext, entryFilePath) {
|
||
|
return () => {
|
||
|
return z.string().transform(async (imagePath, ctx) => {
|
||
|
var _a;
|
||
|
const resolvedFilePath = (_a = await pluginContext.resolve(imagePath, entryFilePath)) == null ? void 0 : _a.id;
|
||
|
const metadata = await emitESMImage(
|
||
|
resolvedFilePath,
|
||
|
pluginContext.meta.watchMode,
|
||
|
pluginContext.emitFile
|
||
|
);
|
||
|
if (!metadata) {
|
||
|
ctx.addIssue({
|
||
|
code: "custom",
|
||
|
message: `Image ${imagePath} does not exist. Is the path correct?`,
|
||
|
fatal: true
|
||
|
});
|
||
|
return z.never();
|
||
|
}
|
||
|
return metadata;
|
||
|
});
|
||
|
};
|
||
|
}
|
||
|
export {
|
||
|
createImage
|
||
|
};
|