diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-12-06 08:06:59 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-12-06 08:11:35 -0400 |
commit | 19b832b91b882293f0b145941961c880671fddef (patch) | |
tree | ad919d7a2f7e25253af83dfc12b789c40285d684 /src | |
parent | 6c22ef3ede69956d7381bed1f9fa0aa286f9dd63 (diff) |
expose more utilities to REPL
Diffstat (limited to 'src')
-rw-r--r-- | src/repl.js | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/repl.js b/src/repl.js index 5497ef55..a60d7809 100644 --- a/src/repl.js +++ b/src/repl.js @@ -3,8 +3,16 @@ import * as path from 'path'; import * as repl from 'repl'; import {quickLoadAllFromYAML} from './data/yaml.js'; -import {logError, parseOptions} from './util/cli.js'; +import {logError, logWarn, parseOptions} from './util/cli.js'; import {showAggregate} from './util/sugar.js'; +import {generateURLs} from './util/urls.js'; + +import * as serialize from './util/serialize.js'; +import * as sugar from './util/sugar.js'; +import * as wikiDataUtils from './util/wiki-data.js'; +import _find, {bindFind} from './util/find.js'; + +import urlSpec from './url-spec.js'; async function main() { const miscOptions = await parseOptions(process.argv.slice(2), { @@ -30,7 +38,39 @@ async function main() { const wikiData = await quickLoadAllFromYAML(dataPath); const replServer = repl.start(); - Object.assign(replServer.context, wikiData, {wikiData, WD: wikiData}); + let urls; + try { + urls = generateURLs(urlSpec); + } catch (error) { + console.error(error); + logWarn`Failed to generate URL mappings for built-in urlSpec`; + logWarn`\`urls\` variable will be missing`; + } + + let find; + try { + find = bindFind(wikiData); + } catch (error) { + console.error(error); + logWarn`Failed to prepare wikiData-bound find() functions`; + logWarn`\`find\` variable will be missing`; + } + + Object.assign(replServer.context, wikiData, { + wikiData, + WD: wikiData, + + serialize, + S: serialize, + + _find, + find, + bindFind, + urls, + + ...sugar, + ...wikiDataUtils, + }); if (disableHistory) { console.log(`\rInput history disabled (--no-history provided)`); |