plac-micro-common 1.3.6 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,21 +39,15 @@ const path = __importStar(require("path"));
|
|
|
39
39
|
const ejs = __importStar(require("ejs"));
|
|
40
40
|
let cached_font_base64 = null;
|
|
41
41
|
const cached_templates = {};
|
|
42
|
+
function getPackageRootPath() {
|
|
43
|
+
return path.resolve(__dirname, "..", "..", "..");
|
|
44
|
+
}
|
|
42
45
|
function getAssetsRootPath() {
|
|
43
|
-
return path.join(
|
|
46
|
+
return path.join(getPackageRootPath(), "dist", "assets");
|
|
44
47
|
}
|
|
45
48
|
function getFontBase64() {
|
|
46
49
|
if (!cached_font_base64) {
|
|
47
|
-
const
|
|
48
|
-
const font_path = path.join(assets_root, "fonts", "KhmerOS.ttf");
|
|
49
|
-
if (!fs.existsSync(font_path)) {
|
|
50
|
-
throw new Error([
|
|
51
|
-
"[generateFormSIO] Font not found",
|
|
52
|
-
`__dirname: ${__dirname}`,
|
|
53
|
-
`assets_root: ${assets_root}`,
|
|
54
|
-
`font_path: ${font_path}`,
|
|
55
|
-
].join("\n"));
|
|
56
|
-
}
|
|
50
|
+
const font_path = path.join(getAssetsRootPath(), "fonts", "KhmerOS.ttf");
|
|
57
51
|
const font_buffer = fs.readFileSync(font_path);
|
|
58
52
|
cached_font_base64 = font_buffer.toString("base64");
|
|
59
53
|
}
|
|
@@ -61,19 +55,9 @@ function getFontBase64() {
|
|
|
61
55
|
}
|
|
62
56
|
function getTemplate(lang) {
|
|
63
57
|
if (!cached_templates[lang]) {
|
|
64
|
-
const assets_root = getAssetsRootPath();
|
|
65
58
|
const template_path = lang === "en"
|
|
66
|
-
? path.join(
|
|
67
|
-
: path.join(
|
|
68
|
-
if (!fs.existsSync(template_path)) {
|
|
69
|
-
throw new Error([
|
|
70
|
-
"[generateFormSIO] Template not found",
|
|
71
|
-
`lang: ${lang}`,
|
|
72
|
-
`__dirname: ${__dirname}`,
|
|
73
|
-
`assets_root: ${assets_root}`,
|
|
74
|
-
`template_path: ${template_path}`,
|
|
75
|
-
].join("\n"));
|
|
76
|
-
}
|
|
59
|
+
? path.join(getAssetsRootPath(), "templates", "sio-form-en.ejs")
|
|
60
|
+
: path.join(getAssetsRootPath(), "templates", "sio-form-kh.ejs");
|
|
77
61
|
const template = fs.readFileSync(template_path, "utf8");
|
|
78
62
|
cached_templates[lang] = ejs.compile(template);
|
|
79
63
|
}
|