From 19b832b91b882293f0b145941961c880671fddef Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 6 Dec 2022 08:06:59 -0400 Subject: expose more utilities to REPL --- src/repl.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file 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)`); -- cgit 1.3.0-6-gf8a5