diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-03-04 18:00:10 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-03-04 18:00:10 -0400 |
commit | 06e1503a921ca28c4d4f994ee46a3044acfb3a32 (patch) | |
tree | a6d150ce782582b963850a4e6b2598f4bdd5d0d9 | |
parent | 79b233cab5853b50717ffb281247485e26101ef0 (diff) |
boot directly into REPL with --repl
-rw-r--r-- | src/repl.js | 73 | ||||
-rwxr-xr-x | src/upd8.js | 33 |
2 files changed, 82 insertions, 24 deletions
diff --git a/src/repl.js b/src/repl.js index f6f78bf0..f9996453 100644 --- a/src/repl.js +++ b/src/repl.js @@ -22,6 +22,8 @@ import urlSpec from './url-spec.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); export async function getContextAssignments({ + dataPath, + mediaPath, wikiData, }) { let urls; @@ -56,6 +58,9 @@ export async function getContextAssignments({ } return { + dataPath, + mediaPath, + wikiData, ...wikiData, WD: wikiData, @@ -77,30 +82,22 @@ export async function getContextAssignments({ }; } -async function main() { - const miscOptions = await parseOptions(process.argv.slice(2), { - 'data-path': { - type: 'value', - }, - - 'no-history': { - type: 'flag', - }, - - 'show-traces': { - type: 'flag', - }, - }); - - const dataPath = miscOptions['data-path'] || process.env.HSMUSIC_DATA; - const disableHistory = miscOptions['no-history'] ?? false; - const showTraces = miscOptions['show-traces'] ?? false; - +export default async function bootRepl({ + dataPath = process.env.HSMUSIC_DATA, + mediaPath = process.env.HSMUSIC_MEDIA, + disableHistory = false, + showTraces = false, +}) { if (!dataPath) { logError`Expected --data-path option or HSMUSIC_DATA to be set`; return; } + if (!mediaPath) { + logError`Expected --media-path option or HSMUSIC_MEDIA to be set`; + return; + } + console.log('HSMusic data REPL'); const wikiData = await quickLoadAllFromYAML(dataPath, { @@ -117,23 +114,55 @@ async function main() { })); if (disableHistory) { - console.log(`\rInput history disabled (--no-history provided)`); + console.log(`\rInput history disabled (--no-repl-history provided)`); replServer.displayPrompt(true); } else { const historyFile = path.join(os.homedir(), '.hsmusic_repl_history'); replServer.setupHistory(historyFile, (err) => { if (err) { console.error( - `\rFailed to begin locally logging input history to ${historyFile} (provide --no-history to disable)` + `\rFailed to begin locally logging input history to ${historyFile} (provide --no-repl-history to disable)` ); } else { console.log( - `\rLogging input history to ${historyFile} (provide --no-history to disable)` + `\rLogging input history to ${historyFile} (provide --no-repl-history to disable)` ); } replServer.displayPrompt(true); }); } + + // Is this called breaking a promise? + await new Promise(() => {}); + + return true; +} + +async function main() { + const miscOptions = await parseOptions(process.argv.slice(2), { + 'data-path': { + type: 'value', + }, + + 'media-path': { + type: 'value', + }, + + 'no-repl-history': { + type: 'flag', + }, + + 'show-traces': { + type: 'flag', + }, + }); + + return bootRepl({ + dataPath: miscOptions['data-path'], + mediaPath: miscOptions['media-path'], + disableHistory: miscOptions['no-repl-history'], + showTraces: miscOptions['show-traces'], + }); } if (isMain(import.meta.url)) { diff --git a/src/upd8.js b/src/upd8.js index 2b4fb5f6..9fff67cc 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -41,6 +41,8 @@ import genThumbs, { defaultMagickThreads, isThumb, } from './gen-thumbs.js'; + +import bootRepl from './repl.js'; import {listingSpec, listingTargetSpec} from './listing-spec.js'; import urlSpec from './url-spec.js'; @@ -126,7 +128,6 @@ async function main() { if (empty(selectedBuildModeFlags)) { selectedBuildModeFlag = 'static-build'; usingDefaultBuildMode = true; - logInfo`No build mode specified, using default: ${selectedBuildModeFlag}`; } else if (selectedBuildModeFlags.length > 1) { logError`Building multiple modes (${selectedBuildModeFlags.join(', ')}) at once not supported.`; logError`Please specify a maximum of one build mode.`; @@ -134,7 +135,6 @@ async function main() { } else { selectedBuildModeFlag = selectedBuildModeFlags[0]; usingDefaultBuildMode = false; - logInfo`Using specified build mode: ${selectedBuildModeFlag}`; } const selectedBuildMode = buildModes[selectedBuildModeFlag]; @@ -184,6 +184,16 @@ async function main() { type: 'value', }, + 'repl': { + help: `Boot into the HSMusic REPL for command-line interactive access to data objects`, + type: 'flag', + }, + + 'no-repl-history': { + help: `Disable locally logging commands entered into the REPL in your home directory`, + type: 'flag', + }, + // Thum8nail gener8tion is *usually* something you want, 8ut it can 8e // kinda a pain to run every time, since it does necessit8te reading // every media file at run time. Pass this to skip it. @@ -367,6 +377,9 @@ async function main() { const clearThumbsFlag = cliOptions['clear-thumbs'] ?? false; const noBuild = cliOptions['no-build'] ?? false; + const replFlag = cliOptions['repl'] ?? false; + const disableReplHistory = cliOptions['no-repl-history'] ?? false; + const showAggregateTraces = cliOptions['show-traces'] ?? false; const precacheData = cliOptions['precache-data'] ?? false; @@ -394,6 +407,16 @@ async function main() { } } + if (replFlag) { + return bootRepl({ + dataPath, + mediaPath, + + disableHistory: disableReplHistory, + showTraces: showAggregateTraces, + }); + } + const niceShowAggregate = (error, ...opts) => { showAggregate(error, { showTraces: showAggregateTraces, @@ -431,6 +454,12 @@ async function main() { if (thumbsOnly) return; } + if (usingDefaultBuildMode) { + logInfo`No build mode specified, using default: ${selectedBuildModeFlag}`; + } else { + logInfo`Using specified build mode: ${selectedBuildModeFlag}`; + } + if (showInvalidPropertyAccesses) { CacheableObject.DEBUG_SLOW_TRACK_INVALID_PROPERTIES = true; } |