mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-08 20:48:41 +00:00
Upgrade the source to use ES6 syntax including classes, import and static properties (#679)
* Add babel transform-class-properties to have static class properties * Upgrade Lexer and Parser files to use ES6 classes * Update eslint max line length to 90 character (more indent because of using ES6 classes) * Upgrade eslint and jasmin to support ES stage-2 features * Use static properties to place constants near their functions * Migrate all remaining sources to ES6 syntax * Increase eslint max line length to 84 * Remove non-babelified endpoint in dev server.js * Clean up server.js functions after removing browserified * Make screenshotter not to use babel endpoint as we babelify everything now
This commit is contained in:
committed by
Kevin Barabash
parent
0edd3d1bbb
commit
a019f36f8a
41
server.js
41
server.js
@@ -15,7 +15,7 @@ if (require.main === module) {
|
||||
":date[iso] :method :url HTTP/:http-version - :status"));
|
||||
}
|
||||
|
||||
function serveBrowserified(file, standaloneName, doBabelify) {
|
||||
function serveBrowserified(file, standaloneName) {
|
||||
return function(req, res, next) {
|
||||
let files;
|
||||
if (Array.isArray(file)) {
|
||||
@@ -26,10 +26,9 @@ function serveBrowserified(file, standaloneName, doBabelify) {
|
||||
files = [path.join(__dirname, file)];
|
||||
}
|
||||
|
||||
const options = {};
|
||||
if (doBabelify) {
|
||||
options.transform = [babelify];
|
||||
}
|
||||
const options = {
|
||||
transform: [babelify],
|
||||
};
|
||||
if (standaloneName) {
|
||||
options.standalone = standaloneName;
|
||||
}
|
||||
@@ -46,30 +45,24 @@ function serveBrowserified(file, standaloneName, doBabelify) {
|
||||
};
|
||||
}
|
||||
|
||||
function twoBrowserified(url, file, standaloneName) {
|
||||
app.get(url, serveBrowserified(file, standaloneName, false));
|
||||
app.get("/babel" + url, serveBrowserified(file, standaloneName, true));
|
||||
function browserified(url, file, standaloneName) {
|
||||
app.get(url, serveBrowserified(file, standaloneName));
|
||||
}
|
||||
|
||||
function twoUse(url, handler) {
|
||||
app.use(url, handler);
|
||||
app.use("/babel" + url, handler);
|
||||
function getStatic(url, file) {
|
||||
app.use(url, express.static(path.join(__dirname, file)));
|
||||
}
|
||||
|
||||
function twoStatic(url, file) {
|
||||
twoUse(url, express.static(path.join(__dirname, file)));
|
||||
}
|
||||
|
||||
twoBrowserified("/katex.js", "katex", "katex");
|
||||
twoUse("/test/jasmine", express.static(path.dirname(
|
||||
browserified("/katex.js", "katex", "katex");
|
||||
app.use("/test/jasmine", express.static(path.dirname(
|
||||
require.resolve("jasmine-core/lib/jasmine-core/jasmine.js"))));
|
||||
twoBrowserified("/test/katex-spec.js", "test/*[Ss]pec.js");
|
||||
twoBrowserified(
|
||||
browserified("/test/katex-spec.js", "test/*[Ss]pec.js");
|
||||
browserified(
|
||||
"/contrib/auto-render/auto-render.js",
|
||||
"contrib/auto-render/auto-render",
|
||||
"renderMathInElement");
|
||||
|
||||
twoUse("/katex.css", function(req, res, next) {
|
||||
app.use("/katex.css", function(req, res, next) {
|
||||
const lessfile = path.join(__dirname, "static", "katex.less");
|
||||
fs.readFile(lessfile, {encoding: "utf8"}, function(err, data) {
|
||||
if (err) {
|
||||
@@ -93,10 +86,10 @@ twoUse("/katex.css", function(req, res, next) {
|
||||
});
|
||||
});
|
||||
|
||||
twoStatic("", "static");
|
||||
twoStatic("", "build");
|
||||
twoStatic("/test", "test");
|
||||
twoStatic("/contrib", "contrib");
|
||||
getStatic("", "static");
|
||||
getStatic("", "build");
|
||||
getStatic("/test", "test");
|
||||
getStatic("/contrib", "contrib");
|
||||
|
||||
app.use(function(err, req, res, next) {
|
||||
console.error(err.stack);
|
||||
|
Reference in New Issue
Block a user