2023-04-03 11:04:32 +00:00
|
|
|
import { ftlToJSON } from "ftl-tx";
|
|
|
|
import fs from 'fs-extra';
|
|
|
|
import { dirname, join } from 'path';
|
|
|
|
import { fileURLToPath } from 'url';
|
2023-05-29 10:02:09 +00:00
|
|
|
import { ftlFileBaseNames as sourceFileBaseNames } from './config.js';
|
|
|
|
import { onError, onProgress, onSuccess } from './utils.js';
|
2023-04-03 11:04:32 +00:00
|
|
|
|
|
|
|
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
|
|
|
|
|
|
async function getJSON() {
|
|
|
|
const t1 = performance.now();
|
2023-04-13 05:22:29 +00:00
|
|
|
const sourceDir = join(ROOT, 'chrome', 'locale', 'en-US', 'zotero');
|
2023-05-29 10:02:09 +00:00
|
|
|
for (let sourceFileBaseName of sourceFileBaseNames) {
|
|
|
|
const sourceFile = join(sourceDir, sourceFileBaseName + '.ftl');
|
|
|
|
const destFile = join(sourceDir, sourceFileBaseName + '.json');
|
|
|
|
const ftl = await fs.readFile(sourceFile, 'utf8');
|
|
|
|
const json = ftlToJSON(ftl, { transformTerms: false, storeTermsInJSON: false });
|
|
|
|
await fs.outputJSON(destFile, json, { spaces: '\t' });
|
|
|
|
onProgress(destFile, destFile, 'json');
|
|
|
|
}
|
2023-04-03 11:04:32 +00:00
|
|
|
const t2 = performance.now();
|
2023-05-29 10:02:09 +00:00
|
|
|
return ({
|
|
|
|
action: 'ftl->json',
|
|
|
|
count: sourceFileBaseNames.length,
|
|
|
|
totalCount: sourceFileBaseNames.length,
|
|
|
|
processingTime: t2 - t1
|
|
|
|
});
|
2023-04-03 11:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
|
|
(async () => {
|
|
|
|
try {
|
|
|
|
onSuccess(await getJSON());
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
process.exitCode = 1;
|
|
|
|
global.isError = true;
|
|
|
|
onError(err);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|