@mercurjs/dashboard-sdk 2.0.0-canary.60 → 2.0.0-canary.62
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 +38 -40
- package/dist/index.d.cts +5 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,8 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
34
|
-
defineConfig: () => defineConfig
|
|
33
|
+
mercurDashboardPlugin: () => mercurDashboardPlugin
|
|
35
34
|
});
|
|
36
35
|
module.exports = __toCommonJS(index_exports);
|
|
37
36
|
|
|
@@ -73,7 +72,6 @@ function normalizePath(filePath) {
|
|
|
73
72
|
|
|
74
73
|
// src/constants.ts
|
|
75
74
|
var VALID_FILE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
76
|
-
var CONFIG_NAME = "mercur.config.ts";
|
|
77
75
|
var CONFIG_VIRTUAL_MODULE = "virtual:mercur/config";
|
|
78
76
|
var ROUTES_VIRTUAL_MODULE = "virtual:mercur/routes";
|
|
79
77
|
var COMPONENTS_VIRTUAL_MODULE = "virtual:mercur/components";
|
|
@@ -506,41 +504,52 @@ function loadI18nModule(mercurConfig) {
|
|
|
506
504
|
}
|
|
507
505
|
|
|
508
506
|
// src/plugin.ts
|
|
509
|
-
function buildConfig(config, root) {
|
|
510
|
-
const srcDir = import_path5.default.join(root, "src");
|
|
511
|
-
return {
|
|
512
|
-
...config,
|
|
513
|
-
backendUrl: config.backendUrl ?? "http://localhost:9000",
|
|
514
|
-
root,
|
|
515
|
-
srcDir,
|
|
516
|
-
configPath: import_path5.default.resolve(root, CONFIG_NAME)
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
async function loadMercurConfig(root) {
|
|
520
|
-
const configPath = import_path5.default.resolve(root, CONFIG_NAME);
|
|
521
|
-
try {
|
|
522
|
-
const mod = await getFileExports(configPath);
|
|
523
|
-
const content = mod.default ?? mod;
|
|
524
|
-
return buildConfig(content, root);
|
|
525
|
-
} catch (error) {
|
|
526
|
-
console.error(error);
|
|
527
|
-
throw new Error(
|
|
528
|
-
`[@mercurjs/dashboard-sdk] Could not find or load ${CONFIG_NAME} in ${root}`
|
|
529
|
-
);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
507
|
function isPageFile(file) {
|
|
533
508
|
const basename = import_path5.default.basename(file, import_path5.default.extname(file));
|
|
534
509
|
return basename === "page";
|
|
535
510
|
}
|
|
536
|
-
|
|
511
|
+
var UI_MODULE_KEYS = [
|
|
512
|
+
"admin_ui",
|
|
513
|
+
"vendor_ui"
|
|
514
|
+
];
|
|
515
|
+
async function loadMedusaConfig(medusaConfigPath, root) {
|
|
516
|
+
try {
|
|
517
|
+
const mod = await getFileExports(medusaConfigPath);
|
|
518
|
+
const medusaConfig = mod.default ?? mod;
|
|
519
|
+
const modules = medusaConfig?.modules ?? {};
|
|
520
|
+
for (const key of UI_MODULE_KEYS) {
|
|
521
|
+
const value = modules[key];
|
|
522
|
+
if (!value || typeof value !== "object" || !value.options?.appDir) continue;
|
|
523
|
+
const appDir = import_path5.default.resolve(import_path5.default.dirname(medusaConfigPath), value.options.appDir);
|
|
524
|
+
if (appDir === root) {
|
|
525
|
+
return {
|
|
526
|
+
base: value.options.path
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return {};
|
|
531
|
+
} catch {
|
|
532
|
+
return {};
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function mercurDashboardPlugin(pluginConfig) {
|
|
537
536
|
let root;
|
|
538
537
|
let config;
|
|
539
538
|
return {
|
|
540
539
|
name: "@mercurjs/dashboard-sdk",
|
|
541
540
|
async config(viteConfig) {
|
|
542
541
|
root = viteConfig.root || process.cwd();
|
|
543
|
-
|
|
542
|
+
const medusaConfigPath = import_path5.default.resolve(root, pluginConfig.medusaConfigPath);
|
|
543
|
+
const { base } = await loadMedusaConfig(medusaConfigPath, root);
|
|
544
|
+
const srcDir = import_path5.default.join(root, "src");
|
|
545
|
+
const backendUrl = pluginConfig.backendUrl ?? "http://localhost:9000";
|
|
546
|
+
config = {
|
|
547
|
+
...pluginConfig,
|
|
548
|
+
backendUrl,
|
|
549
|
+
base,
|
|
550
|
+
root,
|
|
551
|
+
srcDir
|
|
552
|
+
};
|
|
544
553
|
return {
|
|
545
554
|
base: config.base,
|
|
546
555
|
define: {
|
|
@@ -577,11 +586,6 @@ function dashboardPlugin() {
|
|
|
577
586
|
server.watcher.on("unlink", handlePageChange);
|
|
578
587
|
},
|
|
579
588
|
handleHotUpdate({ file, server }) {
|
|
580
|
-
const configPath = import_path5.default.resolve(root, CONFIG_NAME);
|
|
581
|
-
if (file === configPath) {
|
|
582
|
-
server.restart();
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
589
|
if (isPageFile(file)) {
|
|
586
590
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ROUTES_MODULE);
|
|
587
591
|
if (mod) {
|
|
@@ -591,13 +595,7 @@ function dashboardPlugin() {
|
|
|
591
595
|
}
|
|
592
596
|
};
|
|
593
597
|
}
|
|
594
|
-
|
|
595
|
-
// src/define-config.ts
|
|
596
|
-
function defineConfig(config) {
|
|
597
|
-
return config;
|
|
598
|
-
}
|
|
599
598
|
// Annotate the CommonJS export names for ESM import in node:
|
|
600
599
|
0 && (module.exports = {
|
|
601
|
-
|
|
602
|
-
defineConfig
|
|
600
|
+
mercurDashboardPlugin
|
|
603
601
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as Vite from 'vite';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
3
|
|
|
4
|
-
declare function dashboardPlugin(): Vite.Plugin;
|
|
5
|
-
|
|
6
4
|
interface MercurConfig {
|
|
5
|
+
medusaConfigPath: string;
|
|
6
|
+
backendUrl?: string;
|
|
7
7
|
name?: string;
|
|
8
8
|
logo?: string;
|
|
9
9
|
components?: {
|
|
@@ -14,15 +14,13 @@ interface MercurConfig {
|
|
|
14
14
|
i18n?: {
|
|
15
15
|
defaultLanguage: string;
|
|
16
16
|
};
|
|
17
|
-
backendUrl?: string;
|
|
18
|
-
base?: string;
|
|
19
17
|
enableSellerRegistration?: boolean;
|
|
20
18
|
}
|
|
21
19
|
interface BuiltMercurConfig extends MercurConfig {
|
|
22
20
|
backendUrl: string;
|
|
21
|
+
base?: string;
|
|
23
22
|
root: string;
|
|
24
23
|
srcDir: string;
|
|
25
|
-
configPath: string;
|
|
26
24
|
}
|
|
27
25
|
type RouteConfig = {
|
|
28
26
|
label: string;
|
|
@@ -33,6 +31,6 @@ type RouteConfig = {
|
|
|
33
31
|
public?: boolean;
|
|
34
32
|
};
|
|
35
33
|
|
|
36
|
-
declare function
|
|
34
|
+
declare function mercurDashboardPlugin(pluginConfig: MercurConfig): Vite.Plugin;
|
|
37
35
|
|
|
38
|
-
export { type BuiltMercurConfig, type MercurConfig, type RouteConfig,
|
|
36
|
+
export { type BuiltMercurConfig, type MercurConfig, type RouteConfig, mercurDashboardPlugin };
|