mume-with-litvis
Version:
Fork of mume with added http://litvis.org/
116 lines • 5.42 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExtensionConfigPath = exports.onDidChangeConfigFile = exports.init = exports.MarkdownEngine = exports.configs = exports.utility = void 0;
/**
* The core of mume package.
*/
const fs = require("fs");
const path = require("path");
const mkdirp = require("mkdirp");
const utility_ = require("./utility");
let INITIALIZED = false;
let CONFIG_CHANGE_CALLBACK = null;
exports.utility = utility_;
exports.configs = exports.utility.configs;
var markdown_engine_1 = require("./markdown-engine");
Object.defineProperty(exports, "MarkdownEngine", { enumerable: true, get: function () { return markdown_engine_1.MarkdownEngine; } });
let extensionConfigPath = exports.utility.getConfigPath();
/**
* init mume config folder at ~/.config/mume
*/
function init(configPath = null) {
return __awaiter(this, void 0, void 0, function* () {
if (INITIALIZED) {
return;
}
configPath = configPath ? path.resolve(configPath) : exports.utility.getConfigPath();
extensionConfigPath = configPath;
if (!fs.existsSync(configPath)) {
mkdirp.sync(configPath);
}
exports.configs.globalStyle = yield exports.utility.getGlobalStyles(configPath);
exports.configs.mermaidConfig = yield exports.utility.getMermaidConfig(configPath);
exports.configs.mathjaxConfig = yield exports.utility.getMathJaxConfig(configPath);
exports.configs.katexConfig = yield exports.utility.getKaTeXConfig(configPath);
exports.configs.parserConfig = yield exports.utility.getParserConfig(configPath);
exports.configs.config = yield exports.utility.getExtensionConfig(configPath);
fs.watch(configPath, (eventType, fileName) => {
if (eventType === "change") {
if (fileName === "style.less") {
// || fileName==='mermaid_config.js' || fileName==='mathjax_config')
exports.utility.getGlobalStyles(configPath).then((css) => {
exports.configs.globalStyle = css;
if (CONFIG_CHANGE_CALLBACK) {
CONFIG_CHANGE_CALLBACK();
}
});
}
else if (fileName === "mermaid_config.js") {
exports.utility.getMermaidConfig(configPath).then((mermaidConfig) => {
exports.configs.mermaidConfig = mermaidConfig;
if (CONFIG_CHANGE_CALLBACK) {
CONFIG_CHANGE_CALLBACK();
}
});
}
else if (fileName === "mathjax_config.js") {
exports.utility.getMathJaxConfig(configPath).then((mathjaxConfig) => {
exports.configs.mathjaxConfig = mathjaxConfig;
if (CONFIG_CHANGE_CALLBACK) {
CONFIG_CHANGE_CALLBACK();
}
});
}
else if (fileName === "katex_config.js") {
exports.utility.getKaTeXConfig(configPath).then((katexConfig) => {
exports.configs.katexConfig = katexConfig;
if (CONFIG_CHANGE_CALLBACK) {
CONFIG_CHANGE_CALLBACK();
}
});
}
else if (fileName === "parser.js") {
exports.utility.getParserConfig(configPath).then((parserConfig) => {
exports.configs.parserConfig = parserConfig;
if (CONFIG_CHANGE_CALLBACK) {
CONFIG_CHANGE_CALLBACK();
}
});
}
else if (fileName === "config.json") {
exports.utility.getExtensionConfig(configPath).then((config) => {
exports.configs.config = config;
if (CONFIG_CHANGE_CALLBACK) {
CONFIG_CHANGE_CALLBACK();
}
});
}
}
});
INITIALIZED = true;
return;
});
}
exports.init = init;
/**
* cb will be called when global style.less like files is changed.
* @param cb function(error, css){}
*/
function onDidChangeConfigFile(cb) {
CONFIG_CHANGE_CALLBACK = cb;
}
exports.onDidChangeConfigFile = onDidChangeConfigFile;
function getExtensionConfigPath() {
return extensionConfigPath;
}
exports.getExtensionConfigPath = getExtensionConfigPath;
//# sourceMappingURL=mume.js.map