mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
editor: import & use language grammars from refractor directly
This commit is contained in:
@@ -1,4 +1,2 @@
|
||||
*
|
||||
!dist/**/*
|
||||
!styles/**/*
|
||||
!languages/**/*
|
||||
@@ -42,9 +42,23 @@ for (const name in pathsToCopy) {
|
||||
});
|
||||
}
|
||||
|
||||
const languagesList = await langen(ROOT_DIR, path.join(ROOT_DIR, "languages"));
|
||||
const { languageIndex, languages } = await langen(ROOT_DIR);
|
||||
|
||||
if (!languageIndex || !languages) throw new Error("No language index found.");
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(
|
||||
ROOT_DIR,
|
||||
"src",
|
||||
"extensions",
|
||||
"code-block",
|
||||
"languages",
|
||||
"index.ts"
|
||||
),
|
||||
languageIndex
|
||||
);
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(ROOT_DIR, "src", "extensions", "code-block", "languages.json"),
|
||||
JSON.stringify(languagesList)
|
||||
JSON.stringify(languages)
|
||||
);
|
||||
|
||||
@@ -21,33 +21,52 @@ import * as Mjs from "@mdi/js";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import { readFile, writeFile } from "fs/promises";
|
||||
import { cp, readFile, writeFile } from "fs/promises";
|
||||
|
||||
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 ICONS_FILE_PATH = path.join(DIST_DIR, "toolbar", "icons.js");
|
||||
const CJS_BUNDLE_PATH = path.resolve(ROOT_DIR, "dist", "index.js");
|
||||
const MJS_BUNDLE_PATH = path.resolve(ROOT_DIR, "dist", "index.mjs");
|
||||
|
||||
if (!fs.existsSync(DIST_DIR) || !fs.existsSync(ICONS_FILE_PATH))
|
||||
if (
|
||||
!fs.existsSync(DIST_DIR) ||
|
||||
!fs.existsSync(CJS_BUNDLE_PATH) ||
|
||||
!fs.existsSync(MJS_BUNDLE_PATH)
|
||||
)
|
||||
throw new Error("Please build the editor before running this script.");
|
||||
|
||||
console.log("Replacing icons with their path...");
|
||||
for (const bundle of [
|
||||
{ type: "cjs", path: CJS_BUNDLE_PATH },
|
||||
{ type: "mjs", path: MJS_BUNDLE_PATH }
|
||||
]) {
|
||||
console.log("Replacing icons with their path...");
|
||||
|
||||
let ICON_FILE = await readFile(ICONS_FILE_PATH, "utf-8");
|
||||
const icons = ICON_FILE.matchAll(/: (mdi.+),/g);
|
||||
for (const icon of icons) {
|
||||
const iconPath = Mjs[icon[1]];
|
||||
if (!iconPath) throw new Error(`Could not find path for icon: ${icon[1]}.`);
|
||||
ICON_FILE = ICON_FILE.replace(icon[0], `: "${iconPath}",`);
|
||||
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);
|
||||
for (const icon of icons) {
|
||||
const iconPath = Mjs[icon[1]];
|
||||
if (!iconPath) throw new Error(`Could not find path for icon: ${icon[1]}.`);
|
||||
ICON_FILE = ICON_FILE.replace(icon[0], `: "${iconPath}",`);
|
||||
}
|
||||
|
||||
console.log("Removing @mdi/js import...");
|
||||
|
||||
ICON_FILE = ICON_FILE.replace("var _js = require('@mdi/js');", "");
|
||||
|
||||
console.log("Saving file...");
|
||||
|
||||
await writeFile(bundle.path, ICON_FILE);
|
||||
}
|
||||
|
||||
console.log("Removing @mdi/js import...");
|
||||
console.log("copying styles...");
|
||||
|
||||
ICON_FILE = ICON_FILE.replace(/^import \{.+ } from "@mdi\/js";/gm, "");
|
||||
|
||||
console.log("Saving file...");
|
||||
|
||||
await writeFile(ICONS_FILE_PATH, ICON_FILE);
|
||||
await cp(path.resolve(ROOT_DIR, "styles"), path.resolve(DIST_DIR, "styles"), {
|
||||
recursive: true
|
||||
});
|
||||
|
||||
console.log("Done.");
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
"compilerOptions": {
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"jsx": "react-jsx",
|
||||
"outDir": "./dist/",
|
||||
"incremental": true
|
||||
"outDir": "./dist/"
|
||||
},
|
||||
"exclude": ["src/**/*.test.ts"],
|
||||
"include": ["src/**/*"]
|
||||
|
||||
Reference in New Issue
Block a user