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/**/*
|
!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(
|
fs.writeFileSync(
|
||||||
path.join(ROOT_DIR, "src", "extensions", "code-block", "languages.json"),
|
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 path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import { readFile, writeFile } from "fs/promises";
|
import { cp, readFile, writeFile } from "fs/promises";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
const ROOT_DIR = path.resolve(path.join(__dirname, ".."));
|
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 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.");
|
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");
|
let ICON_FILE = await readFile(bundle.path, "utf-8");
|
||||||
const icons = ICON_FILE.matchAll(/: (mdi.+),/g);
|
const icons =
|
||||||
for (const icon of icons) {
|
bundle.type === "cjs"
|
||||||
const iconPath = Mjs[icon[1]];
|
? ICON_FILE.matchAll(/: _js\.(mdi.+),/g)
|
||||||
if (!iconPath) throw new Error(`Could not find path for icon: ${icon[1]}.`);
|
: ICON_FILE.matchAll(/: (mdi.+),/g);
|
||||||
ICON_FILE = ICON_FILE.replace(icon[0], `: "${iconPath}",`);
|
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, "");
|
await cp(path.resolve(ROOT_DIR, "styles"), path.resolve(DIST_DIR, "styles"), {
|
||||||
|
recursive: true
|
||||||
console.log("Saving file...");
|
});
|
||||||
|
|
||||||
await writeFile(ICONS_FILE_PATH, ICON_FILE);
|
|
||||||
|
|
||||||
console.log("Done.");
|
console.log("Done.");
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"outDir": "./dist/",
|
"outDir": "./dist/"
|
||||||
"incremental": true
|
|
||||||
},
|
},
|
||||||
"exclude": ["src/**/*.test.ts"],
|
"exclude": ["src/**/*.test.ts"],
|
||||||
"include": ["src/**/*"]
|
"include": ["src/**/*"]
|
||||||
|
|||||||
Reference in New Issue
Block a user