diff options
-rw-r--r-- | src/data/language.js | 40 | ||||
-rw-r--r-- | src/repl.js | 2 | ||||
-rwxr-xr-x | src/upd8.js | 50 |
3 files changed, 45 insertions, 47 deletions
diff --git a/src/data/language.js b/src/data/language.js new file mode 100644 index 00000000..da9528f2 --- /dev/null +++ b/src/data/language.js @@ -0,0 +1,40 @@ +import {readFile} from 'fs/promises'; + +// It stands for "HTML Entities", apparently. Cursed. +import he from 'he'; + +import T from './things/index.js'; + +// TODO: define somewhere besides upd8.js obviously +export async function processLanguageFile(file) { + const contents = await readFile(file, 'utf-8'); + const json = JSON.parse(contents); + + const code = json['meta.languageCode']; + if (!code) { + throw new Error(`Missing language code (file: ${file})`); + } + delete json['meta.languageCode']; + + const intlCode = json['meta.languageIntlCode'] ?? null; + delete json['meta.languageIntlCode']; + + const name = json['meta.languageName']; + if (!name) { + throw new Error(`Missing language name (${code})`); + } + delete json['meta.languageName']; + + const hidden = json['meta.hidden'] ?? false; + delete json['meta.hidden']; + + const language = new T.Language(); + language.code = code; + language.intlCode = intlCode; + language.name = name; + language.hidden = hidden; + language.escapeHTML = (string) => + he.encode(string, {useNamedReferences: true}); + language.strings = json; + return language; +} diff --git a/src/repl.js b/src/repl.js index 08e83a5c..69e2fe05 100644 --- a/src/repl.js +++ b/src/repl.js @@ -10,7 +10,7 @@ import {isMain} from './util/node-utils.js'; import {bindOpts, showAggregate} from './util/sugar.js'; import {generateURLs} from './util/urls.js'; -import {processLanguageFile} from './upd8.js'; +import {processLanguageFile} from './data/language.js'; import * as serialize from './util/serialize.js'; import * as sugar from './util/sugar.js'; diff --git a/src/upd8.js b/src/upd8.js index a70864de..0de724f2 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -34,15 +34,11 @@ import * as path from 'path'; import {fileURLToPath} from 'url'; -// It stands for "HTML Entities", apparently. Cursed. -import he from 'he'; - import chroma from 'chroma-js'; import { copyFile, mkdir, - readFile, stat, symlink, writeFile, @@ -64,10 +60,9 @@ import {isMain} from './util/node-utils.js'; import CacheableObject from './data/things/cacheable-object.js'; +import {processLanguageFile} from './data/language.js'; import {serializeThings} from './data/serialize.js'; -import T from './data/things/index.js'; - import { filterDuplicateDirectories, filterReferenceErrors, @@ -1602,45 +1597,6 @@ function generateRedirectHTML(title, target, {language}) { ]); } -// TODO: define somewhere besides upd8.js obviously -export async function processLanguageFile(file) { - const contents = await readFile(file, 'utf-8'); - const json = JSON.parse(contents); - - const code = json['meta.languageCode']; - if (!code) { - throw new Error(`Missing language code (file: ${file})`); - } - delete json['meta.languageCode']; - - const intlCode = json['meta.languageIntlCode'] ?? null; - delete json['meta.languageIntlCode']; - - const name = json['meta.languageName']; - if (!name) { - throw new Error(`Missing language name (${code})`); - } - delete json['meta.languageName']; - - const hidden = json['meta.hidden'] ?? false; - delete json['meta.hidden']; - - if (json['meta.baseDirectory']) { - logWarn`(${code}) Language JSON still has unused meta.baseDirectory`; - delete json['meta.baseDirectory']; - } - - const language = new T.Language(); - language.code = code; - language.intlCode = intlCode; - language.name = name; - language.hidden = hidden; - language.escapeHTML = (string) => - he.encode(string, {useNamedReferences: true}); - language.strings = json; - return language; -} - // Wrapper function for running a function once for all languages. async function wrapLanguages(fn, {languages, writeOneLanguage = null}) { const k = writeOneLanguage; @@ -2616,7 +2572,9 @@ async function main() { logInfo`Written!`; } -if (isMain(import.meta.url) || path.basename(process.argv[1]) === 'hsmusic') { +// TODO: isMain detection isn't consistent across platforms here +/* eslint-disable-next-line no-constant-condition */ +if (true || isMain(import.meta.url) || path.basename(process.argv[1]) === 'hsmusic') { main() .catch((error) => { if (error instanceof AggregateError) { |