[ESM] Convert the "cmaps"-task to use import() syntax

This commit is contained in:
Jonas Jenwald 2023-07-08 14:35:15 +02:00
parent 42edc4d895
commit f012fc5e70
4 changed files with 20 additions and 14 deletions

View File

@ -13,10 +13,10 @@
* limitations under the License.
*/
const fs = require("fs");
const path = require("path");
const parseAdobeCMap = require("./parse.js").parseAdobeCMap;
const optimizeCMap = require("./optimize.js").optimizeCMap;
import fs from "fs";
import { optimizeCMap } from "./optimize.mjs";
import { parseAdobeCMap } from "./parse.mjs";
import path from "path";
function compressCmap(srcPath, destPath, verify) {
const content = fs.readFileSync(srcPath).toString();
@ -469,7 +469,7 @@ function incHex(a) {
return s;
}
exports.compressCmaps = function (src, dest, verify) {
function compressCmaps(src, dest, verify) {
const files = fs.readdirSync(src).filter(function (fn) {
return !fn.includes("."); // skipping files with the extension
});
@ -489,4 +489,6 @@ exports.compressCmaps = function (src, dest, verify) {
"%"
);
});
};
}
export { compressCmaps };

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
exports.optimizeCMap = function (data) {
function optimizeCMap(data) {
let i = 1;
while (i < data.body.length) {
if (data.body[i - 1].type === data.body[i].type) {
@ -206,7 +206,7 @@ exports.optimizeCMap = function (data) {
}
i++;
}
};
}
function incHex(a) {
let c = 1,
@ -223,3 +223,5 @@ function incHex(a) {
}
return s;
}
export { optimizeCMap };

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
exports.parseAdobeCMap = function (content) {
function parseAdobeCMap(content) {
let m = /(\bbegincmap\b[\s\S]*?)\bendcmap\b/.exec(content);
if (!m) {
throw new Error("cmap was not found");
@ -100,4 +100,6 @@ exports.parseAdobeCMap = function (content) {
}
return result;
};
}
export { parseAdobeCMap };

View File

@ -848,7 +848,7 @@ gulp.task("locale", function () {
]);
});
gulp.task("cmaps", function (done) {
gulp.task("cmaps", async function () {
const CMAP_INPUT = "external/cmaps";
const VIEWER_CMAP_OUTPUT = "external/bcmaps";
@ -869,10 +869,10 @@ gulp.task("cmaps", function (done) {
}
});
const compressCmaps =
require("./external/cmapscompress/compress.js").compressCmaps;
const { compressCmaps } = await import(
"./external/cmapscompress/compress.mjs"
);
compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true);
done();
});
function preprocessCSS(source, defines) {