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 CLI file handling to update paths for better organization, rename function for clarity, and streamline registry URL format.

vholik30f8326bafae
diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts
index e7148aaf7..b3b89643a 100644
--- a/packages/cli/src/commands/init.ts
+++ b/packages/cli/src/commands/init.ts
@@ -103,13 +103,13 @@ async function promptForConfig(opts: z.infer<typeof initOptionsSchema>) {
return rawConfigSchema.parse({
$schema: "https://mercurjs.com/schema.json",
aliases: {
- workflows: "@/workflows",
- api: "@/api",
- links: "@/links",
- modules: "@/modules",
- vendorPages: "@/vendor-pages",
- adminPages: "@/admin-pages",
- lib: "@/lib",
+ workflows: "@/src/workflows",
+ api: "@/src/api",
+ links: "@/src/links",
+ modules: "@/src/modules",
+ vendorPages: "@workspace/apps/vendor/src/pages",
+ adminPages: "@workspace/apps/admin/src/pages",
+ lib: "@/src/lib",
},
registries: BUILTIN_REGISTRIES,
});
@@ -121,43 +121,43 @@ async function promptForConfig(opts: z.infer<typeof initOptionsSchema>) {
type: "text",
name: "workflows",
message: `Configure the import alias for ${highlighter.info("workflows")}:`,
- initial: "@/apps/api/src/workflows",
+ initial: "@/src/workflows",
},
{
type: "text",
name: "api",
message: `Configure the import alias for ${highlighter.info("api")}:`,
- initial: "@/apps/api/src/api",
+ initial: "@/src/api",
},
{
type: "text",
name: "links",
message: `Configure the import alias for ${highlighter.info("links")}:`,
- initial: "@/apps/api/src/links",
+ initial: "@/src/links",
},
{
type: "text",
name: "modules",
message: `Configure the import alias for ${highlighter.info("modules")}:`,
- initial: "@/apps/api/src/modules",
+ initial: "@/src/modules",
},
{
type: "text",
name: "vendorPages",
message: `Configure the import alias for ${highlighter.info("Vendor panel pages")}:`,
- initial: "@/apps/vendor/src/pages",
+ initial: "@workspace/apps/vendor/src/pages",
},
{
type: "text",
name: "adminPages",
message: `Configure the import alias for ${highlighter.info("Admin panel pages")}:`,
- initial: "@/apps/admin/src/pages",
+ initial: "@workspace/apps/admin/src/pages",
},
{
type: "text",
name: "lib",
message: `Configure the import alias for ${highlighter.info("lib")}:`,
- initial: "@/apps/api/src/lib",
+ initial: "@/src/lib",
},
]);
@@ -185,13 +185,13 @@ async function promptForMinimalConfig(
return rawConfigSchema.parse({
$schema: "https://mercurjs.com/schema.json",
aliases: {
- workflows: "@/apps/api/src/workflows",
- api: "@/apps/api/src/api",
- links: "@/apps/api/src/links",
- modules: "@/apps/api/src/modules",
- vendorPages: "@/apps/vendor/src/pages",
- adminPages: "@/apps/admin/src/pages",
- lib: "@/apps/api/src/lib",
+ workflows: "@/src/workflows",
+ api: "@/src/api",
+ links: "@/src/links",
+ modules: "@/src/modules",
+ vendorPages: "@workspace/apps/vendor/src/pages",
+ adminPages: "@workspace/apps/admin/src/pages",
+ lib: "@/src/lib",
},
registries: BUILTIN_REGISTRIES,
});
diff --git a/packages/cli/src/registry/constants.ts b/packages/cli/src/registry/constants.ts
index 2fd329951..15bfb07c4 100644
--- a/packages/cli/src/registry/constants.ts
+++ b/packages/cli/src/registry/constants.ts
@@ -10,5 +10,5 @@ export const REGISTRY_URL =
// Built-in registries that are always available and cannot be overridden
export const BUILTIN_REGISTRIES: z.infer<typeof registryConfigSchema> = {
- "@mercurjs": `${REGISTRY_URL}/{type}/{name}.json`,
+ "@mercurjs": `${REGISTRY_URL}/{name}.json`,
};
diff --git a/packages/cli/src/utils/file-type.ts b/packages/cli/src/utils/file-type.ts
index 3e378d837..0ae037199 100644
--- a/packages/cli/src/utils/file-type.ts
+++ b/packages/cli/src/utils/file-type.ts
@@ -3,7 +3,7 @@ import type { RegistryItemCategory } from "../registry/schema";
/**
* Get the target directory for a registry file based on its type.
*/
-export function getFileType(file: {
+export function getTargetDir(file: {
type: string;
path: string;
}): RegistryItemCategory {
@@ -21,8 +21,5 @@ export function getFileType(file: {
* Get the relative path by stripping the type prefix from a file path.
*/
export function getRelativePath(filePath: string) {
- return filePath.replace(
- /^(workflows|api|links|modules|vendorPages|adminPages|lib)\//,
- ""
- );
+ return filePath.replace(/^(agents|tools|prompts)\//, "");
}
diff --git a/packages/cli/src/utils/update-files.ts b/packages/cli/src/utils/update-files.ts
index 7d32e62cf..2221c1b3e 100644
--- a/packages/cli/src/utils/update-files.ts
+++ b/packages/cli/src/utils/update-files.ts
@@ -5,7 +5,7 @@ import prompts from "prompts";
import type { RegistryItem } from "../registry/schema";
import type { Config } from "../schema";
import { isContentSame } from "./compare";
-import { getRelativePath, getFileType } from "./file-type";
+import { getRelativePath, getTargetDir } from "./file-type";
import { getProjectInfo } from "./get-project-info";
import { highlighter } from "./highlighter";
import { logger } from "./logger";
@@ -50,7 +50,7 @@ export async function updateFiles(
const filesDeclined: string[] = [];
for (const file of files) {
- const fileType = getFileType(file);
+ const fileType = getTargetDir(file);
const relativePath = getRelativePath(file.path);
const basePath = options.path || config.resolvedPaths[fileType];