@mercurjs/dashboard-sdk 2.0.0-canary.67 → 2.0.0-canary.69
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 +81 -20
- package/dist/index.d.cts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/plugin.ts
|
|
38
38
|
var import_path5 = __toESM(require("path"), 1);
|
|
39
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
39
40
|
|
|
40
41
|
// src/utils.ts
|
|
41
42
|
function resolveExports(moduleExports) {
|
|
@@ -256,21 +257,26 @@ function buildRouteTree(results) {
|
|
|
256
257
|
}
|
|
257
258
|
return Array.from(routeMap.values());
|
|
258
259
|
}
|
|
259
|
-
function generateRoutes({ srcDir }) {
|
|
260
|
+
function generateRoutes({ srcDir, pluginDirs }) {
|
|
260
261
|
const pagesDir = import_path.default.join(srcDir, "pages");
|
|
261
|
-
const files = crawlPages(pagesDir);
|
|
262
|
-
if (files.length === 0) {
|
|
263
|
-
return `export const customRoutes = []`;
|
|
264
|
-
}
|
|
265
262
|
let index = 0;
|
|
266
263
|
const results = [];
|
|
267
|
-
for (const file of
|
|
264
|
+
for (const file of crawlPages(pagesDir)) {
|
|
268
265
|
const result = parseFile(file, pagesDir, index);
|
|
269
266
|
if (result) {
|
|
270
267
|
results.push(result);
|
|
271
268
|
index++;
|
|
272
269
|
}
|
|
273
270
|
}
|
|
271
|
+
for (const pluginDir of pluginDirs) {
|
|
272
|
+
for (const file of crawlPages(pluginDir)) {
|
|
273
|
+
const result = parseFile(file, pluginDir, index);
|
|
274
|
+
if (result) {
|
|
275
|
+
results.push(result);
|
|
276
|
+
index++;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
274
280
|
if (results.length === 0) {
|
|
275
281
|
return `export const customRoutes = []`;
|
|
276
282
|
}
|
|
@@ -388,21 +394,26 @@ function parseFile2(file, pagesDir, index) {
|
|
|
388
394
|
menuItem: generateMenuItem(config, file, pagesDir, index)
|
|
389
395
|
};
|
|
390
396
|
}
|
|
391
|
-
function generateMenuItems({ srcDir }) {
|
|
397
|
+
function generateMenuItems({ srcDir, pluginDirs }) {
|
|
392
398
|
const pagesDir = import_path2.default.join(srcDir, "pages");
|
|
393
|
-
const files = crawlPages2(pagesDir);
|
|
394
|
-
if (files.length === 0) {
|
|
395
|
-
return `export default { menuItems: [] }`;
|
|
396
|
-
}
|
|
397
399
|
let index = 0;
|
|
398
400
|
const results = [];
|
|
399
|
-
for (const file of
|
|
401
|
+
for (const file of crawlPages2(pagesDir)) {
|
|
400
402
|
const result = parseFile2(file, pagesDir, index);
|
|
401
403
|
if (result) {
|
|
402
404
|
results.push(result);
|
|
403
405
|
index++;
|
|
404
406
|
}
|
|
405
407
|
}
|
|
408
|
+
for (const pluginDir of pluginDirs) {
|
|
409
|
+
for (const file of crawlPages2(pluginDir)) {
|
|
410
|
+
const result = parseFile2(file, pluginDir, index);
|
|
411
|
+
if (result) {
|
|
412
|
+
results.push(result);
|
|
413
|
+
index++;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
406
417
|
if (results.length === 0) {
|
|
407
418
|
return `export default { menuItems: [] }`;
|
|
408
419
|
}
|
|
@@ -512,24 +523,73 @@ var UI_MODULE_KEYS = [
|
|
|
512
523
|
"admin_ui",
|
|
513
524
|
"vendor_ui"
|
|
514
525
|
];
|
|
526
|
+
function findNodeModulesRoot(configDir) {
|
|
527
|
+
let dir = configDir;
|
|
528
|
+
while (dir !== import_path5.default.dirname(dir)) {
|
|
529
|
+
const candidate = import_path5.default.join(dir, "node_modules");
|
|
530
|
+
if (import_fs4.default.existsSync(candidate) && import_fs4.default.statSync(candidate).isDirectory()) {
|
|
531
|
+
return candidate;
|
|
532
|
+
}
|
|
533
|
+
dir = import_path5.default.dirname(dir);
|
|
534
|
+
}
|
|
535
|
+
return import_path5.default.join(configDir, "node_modules");
|
|
536
|
+
}
|
|
537
|
+
function resolvePluginRoot(resolve, configDir, nodeModulesRoot) {
|
|
538
|
+
try {
|
|
539
|
+
if (resolve.startsWith(".")) {
|
|
540
|
+
const resolved = import_path5.default.resolve(configDir, resolve);
|
|
541
|
+
if (import_fs4.default.existsSync(resolved)) {
|
|
542
|
+
return import_fs4.default.realpathSync(resolved);
|
|
543
|
+
}
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
const packagePath = import_path5.default.join(nodeModulesRoot, resolve);
|
|
547
|
+
if (!import_fs4.default.existsSync(packagePath)) {
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
return import_fs4.default.realpathSync(packagePath);
|
|
551
|
+
} catch {
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function resolvePluginDirs(plugins, configDir, appType) {
|
|
556
|
+
const nodeModulesRoot = findNodeModulesRoot(configDir);
|
|
557
|
+
const dirs = [];
|
|
558
|
+
for (const plugin of plugins) {
|
|
559
|
+
const resolve = typeof plugin === "string" ? plugin : plugin?.resolve;
|
|
560
|
+
if (!resolve || typeof resolve !== "string") continue;
|
|
561
|
+
const pluginRoot = resolvePluginRoot(resolve, configDir, nodeModulesRoot);
|
|
562
|
+
if (!pluginRoot) continue;
|
|
563
|
+
const extDir = import_path5.default.join(pluginRoot, appType);
|
|
564
|
+
if (import_fs4.default.existsSync(extDir) && import_fs4.default.statSync(extDir).isDirectory()) {
|
|
565
|
+
dirs.push(extDir);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return dirs;
|
|
569
|
+
}
|
|
515
570
|
async function loadMedusaConfig(medusaConfigPath, root) {
|
|
516
571
|
try {
|
|
517
572
|
const mod = await getFileExports(medusaConfigPath);
|
|
518
573
|
const medusaConfig = mod.default ?? mod;
|
|
519
574
|
const modules = medusaConfig?.modules ?? {};
|
|
575
|
+
const configDir = import_path5.default.dirname(medusaConfigPath);
|
|
576
|
+
let base;
|
|
577
|
+
let appType;
|
|
520
578
|
for (const key of UI_MODULE_KEYS) {
|
|
521
579
|
const value = modules[key];
|
|
522
580
|
if (!value || typeof value !== "object" || !value.options?.appDir) continue;
|
|
523
|
-
const appDir = import_path5.default.resolve(
|
|
581
|
+
const appDir = import_path5.default.resolve(configDir, value.options.appDir);
|
|
524
582
|
if (appDir === root) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
583
|
+
base = value.options.path;
|
|
584
|
+
appType = key === "admin_ui" ? "admin" : "vendor";
|
|
585
|
+
break;
|
|
528
586
|
}
|
|
529
587
|
}
|
|
530
|
-
|
|
588
|
+
const plugins = medusaConfig?.plugins ?? [];
|
|
589
|
+
const pluginDirs = appType ? resolvePluginDirs(plugins, configDir, appType) : [];
|
|
590
|
+
return { base, pluginDirs };
|
|
531
591
|
} catch {
|
|
532
|
-
return {};
|
|
592
|
+
return { pluginDirs: [] };
|
|
533
593
|
}
|
|
534
594
|
}
|
|
535
595
|
function mercurDashboardPlugin(pluginConfig) {
|
|
@@ -540,7 +600,7 @@ function mercurDashboardPlugin(pluginConfig) {
|
|
|
540
600
|
async config(viteConfig) {
|
|
541
601
|
root = viteConfig.root || process.cwd();
|
|
542
602
|
const medusaConfigPath = import_path5.default.resolve(root, pluginConfig.medusaConfigPath);
|
|
543
|
-
const { base } = await loadMedusaConfig(medusaConfigPath, root);
|
|
603
|
+
const { base, pluginDirs } = await loadMedusaConfig(medusaConfigPath, root);
|
|
544
604
|
const srcDir = import_path5.default.join(root, "src");
|
|
545
605
|
const backendUrl = pluginConfig.backendUrl ?? "http://localhost:9000";
|
|
546
606
|
config = {
|
|
@@ -548,7 +608,8 @@ function mercurDashboardPlugin(pluginConfig) {
|
|
|
548
608
|
backendUrl,
|
|
549
609
|
base,
|
|
550
610
|
root,
|
|
551
|
-
srcDir
|
|
611
|
+
srcDir,
|
|
612
|
+
pluginDirs
|
|
552
613
|
};
|
|
553
614
|
return {
|
|
554
615
|
base: config.base,
|
package/dist/index.d.cts
CHANGED