scripts / fix-install-assets.js
"use strict";
// `lms dev --install` bundles the TS source but doesn't know to carry along
// runtime data files that aren't imported by any module — namely the OCR
// language file. Without it in the installed plugin's directory, tesseract.js
// falls back to fetching it from the network on first OCR run.
const fs = require("node:fs");
const path = require("node:path");
const os = require("node:os");
const projectRoot = path.resolve(__dirname, "..");
const manifest = JSON.parse(fs.readFileSync(path.join(projectRoot, "manifest.json"), "utf8"));
const installDir = path.join(
os.homedir(),
".lmstudio",
"extensions",
"plugins",
manifest.owner,
manifest.name,
);
if (!fs.existsSync(installDir)) {
console.error(`[fix-install-assets] Install directory not found: ${installDir}`);
console.error(`[fix-install-assets] Run "lms dev --install -y" first.`);
process.exit(1);
}
// Known OCR language files, kept in sync with scripts/download-languages.js.
// copy all that exist locally into the install dir so tesseract.js never has
// to download them from the network on first OCR run.
const assets = ["eng.traineddata", "rus.traineddata"];
let copied = 0;
for (const asset of assets) {
const src = path.join(projectRoot, asset);
const dest = path.join(installDir, asset);
if (!fs.existsSync(src)) {
console.warn(`[fix-install-assets] Skipping missing asset: ${asset}. Run "npm run download" first.`);
continue;
}
fs.copyFileSync(src, dest);
console.log(`[fix-install-assets] Copied ${asset} -> ${dest}`);
copied++;
}
if (copied === 0) {
console.warn("[fix-install-assets] No OCR language files found in the project root.");
}
scripts / fix-install-assets.js
"use strict";
// `lms dev --install` bundles the TS source but doesn't know to carry along
// runtime data files that aren't imported by any module — namely the OCR
// language file. Without it in the installed plugin's directory, tesseract.js
// falls back to fetching it from the network on first OCR run.
const fs = require("node:fs");
const path = require("node:path");
const os = require("node:os");
const projectRoot = path.resolve(__dirname, "..");
const manifest = JSON.parse(fs.readFileSync(path.join(projectRoot, "manifest.json"), "utf8"));
const installDir = path.join(
os.homedir(),
".lmstudio",
"extensions",
"plugins",
manifest.owner,
manifest.name,
);
if (!fs.existsSync(installDir)) {
console.error(`[fix-install-assets] Install directory not found: ${installDir}`);
console.error(`[fix-install-assets] Run "lms dev --install -y" first.`);
process.exit(1);
}
// Known OCR language files, kept in sync with scripts/download-languages.js.
// copy all that exist locally into the install dir so tesseract.js never has
// to download them from the network on first OCR run.
const assets = ["eng.traineddata", "rus.traineddata"];
let copied = 0;
for (const asset of assets) {
const src = path.join(projectRoot, asset);
const dest = path.join(installDir, asset);
if (!fs.existsSync(src)) {
console.warn(`[fix-install-assets] Skipping missing asset: ${asset}. Run "npm run download" first.`);
continue;
}
fs.copyFileSync(src, dest);
console.log(`[fix-install-assets] Copied ${asset} -> ${dest}`);
copied++;
}
if (copied === 0) {
console.warn("[fix-install-assets] No OCR language files found in the project root.");
}