Handle multiple Fluent source files

With list specified in js-build/config.js
This commit is contained in:
Dan Stillman 2023-05-29 06:02:09 -04:00 committed by Dan Stillman
parent 0de1305665
commit 086399da33
3 changed files with 78 additions and 56 deletions

View file

@ -2,25 +2,29 @@ import { ftlToJSON } from "ftl-tx";
import fs from 'fs-extra';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { onError, onSuccess } from './utils.js';
import { ftlFileBaseNames as sourceFileBaseNames } from './config.js';
import { onError, onProgress, onSuccess } from './utils.js';
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
async function getJSON() {
const t1 = performance.now();
const sourceDir = join(ROOT, 'chrome', 'locale', 'en-US', 'zotero');
const sourceFile = join(sourceDir, 'zotero.ftl');
const destFile = join(sourceDir, 'zotero.json');
const ftl = await fs.readFile(sourceFile, 'utf8');
const json = ftlToJSON(ftl, { transformTerms: false, storeTermsInJSON: false });
await fs.outputJSON(destFile, json, { spaces: '\t' });
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');
}
const t2 = performance.now();
return ({
action: 'ftl->json',
count: 1,
totalCount: 1,
processingTime: t2 - t1
});
return ({
action: 'ftl->json',
count: sourceFileBaseNames.length,
totalCount: sourceFileBaseNames.length,
processingTime: t2 - t1
});
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {