mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-21 01:39:48 +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 {
|
||||
|
||||
@@ -3,7 +3,27 @@ import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import type { ThemeName } from "./types.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);
|
||||
export const THEME_DIR = path.resolve(SCRIPT_DIR, "themes");
|
||||
const FALLBACK_THEMES: ThemeName[] = ["default", "grace", "simple"];
|
||||
const THEMES_EXTENDING_DEFAULT = new Set<ThemeName>(["grace", "simple"]);
|
||||
|
||||
Reference in New Issue
Block a user