editor: export tool definitions and other utils independently

This commit is contained in:
Abdullah Atta
2024-09-24 13:44:31 +05:00
parent b881023e7b
commit 21b6fc4982
2 changed files with 50 additions and 6 deletions

View File

@@ -16,8 +16,36 @@
} }
}, },
"./styles/*.css": "./dist/styles/*.css", "./styles/*.css": "./dist/styles/*.css",
"./tools": "./src/toolbar/tool-definitions.ts", "./toolbar/tool-definitions": {
"./fonts": "./src/utils/font.ts" "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", "license": "GPL-3.0-or-later",
"dependencies": { "dependencies": {

View File

@@ -29,24 +29,40 @@ const ROOT_DIR = path.resolve(path.join(__dirname, ".."));
const DIST_DIR = path.resolve(ROOT_DIR, "dist"); const DIST_DIR = path.resolve(ROOT_DIR, "dist");
const CJS_BUNDLE_PATH = path.resolve(ROOT_DIR, "dist", "index.js"); const CJS_BUNDLE_PATH = path.resolve(ROOT_DIR, "dist", "index.js");
const MJS_BUNDLE_PATH = path.resolve(ROOT_DIR, "dist", "index.mjs"); 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 ( if (
!fs.existsSync(DIST_DIR) || !fs.existsSync(DIST_DIR) ||
!fs.existsSync(CJS_BUNDLE_PATH) || !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."); throw new Error("Please build the editor before running this script.");
for (const bundle of [ for (const bundle of [
{ type: "cjs", path: CJS_BUNDLE_PATH }, { 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..."); console.log("Replacing icons with their path...");
let ICON_FILE = await readFile(bundle.path, "utf-8"); let ICON_FILE = await readFile(bundle.path, "utf-8");
const icons = const icons =
bundle.type === "cjs" bundle.type === "cjs"
? ICON_FILE.matchAll(/: _js\.(mdi.+),/g) ? ICON_FILE.matchAll(/: .+\.(mdi.+),/g)
: ICON_FILE.matchAll(/: (mdi.+),/g); : ICON_FILE.matchAll(/: (mdi.+),/g);
for (const icon of icons) { for (const icon of icons) {
const iconPath = Mjs[icon[1]]; const iconPath = Mjs[icon[1]];
@@ -56,7 +72,7 @@ for (const bundle of [
console.log("Removing @mdi/js import..."); 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..."); console.log("Saving file...");