The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
import path from "path";
import { registryCodegenOptionsSchema } from "@/src/commands/registry-codegen";
import * as ERRORS from "@/src/utils/errors";
import { getConfig } from "@/src/utils/get-config";
import { highlighter } from "@/src/utils/highlighter";
import { logger } from "@/src/utils/logger";
import fs from "fs-extra";
import { z } from "zod";
export async function preFlightRegistryCodegen(
options: z.infer<typeof registryCodegenOptionsSchema>
) {
const errors: Record<string, boolean> = {};
const resolvePaths = {
cwd: options.cwd,
registryFile: path.resolve(options.cwd, options.registryFile),
};
// Ensure registry file exists.
if (!fs.existsSync(resolvePaths.registryFile)) {
errors[ERRORS.BUILD_MISSING_REGISTRY_FILE] = true;
return {
errors,
resolvePaths: null,
config: null,
};
}
// Check for existing blocks.json file.
if (!fs.existsSync(path.resolve(options.cwd, "blocks.json"))) {
errors[ERRORS.MISSING_CONFIG] = true;
return {
errors,
resolvePaths: null,
config: null,
};
}
try {
const config = await getConfig(options.cwd);
return {
errors,
config: config!,
resolvePaths,
};
} catch {
logger.break();
logger.error(
`An invalid ${highlighter.info(
"blocks.json"
)} file was found at ${highlighter.info(
options.cwd
)}.\nBefore you can run registry:codegen, you must create a valid ${highlighter.info(
"blocks.json"
)} file by running the ${highlighter.info("init")} command.`
);
logger.break();
process.exit(1);
}
}