mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
editor: export tool definitions and other utils independently
This commit is contained in:
@@ -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": {
|
||||||
|
|||||||
@@ -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...");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user