plac-micro-common 1.3.8 → 1.3.9
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.
|
@@ -40,11 +40,23 @@ const ejs = __importStar(require("ejs"));
|
|
|
40
40
|
let cached_font_base64 = null;
|
|
41
41
|
const cached_templates = {};
|
|
42
42
|
function getAssetsRootPath() {
|
|
43
|
-
|
|
43
|
+
const shared_entry_path = require.resolve("plac-micro-common/shared");
|
|
44
|
+
const shared_dist_dir = path.dirname(shared_entry_path);
|
|
45
|
+
// shared entry = dist/shared/index.js
|
|
46
|
+
// assets root = dist/assets
|
|
47
|
+
return path.resolve(shared_dist_dir, "..", "assets");
|
|
44
48
|
}
|
|
45
49
|
function getFontBase64() {
|
|
46
50
|
if (!cached_font_base64) {
|
|
47
51
|
const font_path = path.join(getAssetsRootPath(), "fonts", "KhmerOS.ttf");
|
|
52
|
+
if (!fs.existsSync(font_path)) {
|
|
53
|
+
throw new Error([
|
|
54
|
+
"[generateFormSIO] Font not found",
|
|
55
|
+
`shared_entry: ${require.resolve("plac-micro-common/shared")}`,
|
|
56
|
+
`assets_root: ${getAssetsRootPath()}`,
|
|
57
|
+
`font_path: ${font_path}`,
|
|
58
|
+
].join("\n"));
|
|
59
|
+
}
|
|
48
60
|
const font_buffer = fs.readFileSync(font_path);
|
|
49
61
|
cached_font_base64 = font_buffer.toString("base64");
|
|
50
62
|
}
|
|
@@ -55,6 +67,15 @@ function getTemplate(lang) {
|
|
|
55
67
|
const template_path = lang === "en"
|
|
56
68
|
? path.join(getAssetsRootPath(), "templates", "sio-form-en.ejs")
|
|
57
69
|
: path.join(getAssetsRootPath(), "templates", "sio-form-kh.ejs");
|
|
70
|
+
if (!fs.existsSync(template_path)) {
|
|
71
|
+
throw new Error([
|
|
72
|
+
"[generateFormSIO] Template not found",
|
|
73
|
+
`lang: ${lang}`,
|
|
74
|
+
`shared_entry: ${require.resolve("plac-micro-common/shared")}`,
|
|
75
|
+
`assets_root: ${getAssetsRootPath()}`,
|
|
76
|
+
`template_path: ${template_path}`,
|
|
77
|
+
].join("\n"));
|
|
78
|
+
}
|
|
58
79
|
const template = fs.readFileSync(template_path, "utf8");
|
|
59
80
|
cached_templates[lang] = ejs.compile(template);
|
|
60
81
|
}
|