Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: export tool definitions and other utils independently

Abdullah Atta21b6fc49829c
diff --git a/packages/editor/package.json b/packages/editor/package.json
index 2e91cf168..95246c468 100644
--- a/packages/editor/package.json
+++ b/packages/editor/package.json
@@ -16,8 +16,36 @@
}
},
"./styles/*.css": "./dist/styles/*.css",
- "./tools": "./src/toolbar/tool-definitions.ts",
- "./fonts": "./src/utils/font.ts"
+ "./toolbar/tool-definitions": {
+ "require": {
+ "types": "./dist/toolbar/tool-definitions.d.ts",
+ "default": "./dist/toolbar/tool-definitions.js"
+ },
+ "import": {
+ "types": "./dist/toolbar/tool-definitions.d.mts",
+ "default": "./dist/toolbar/tool-definitions.mjs"
+ }
+ },
+ "./utils/font": {
+ "require": {
+ "types": "./dist/utils/font.d.ts",
+ "default": "./dist/utils/font.js"
+ },
+ "import": {
+ "types": "./dist/utils/font.d.mts",
+ "default": "./dist/utils/font.mjs"
+ }
+ },
+ "./toolbar/icons": {
+ "require": {
+ "types": "./dist/toolbar/icons.d.ts",
+ "default": "./dist/toolbar/icons.js"
+ },
+ "import": {
+ "types": "./dist/toolbar/icons.d.mts",
+ "default": "./dist/toolbar/icons.mjs"
+ }
+ }
},
"license": "GPL-3.0-or-later",
"dependencies": {
diff --git a/packages/editor/scripts/postbuild.mjs b/packages/editor/scripts/postbuild.mjs
index 5ab0ccad8..89a426e16 100644
--- a/packages/editor/scripts/postbuild.mjs
+++ b/packages/editor/scripts/postbuild.mjs
@@ -29,24 +29,40 @@ 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",
+ "toolbar",
+ "icons.mjs"
+);
+const ICONS_CJS_BUNDLE_PATH = path.resolve(
+ ROOT_DIR,
+ "dist",
+ "toolbar",
+ "icons.js"
+);
if (
!fs.existsSync(DIST_DIR) ||
!fs.existsSync(CJS_BUNDLE_PATH) ||
- !fs.existsSync(MJS_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: "mjs", path: MJS_BUNDLE_PATH },
+ { type: "cjs", path: ICONS_CJS_BUNDLE_PATH },
+ { type: "mjs", path: ICONS_MJS_BUNDLE_PATH }
]) {
console.log("Replacing icons with their path...");
let ICON_FILE = await readFile(bundle.path, "utf-8");
const icons =
bundle.type === "cjs"
- ? ICON_FILE.matchAll(/: _js\.(mdi.+),/g)
+ ? ICON_FILE.matchAll(/: .+\.(mdi.+),/g)
: ICON_FILE.matchAll(/: (mdi.+),/g);
for (const icon of icons) {
const iconPath = Mjs[icon[1]];
@@ -56,7 +72,7 @@ for (const bundle of [
console.log("Removing @mdi/js import...");
- ICON_FILE = ICON_FILE.replace("var _js = require('@mdi/js');", "");
+ ICON_FILE = ICON_FILE.replace(/var.+=\s+require\(['"]@mdi\/js['"]\);/gm, "");
console.log("Saving file...");