mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-22 02:09:47 +08:00
Use npm packages for shared skill code (#136)
This commit is contained in:
@@ -4,7 +4,27 @@ import { fileURLToPath } from "node:url";
|
||||
import type { StyleConfig, HtmlDocumentMeta } from "./types.js";
|
||||
import { DEFAULT_STYLE } from "./constants.js";
|
||||
|
||||
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
||||
function resolveCommonJsDir(): string | undefined {
|
||||
try {
|
||||
const value = eval(
|
||||
"typeof module === 'object' && module && module.exports && typeof __dirname === 'string' ? __dirname : undefined",
|
||||
);
|
||||
return typeof value === "string" ? value : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveModuleDir(metaUrl?: string): string {
|
||||
const commonJsDir = resolveCommonJsDir();
|
||||
if (commonJsDir) return commonJsDir;
|
||||
if (!metaUrl) {
|
||||
throw new Error("Unable to resolve module directory.");
|
||||
}
|
||||
return path.dirname(fileURLToPath(metaUrl));
|
||||
}
|
||||
|
||||
const SCRIPT_DIR = resolveModuleDir(import.meta.url);
|
||||
const CODE_THEMES_DIR = path.resolve(SCRIPT_DIR, "code-themes");
|
||||
|
||||
export function buildCss(baseCss: string, themeCss: string, style: StyleConfig = DEFAULT_STYLE): string {
|
||||
|
||||
Reference in New Issue
Block a user