@mercurjs/dashboard-sdk 2.0.0-canary.71 → 2.0.0-canary.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +40 -42
- package/dist/index.d.cts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -257,7 +257,7 @@ function buildRouteTree(results) {
|
|
|
257
257
|
}
|
|
258
258
|
return Array.from(routeMap.values());
|
|
259
259
|
}
|
|
260
|
-
function generateRoutes({ srcDir,
|
|
260
|
+
function generateRoutes({ srcDir, pluginExtensions }) {
|
|
261
261
|
const pagesDir = import_path.default.join(srcDir, "pages");
|
|
262
262
|
let index = 0;
|
|
263
263
|
const results = [];
|
|
@@ -268,25 +268,24 @@ function generateRoutes({ srcDir, pluginDirs }) {
|
|
|
268
268
|
index++;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
271
|
+
const pluginImports = pluginExtensions.map(
|
|
272
|
+
(ext, i) => `import __plugin${i} from "${normalizePath(ext)}"`
|
|
273
|
+
);
|
|
274
|
+
const pluginSpreads = pluginExtensions.map(
|
|
275
|
+
(_, i) => ` ...(__plugin${i}.routeModule?.routes ?? [])`
|
|
276
|
+
);
|
|
277
|
+
const routeTree = buildRouteTree(results);
|
|
278
|
+
const appImports = routeTree.flatMap((r) => r.imports);
|
|
279
|
+
const appRoutes = routeTree.map((r) => formatRoute(r.route));
|
|
280
|
+
const allImports = [...appImports, ...pluginImports];
|
|
281
|
+
const allRoutes = [...appRoutes, ...pluginSpreads];
|
|
282
|
+
if (allImports.length === 0 && allRoutes.length === 0) {
|
|
281
283
|
return `export const customRoutes = []`;
|
|
282
284
|
}
|
|
283
|
-
|
|
284
|
-
const imports = routeTree.flatMap((result) => result.imports);
|
|
285
|
-
const routes = routeTree.map((result) => formatRoute(result.route));
|
|
286
|
-
return `${imports.join("\n")}
|
|
285
|
+
return `${allImports.join("\n")}
|
|
287
286
|
|
|
288
287
|
export const customRoutes = [
|
|
289
|
-
${
|
|
288
|
+
${allRoutes.join(",\n")}
|
|
290
289
|
]`;
|
|
291
290
|
}
|
|
292
291
|
|
|
@@ -394,7 +393,7 @@ function parseFile2(file, pagesDir, index) {
|
|
|
394
393
|
menuItem: generateMenuItem(config, file, pagesDir, index)
|
|
395
394
|
};
|
|
396
395
|
}
|
|
397
|
-
function generateMenuItems({ srcDir,
|
|
396
|
+
function generateMenuItems({ srcDir, pluginExtensions }) {
|
|
398
397
|
const pagesDir = import_path2.default.join(srcDir, "pages");
|
|
399
398
|
let index = 0;
|
|
400
399
|
const results = [];
|
|
@@ -405,25 +404,24 @@ function generateMenuItems({ srcDir, pluginDirs }) {
|
|
|
405
404
|
index++;
|
|
406
405
|
}
|
|
407
406
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
407
|
+
const pluginImports = pluginExtensions.map(
|
|
408
|
+
(ext, i) => `import __plugin${i} from "${normalizePath(ext)}"`
|
|
409
|
+
);
|
|
410
|
+
const pluginSpreads = pluginExtensions.map(
|
|
411
|
+
(_, i) => ` ...(__plugin${i}.menuItemModule?.menuItems ?? [])`
|
|
412
|
+
);
|
|
413
|
+
const appImports = results.map((r) => r.import);
|
|
414
|
+
const appMenuItems = results.map((r) => formatMenuItem(r.menuItem));
|
|
415
|
+
const allImports = [...appImports, ...pluginImports];
|
|
416
|
+
const allMenuItems = [...appMenuItems, ...pluginSpreads];
|
|
417
|
+
if (allImports.length === 0 && allMenuItems.length === 0) {
|
|
418
418
|
return `export default { menuItems: [] }`;
|
|
419
419
|
}
|
|
420
|
-
|
|
421
|
-
const menuItems = results.map((r) => formatMenuItem(r.menuItem));
|
|
422
|
-
return `${imports.join("\n")}
|
|
420
|
+
return `${allImports.join("\n")}
|
|
423
421
|
|
|
424
422
|
export default {
|
|
425
423
|
menuItems: [
|
|
426
|
-
${
|
|
424
|
+
${allMenuItems.join(",\n")}
|
|
427
425
|
]
|
|
428
426
|
}`;
|
|
429
427
|
}
|
|
@@ -552,9 +550,9 @@ function resolvePluginRoot(resolve, configDir, nodeModulesRoot) {
|
|
|
552
550
|
return null;
|
|
553
551
|
}
|
|
554
552
|
}
|
|
555
|
-
function
|
|
553
|
+
function resolvePluginExtensions(plugins, configDir) {
|
|
556
554
|
const nodeModulesRoot = findNodeModulesRoot(configDir);
|
|
557
|
-
const
|
|
555
|
+
const extensions = [];
|
|
558
556
|
const appTypes = ["admin", "vendor"];
|
|
559
557
|
for (const plugin of plugins) {
|
|
560
558
|
const resolve = typeof plugin === "string" ? plugin : plugin?.resolve;
|
|
@@ -562,13 +560,13 @@ function resolvePluginDirs(plugins, configDir) {
|
|
|
562
560
|
const pluginRoot = resolvePluginRoot(resolve, configDir, nodeModulesRoot);
|
|
563
561
|
if (!pluginRoot) continue;
|
|
564
562
|
for (const appType of appTypes) {
|
|
565
|
-
const
|
|
566
|
-
if (import_fs4.default.existsSync(
|
|
567
|
-
|
|
563
|
+
const extFile = import_path5.default.join(pluginRoot, ".medusa/server/src", appType, "index.js");
|
|
564
|
+
if (import_fs4.default.existsSync(extFile)) {
|
|
565
|
+
extensions.push(extFile);
|
|
568
566
|
}
|
|
569
567
|
}
|
|
570
568
|
}
|
|
571
|
-
return
|
|
569
|
+
return extensions;
|
|
572
570
|
}
|
|
573
571
|
async function loadMedusaConfig(medusaConfigPath, root) {
|
|
574
572
|
try {
|
|
@@ -587,10 +585,10 @@ async function loadMedusaConfig(medusaConfigPath, root) {
|
|
|
587
585
|
}
|
|
588
586
|
}
|
|
589
587
|
const plugins = medusaConfig?.plugins ?? [];
|
|
590
|
-
const
|
|
591
|
-
return { base,
|
|
588
|
+
const pluginExtensions = resolvePluginExtensions(plugins, configDir);
|
|
589
|
+
return { base, pluginExtensions };
|
|
592
590
|
} catch {
|
|
593
|
-
return {
|
|
591
|
+
return { pluginExtensions: [] };
|
|
594
592
|
}
|
|
595
593
|
}
|
|
596
594
|
function mercurDashboardPlugin(pluginConfig) {
|
|
@@ -601,7 +599,7 @@ function mercurDashboardPlugin(pluginConfig) {
|
|
|
601
599
|
async config(viteConfig) {
|
|
602
600
|
root = viteConfig.root || process.cwd();
|
|
603
601
|
const medusaConfigPath = import_path5.default.resolve(root, pluginConfig.medusaConfigPath);
|
|
604
|
-
const { base,
|
|
602
|
+
const { base, pluginExtensions } = await loadMedusaConfig(medusaConfigPath, root);
|
|
605
603
|
const srcDir = import_path5.default.join(root, "src");
|
|
606
604
|
const backendUrl = pluginConfig.backendUrl ?? "http://localhost:9000";
|
|
607
605
|
config = {
|
|
@@ -610,7 +608,7 @@ function mercurDashboardPlugin(pluginConfig) {
|
|
|
610
608
|
base,
|
|
611
609
|
root,
|
|
612
610
|
srcDir,
|
|
613
|
-
|
|
611
|
+
pluginExtensions
|
|
614
612
|
};
|
|
615
613
|
return {
|
|
616
614
|
base: config.base,
|
package/dist/index.d.cts
CHANGED