editor: fix postbuild script

This commit is contained in:
Abdullah Atta
2024-11-12 13:17:45 +05:00
committed by Abdullah Atta
parent ecfa0e2c6b
commit b7aaa382b1

View File

@@ -27,33 +27,29 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const ROOT_DIR = path.resolve(path.join(__dirname, ".."));
const DIST_DIR = path.resolve(ROOT_DIR, "dist");
const CJS_BUNDLE_PATH = path.resolve(ROOT_DIR, "dist", "index.js");
const MJS_BUNDLE_PATH = path.resolve(ROOT_DIR, "dist", "index.mjs");
const ICONS_MJS_BUNDLE_PATH = path.resolve(
ROOT_DIR,
"dist",
"esm",
"toolbar",
"icons.mjs"
"icons.js"
);
const ICONS_CJS_BUNDLE_PATH = path.resolve(
ROOT_DIR,
"dist",
"cjs",
"toolbar",
"icons.js"
);
if (
!fs.existsSync(DIST_DIR) ||
!fs.existsSync(CJS_BUNDLE_PATH) ||
!fs.existsSync(MJS_BUNDLE_PATH) ||
!fs.existsSync(ICONS_MJS_BUNDLE_PATH) ||
!fs.existsSync(ICONS_CJS_BUNDLE_PATH)
)
throw new Error("Please build the editor before running this script.");
for (const bundle of [
{ type: "cjs", path: CJS_BUNDLE_PATH },
{ type: "mjs", path: MJS_BUNDLE_PATH },
{ type: "cjs", path: ICONS_CJS_BUNDLE_PATH },
{ type: "mjs", path: ICONS_MJS_BUNDLE_PATH }
]) {
@@ -72,7 +68,11 @@ for (const bundle of [
console.log("Removing @mdi/js import...");
ICON_FILE = ICON_FILE.replace(/var.+=\s+require\(['"]@mdi\/js['"]\);/gm, "");
ICON_FILE = ICON_FILE.replace(/^import \{.+ } from "@mdi\/js";/gm, "");
ICON_FILE = ICON_FILE.replace(
/(var|const|let).+=\s+require\(['"]@mdi\/js['"]\);/gm,
""
);
console.log("Saving file...");