Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

refactor: adjust build process to include source directory conditionally and clean up preflight checks

vholik23df32296612
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts
index d0fdef71c..7ceb0750b 100644
--- a/packages/cli/src/commands/build.ts
+++ b/packages/cli/src/commands/build.ts
@@ -49,12 +49,15 @@ async function buildRegistry(opts: z.infer<typeof buildOptionsSchema>) {
try {
const options = buildOptionsSchema.parse(opts);
+
const [{ errors, resolvePaths, config }, projectInfo] = await Promise.all([
preFlightRegistryBuild(options),
getProjectInfo(options.cwd),
]);
- if (errors[ERRORS.MISSING_CONFIG] || !config || !projectInfo) {
+
+
+ if (errors[ERRORS.MISSING_CONFIG] || !projectInfo) {
logger.error(
`A ${highlighter.info(
"blocks.json"
@@ -126,7 +129,8 @@ async function buildRegistry(opts: z.infer<typeof buildOptionsSchema>) {
REGISTRY_ITEM_SCHEMA_URL;
for (const file of registryItem.files) {
- const absPath = path.resolve(resolvePaths.cwd, file.path);
+ const srcDir = projectInfo.isSrcDir ? "src" : "";
+ const absPath = path.resolve(resolvePaths.cwd, srcDir, file.path);
try {
const stat = await fs.stat(absPath);
if (!stat.isFile()) {
diff --git a/packages/cli/src/preflights/preflight-registry.ts b/packages/cli/src/preflights/preflight-registry.ts
index 7b9e00adb..5f542f0e3 100644
--- a/packages/cli/src/preflights/preflight-registry.ts
+++ b/packages/cli/src/preflights/preflight-registry.ts
@@ -18,6 +18,8 @@ export async function preFlightRegistryBuild(
outputDir: path.resolve(options.cwd, options.outputDir),
};
+
+
// Ensure registry file exists.
if (!fs.existsSync(resolvePaths.registryFile)) {
errors[ERRORS.BUILD_MISSING_REGISTRY_FILE] = true;
@@ -28,6 +30,7 @@ export async function preFlightRegistryBuild(
};
}
+
// Check for existing blocks.json file.
if (!fs.existsSync(path.resolve(options.cwd, "blocks.json"))) {
errors[ERRORS.MISSING_CONFIG] = true;
@@ -44,6 +47,7 @@ export async function preFlightRegistryBuild(
try {
const config = await getConfig(options.cwd);
+
return {
errors,
config: config!,
diff --git a/packages/registry/package.json b/packages/registry/package.json
index 65c979495..338e94134 100644
--- a/packages/registry/package.json
+++ b/packages/registry/package.json
@@ -6,7 +6,7 @@
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
- "build:registry": "mercurjs build ./r"
+ "build:registry": "mercurjs build"
},
"dependencies": {},
"devDependencies": {
diff --git a/packages/registry/registry.json b/packages/registry/registry.json
new file mode 100644
index 000000000..dcb79c1ae
--- /dev/null
+++ b/packages/registry/registry.json
@@ -0,0 +1,43 @@
+{
+ "$schema": "https://raw.githubusercontent.com/mercurjs/mercur/new/packages/registry/public/schema/registry.json",
+ "name": "@mercurjs",
+ "homepage": "https://mercurjs.com",
+ "items": [
+ {
+ "name": "block-1",
+ "description": "A block with a test module, product-test link, and API route.",
+ "dependencies": [],
+ "registryDependencies": [],
+ "files": [
+ {
+ "path": "block-1/modules/test/index.ts",
+ "type": "registry:module",
+ "target": "src/modules/test/index.ts"
+ },
+ {
+ "path": "block-1/modules/test/service.ts",
+ "type": "registry:module",
+ "target": "src/modules/test/service.ts"
+ },
+ {
+ "path": "block-1/modules/test/models/test.ts",
+ "type": "registry:module",
+ "target": "src/modules/test/models/test.ts"
+ },
+ {
+ "path": "block-1/links/product-test.ts",
+ "type": "registry:link",
+ "target": "src/links/product-test.ts"
+ },
+ {
+ "path": "block-1/api/hello/test/route.ts",
+ "type": "registry:api",
+ "target": "src/api/hello/test/route.ts"
+ }
+ ],
+ "categories": [
+ "test"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/packages/registry/src/registry.ts b/packages/registry/src/registry.ts
deleted file mode 100644
index c3d8307f8..000000000
--- a/packages/registry/src/registry.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { Registry, registryItemSchema } from '@mercurjs/cli'
-import { z } from "zod"
-
-const blocks: Registry['items'] = [
- {
- name: "block-1",
- description: "A block with a test module, product-test link, and API route.",
- dependencies: [],
- registryDependencies: [],
- files: [
- {
- path: "block-1/modules/test/index.ts",
- type: "registry:module",
- target: "src/modules/test/index.ts",
- },
- {
- path: "block-1/modules/test/service.ts",
- type: "registry:module",
- target: "src/modules/test/service.ts",
- },
- {
- path: "block-1/modules/test/models/test.ts",
- type: "registry:module",
- target: "src/modules/test/models/test.ts",
- },
- {
- path: "block-1/links/product-test.ts",
- type: "registry:link",
- target: "src/links/product-test.ts",
- },
- {
- path: "block-1/api/hello/test/route.ts",
- type: "registry:api",
- target: "src/api/hello/test/route.ts",
- },
- ],
- categories: ["test"],
- },
-]
-
-
-export const registry = {
- name: "@mercurjs",
- homepage: "https://mercurjs.com",
- items: z.array(registryItemSchema).parse(
- blocks
- ),
-} satisfies Registry
\ No newline at end of file