Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/hackmud-script-manager. Script manager for game hackmud, with minification, TypeScrip www.npmjs.com/package/hackmud-script-manager
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755#!/usr/bin/env node/* eslint-disable no-console */import type { Replace } from "@samual/lib"import type { Info } from ".."import { readFile, writeFile } from "fs/promises"import { homedir as getHomeDirectory } from "os"import { basename as getPathBaseName, dirname as getPathDirectory, extname as getPathFileExtension, relative as getRelativePath, resolve as resolvePath} from "path"import { assert } from "@samual/lib/assert"import { AutoMap } from "@samual/lib/AutoMap"import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"import { writeFilePersistent } from "@samual/lib/writeFilePersistent"import { version as moduleVersion } from "../../package.json"import { supportedExtensions } from "../constants"import { generateTypeDeclaration } from "../generateTypeDeclaration"import { pull } from "../pull"import { syncMacros } from "../syncMacros"
type OptionValue = boolean | string
const options = new Map<string, OptionValue>const commands: string[] = []let didParseOption = falselet didParseOptionAfterCommand = false
for (const argument of process.argv.slice(2)) { if (argument[0] == `-`) { const argumentEqualsIndex = argument.indexOf(`=`) let key let value
if (argumentEqualsIndex == -1) { key = argument value = true } else { key = argument.slice(0, argumentEqualsIndex) value = argument.slice(argumentEqualsIndex + 1)
if (value == `true`) value = true else if (value == `false`) value = false }
if (argument[1] == `-`) options.set(key!.slice(2), value) else { for (const option of key!.slice(1)) options.set(option, value) }
didParseOption = true } else { if (didParseOption) { didParseOptionAfterCommand = true }
commands.push(argument) }}
const pushModule = import(`../push`)const processScriptModule = import(`../processScript`)const watchModule = import(`../watch`)const chokidarModule = import(`chokidar`)const { default: chalk } = await import(`chalk`)const colourA = chalk.rgb(0xFF, 0xFF, 0xFF)const colourB = chalk.rgb(0xCA, 0xCA, 0xCA)const colourC = chalk.rgb(0x9B, 0x9B, 0x9B)const colourD = chalk.rgb(0xFF, 0x00, 0x00)const colourF = chalk.rgb(0xFF, 0x80, 0x00)const colourJ = chalk.rgb(0xFF, 0xF4, 0x04)const colourK = chalk.rgb(0xF3, 0xF9, 0x98)const colourL = chalk.rgb(0x1E, 0xFF, 0x00)const colourM = chalk.rgb(0xB3, 0xFF, 0x9B)const colourN = chalk.rgb(0x00, 0xFF, 0xFF)const colourS = chalk.rgb(0x7A, 0xB2, 0xF4)const colourV = chalk.rgb(0xFF, 0x00, 0xEC)const colourW = chalk.rgb(0xFF, 0x96, 0xE0)const formatOption = (name: string) => colourN(`-${name.length == 1 ? `` : `-`}${name}`)
const userColours = new AutoMap<string, string>(user => { let hash = 0
for (const char of user) hash += (hash >> 1) + hash + `xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj`.indexOf(char) + 1
return [ colourJ, colourK, colourM, colourW, colourL, colourB ][hash % 6]!(user)})
const log = (message: string) => console.log(colourS(message))
if (didParseOptionAfterCommand) { process.exitCode = 1
console.warn(colourF(`\${chalk.bold(`Warning:`)} Options should come after commands when calling the script. This warning will become an error in the next minor version of HSM.` ))}
if (process.version.startsWith(`v21.`)) { process.exitCode = 1
console.warn(colourF(`\${chalk.bold(`Warning:`)} Support for Node.js 21 will be dropped in the next minor version of HSM Your current version of Node.js is ${chalk.bold(process.version)} You should update your version of Node.js https://nodejs.org/en/download/package-manager\n` ))}
if (commands[0] == `v` || commands[0] == `version` || popOption(`version`, `v`)?.value) { console.log(moduleVersion) process.exit()}
let warnedDeprecatedEmitDtsAlias = false
if (popOption(`help`, `h`)?.value) { logHelp() process.exit()}
let autoExit = true
switch (commands[0]) { case `push`: case `dev`: case `watch`: case `golf`: case `minify`: { const noMinifyOption = popOption(`no-minify`, `skip-minify`)
if (noMinifyOption && noMinifyOption.name != `no-minify`) { process.exitCode = 1
console.warn(colourF(`\${chalk.bold(`Warning:`)} ${formatOption(noMinifyOption.name)} is deprecated and will be removed in the next minor release of HSM You should switch to using its alias ${colourN(`--no-minify`)}\n` )) }
const mangleNamesOption = popOption(`mangle-names`) const forceQuineCheatsOption = popOption(`force-quine-cheats`) const noQuineCheatsOptions = popOption(`no-quine-cheats`) const noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
if (noMinifyOption && noMinifyIncompatibleOption) { logError( `Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name) } are incompatible\n` )
logHelp() process.exit(1) }
if (forceQuineCheatsOption && noQuineCheatsOptions) { logError( `Options ${formatOption(forceQuineCheatsOption.name)} and ${formatOption(noQuineCheatsOptions.name) } are incompatible\n` )
logHelp() process.exit(1) }
if (noMinifyOption) assertOptionIsBoolean(noMinifyOption)
if (mangleNamesOption) assertOptionIsBoolean(mangleNamesOption)
if (forceQuineCheatsOption) assertOptionIsBoolean(forceQuineCheatsOption)
if (noQuineCheatsOptions) assertOptionIsBoolean(noQuineCheatsOptions)
const rootFolderPathOption = popOption(`root-folder-path`) const rootFolderPath = rootFolderPathOption && resolvePath(String(rootFolderPathOption.value))
if (commands[0] == `golf` || commands[0] == `minify`) { const watchOption = popOption(`watch`) const target = commands[1]
if (!target) { logError(`Must provide target\n`) logHelp() process.exit(1) }
const fileExtension = getPathFileExtension(target)
if (!supportedExtensions.includes(fileExtension)) { logError(`Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${ supportedExtensions.map(extension => chalk.bold(extension)).join(`", "`) }"`)
process.exit(1) }
complainAboutUnrecognisedOptions()
const { processScript } = await processScriptModule const fileBaseName = getPathBaseName(target, fileExtension) const fileBaseNameEndsWithDotSrc = fileBaseName.endsWith(`.src`) const scriptName = fileBaseNameEndsWithDotSrc ? fileBaseName.slice(0, -4) : fileBaseName
const scriptUser = ( getPathBaseName(resolvePath(target, `..`)) == `scripts` && getPathBaseName(resolvePath(target, `../../..`)) == `hackmud` ) ? getPathBaseName(resolvePath(target, `../..`)) : undefined
let outputPath = commands[2] || resolvePath( getPathDirectory(target), fileBaseNameEndsWithDotSrc ? `${scriptName}.js` : fileExtension == `.js` ? `${fileBaseName}.min.js` : `${fileBaseName}.js` )
const golfFile = () => readFile(target, { encoding: `utf8` }).then(async source => { const timeStart = performance.now()
const { script, warnings } = await processScript(source, { minify: noMinifyOption && !noMinifyOption.value, scriptUser, scriptName, filePath: target, mangleNames: mangleNamesOption?.value, forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value, rootFolderPath })
const timeTook = performance.now() - timeStart
if (warnings.length) process.exitCode = 1
for (const { message } of warnings) console.warn(colourF(`${chalk.bold(`Warning:`)} ${message}`))
await writeFilePersistent(outputPath, script).catch((error: NodeJS.ErrnoException) => { if (!commands[2] || error.code != `EISDIR`) throw error
outputPath = resolvePath(outputPath, `${getPathBaseName(target, fileExtension)}.js`)
return writeFilePersistent(outputPath, script) }).then(() => log(`Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${ chalk.bold(getRelativePath(`.`, outputPath)) } | took ${Math.round(timeTook * 100) / 100}ms`)) })
if (watchOption) { const { watch: watchFile } = await chokidarModule
watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } }) .on(`ready`, () => log(`Watching ${target}`)) .on(`change`, golfFile)
autoExit = false } else await golfFile() } else { const hackmudPath = getHackmudPath() const sourcePath = commands[1]
if (!sourcePath) { logError(`Must provide the directory to ${commands[0] == `push` ? `push from` : `watch`}\n`) logHelp() process.exit(1) }
const scripts = commands.slice(2)
if (scripts.length) { const invalidScript = scripts .find(script => !/^(?:[a-z_][a-z\d_]{0,24}|\*)\.(?:[a-z_][a-z\d_]{0,24}|\*)$/.test(script))
if (invalidScript) { logError(`Invalid script name: ${JSON.stringify(invalidScript)}\n`) logHelp() process.exit(1) } } else scripts.push(`*.*`)
const watchOption = popOption(`watch`)
if (commands[0] == `push` && !watchOption?.value) { const dtsPathOption = popOption(`dts-path`)
complainAboutUnrecognisedOptions()
let declarationPathPromise
if (dtsPathOption) { if (typeof dtsPathOption.value != `string`) { logError( `Option ${formatOption(dtsPathOption.name)} must be a string, got ${colourV(dtsPathOption.value)}\n` )
logHelp() process.exit(1) }
let typeDeclarationPath = resolvePath(dtsPathOption.value) const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration).catch(error => { assert(error instanceof Error, HERE)
if ((error as NodeJS.ErrnoException).code != `EISDIR`) throw error
typeDeclarationPath = resolvePath(typeDeclarationPath, `player.d.ts`)
return writeFile(typeDeclarationPath, typeDeclaration) }).then(() => typeDeclarationPath) }
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule
const infos = await push(sourcePath, hackmudPath, { scripts, onPush: info => logInfo(info, hackmudPath), minify: noMinifyOption && !noMinifyOption.value, mangleNames: mangleNamesOption?.value, forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value, rootFolderPath })
if (infos instanceof Error) { logError(infos.message)
if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) { console.log() logHelp() } else if (infos instanceof MissingHackmudFolderError) { log(`\If this is not where your hackmud folder is, you can specify it with the${colourN(`--hackmud-path`)}=${colourB(`<path>`)} option or ${colourN(`HSM_HACKMUD_PATH`)} environment variable` ) } } else if (!infos.length) logError(`Could not find any scripts to push`)
if (declarationPathPromise) log(`Wrote type declaration to ${chalk.bold(await declarationPathPromise)}`) } else { const dtsPathOption = popOption(`dts-path`, `type-declaration-path`, `type-declaration`, `dts`, `gen-types`)
if (dtsPathOption && dtsPathOption.name != `dts-path` && dtsPathOption.name != `type-declaration-path`) { process.exitCode = 1
console.warn(colourF(`\${chalk.bold(`Warning:`)} ${formatOption(dtsPathOption.name)} is deprecated and will be removed in the next minor release of HSM You should switch to using its alias ${colourN(`--dts-path`)}\n` )) }
complainAboutUnrecognisedOptions()
const { watch } = await watchModule
watch(sourcePath, hackmudPath, { scripts, onPush: info => logInfo(info, hackmudPath), typeDeclarationPath: dtsPathOption?.value.toString(), minify: noMinifyOption && !noMinifyOption.value, mangleNames: mangleNamesOption?.value, onReady: () => log(`Watching`), forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value, rootFolderPath })
autoExit = false } }
break }
case `pull`: { const hackmudPath = getHackmudPath() const script = commands[1]
if (!script) { logError(`Must provide the script to pull\n`) logHelp() process.exit(1) }
complainAboutUnrecognisedOptions()
const sourcePath = commands[2] || `.`
await pull(sourcePath, hackmudPath, script).catch(error => { console.error(error) logError(`Something went wrong, did you forget to ${colourC(`#down`)} the script?`) })
break }
case `sync-macros`: { const hackmudPath = getHackmudPath()
complainAboutUnrecognisedOptions()
const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
log(`Synced ${macrosSynced} macros to ${usersSynced} users`) break }
case `generate-type-declaration`: case `gen-type-declaration`: case `gen-dts`: case `gen-types`: case `emit-dts`: { if (commands[0] != `emit-dts` && commands[0] != `gen-dts`) { warnedDeprecatedEmitDtsAlias = true process.exitCode = 1
console.warn(colourF(`\${chalk.bold(`Warning:`)} ${colourC(`hsm`)} ${colourL(commands[0])} is deprecated and will be removed in the next minor release of HSM You should switch to using its alias ${colourC(`hsm`)} ${colourL(`emit-dts`)}\n` )) }
const hackmudPath = getHackmudPath() const target = commands[1]
if (!target) { logError(`Must provide target directory\n`) logHelp() process.exit(1) }
complainAboutUnrecognisedOptions()
const sourcePath = resolvePath(target) const outputPath = commands[2] || `./player.d.ts`
const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
let typeDeclarationPath = resolvePath(outputPath)
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => { assert(error instanceof Error, HERE)
if ((error as NodeJS.ErrnoException).code != `EISDIR`) throw error
typeDeclarationPath = resolvePath(typeDeclarationPath, `player.d.ts`)
return writeFile(typeDeclarationPath, typeDeclaration) })
log(`Wrote type declaration to ${chalk.bold(typeDeclarationPath)}`) break }
case `help`: logHelp() break
default: { if (commands[0]) logError(`Unknown command: ${colourL(commands[0])}\n`)
logHelp() }}
if (autoExit) process.exit()
function logHelp() { const pushCommandDescription = `Push scripts from a directory to hackmud user's scripts directories` const watchCommandDescription = `Watch a directory and push a script when modified` const minifyCommandDescription = `Minify a script file on the spot` const generateTypeDeclarationCommandDescription = `Generate a type declaration file for a directory of scripts` const syncMacrosCommandDescription = `Sync macros across all hackmud users` const pullCommandDescription = `Pull a script a from a hackmud user's script directory` const noMinifyOptionDescription = `Skip minification to produce a "readable" script` const mangleNamesOptionDescription = `Reduce character count further but lose function names in error call stacks` const forceQuineCheatsOptionDescription = `Force quine cheats on or off`
const hackmudPathOption = `\${colourN(`--hackmud-path`)}=${colourB(`<path>`)} Override hackmud path`
switch (commands[0]) { case `dev`: case `watch`: case `push`: console.log(colourS(`\${colourJ(commands[0] == `push` ? pushCommandDescription : watchCommandDescription)}
${colourA(`Usage:`)}${colourC(`hsm`)} ${colourL(commands[0])} ${colourB(`<directory> ["<script user>.<script name>"...]`)}
${colourA(`Arguments:`)}${colourB(`<directory>`)} The source directory containing your scripts${colourB(`<script user>`)} A user to push script(s) to. Can be set to wild card (${colourV(`*`)}) which will try and discover users to push to${colourB(`<script name>`)} Name of a script to push. Can be set to wild card (${colourV(`*`)}) to find all scripts
${colourA(`Options:`)}${colourN(`--no-minify`)} ${noMinifyOptionDescription}${colourN(`--mangle-names`)} ${mangleNamesOptionDescription}${colourN(`--force-quine-cheats`)}, ${colourN(`--no-quine-cheats`)} ${forceQuineCheatsOptionDescription}${hackmudPathOption}${colourN(`--dts-path`)}=${colourB(`<path>`)} Path to generate a type declaration (.d.ts) file for the scripts${colourN(`--watch`)} Watch for changes${colourN(`--root-folder-path`)} The folder that root will be aliased to in import statements
${colourA(`Examples:`)}${colourC(`hsm`)} ${colourL(commands[0])} ${colourV(`src`)} Pushes all scripts found in ${colourV(`src`)} folder to all users${colourC(`hsm`)} ${colourL(commands[0])} ${colourV(`src`)} ${colourC(`foo`)}${colourV(`.`)}${colourL(`bar`)} Pushes a script named ${colourL(`bar`)} found in ${colourV(`src`)} folder to user ${userColours.get(`foo`)}${colourC(`hsm`)} ${colourL(commands[0])} ${colourV(`src`)} ${colourC(`foo`)}${colourV(`.`)}${colourL(`bar`)} ${colourC(`baz`)}${colourV(`.`)}${colourL(`qux`)} Multiple can be specified${colourC(`hsm`)} ${colourL(commands[0])} ${colourV(`src`)} ${colourC(`foo`)}${colourV(`.`)}${colourL(`*`)} Pushes all scripts found in ${colourV(`src`)} folder to user ${userColours.get(`foo`)}${colourC(`hsm`)} ${colourL(commands[0])} ${colourV(`src`)} ${colourC(`*`)}${colourV(`.`)}${colourL(`foo`)} Pushes all scripts named ${colourL(`foo`)} found in ${colourV(`src`)} folder to all user${colourC(`hsm`)} ${colourL(commands[0])} ${colourV(`src`)} ${colourC(`*`)}${colourV(`.`)}${colourL(`*`)} Pushes all scripts found in ${colourV(`src`)} folder to all users` ))
break
case `pull`: console.log(colourS(`\${colourJ(pullCommandDescription)}
${colourA(`Usage:`)}${colourC(`hsm`)} ${colourL(commands[0])} ${colourB(`<script user>`)}${colourV(`.`)}${colourB(`<script name>`)}
${colourA(`Options:`)}${hackmudPathOption}` ))
break
case `minify`: case `golf`: console.log(colourS(`\${colourJ(minifyCommandDescription)}
${colourA(`Usage:`)}${colourC(`hsm`)} ${colourL(commands[0])} ${colourB(`<target> [output path]`)}
${colourA(`Options:`)}${colourN(`--no-minify`)} ${noMinifyOptionDescription}${colourN(`--mangle-names`)} ${mangleNamesOptionDescription}${colourN(`--force-quine-cheats`)}, ${colourN(`--no-quine-cheats`)} ${forceQuineCheatsOptionDescription}${colourN(`--watch`)} Watch for changes${colourN(`--root-folder-path`)} The folder that root will be aliased to in import statements` ))
break
case `generate-type-declaration`: case `gen-type-declaration`: case `gen-dts`: case `gen-types`: case `emit-dts`: if (!warnedDeprecatedEmitDtsAlias && commands[0] != `emit-dts` && commands[0] != `gen-dts`) { process.exitCode = 1
console.warn(colourF(`\${chalk.bold(`Warning:`)} ${colourC(`hsm`)} ${colourL(commands[0])} is deprecated and will be removed in the next minor release of HSM You should switch to using its alias ${colourC(`hsm`)} ${colourL(`emit-dts`)}\n` )) }
console.log(colourS(`\${colourJ(generateTypeDeclarationCommandDescription)}
${colourA(`Usage:`)}${colourC(`hsm`)} ${colourL(commands[0])} ${colourB(`<directory> [output path]`)}
${colourA(`Options:`)}${hackmudPathOption}` ))
break
case `sync-macros`: console.log(colourS(`\${colourJ(syncMacrosCommandDescription)}
${colourA(`Options:`)}${hackmudPathOption}` ))
break
default: { console.log(colourS(`\${colourJ(`Hackmud Script Manager`)}${colourN(`Version`) + colourS(`: `) + colourV(moduleVersion)}
${colourA(`Commands:`)}${colourL(`push`)} ${pushCommandDescription}${colourL(`minify`)} ${minifyCommandDescription}${colourL(`emit-dts`)} ${generateTypeDeclarationCommandDescription}${colourL(`sync-macros`)} ${syncMacrosCommandDescription}${colourL(`pull`)} ${pullCommandDescription}
${colourA(`Options:`)}${colourN(`--help`)} Can be used on any command e.g. ${colourC(`hsm`)} ${colourL(`push`)} ${colourN(`--help`)} to show helpful information` )) } }}
function logInfo({ path, users, characterCount, error, warnings }: Info, hackmudPath: string) { path = getRelativePath(`.`, path)
if (error) { logError(`Error "${chalk.bold(error.message)}" in ${chalk.bold(path)}`)
return }
if (warnings.length) process.exitCode = 1
for (const warning of warnings) console.warn(colourF(`${chalk.bold(`Warning:`)} ${warning.message}`))
log(`Pushed ${chalk.bold(path)} to ${users.map(user => chalk.bold(userColours.get(user))).join(`, `)} | ${ chalk.bold(String(characterCount)) } chars | ${chalk.bold( `${resolvePath(hackmudPath!, users[0]!, `scripts`, getPathBaseName(path, getPathFileExtension(path)))}.js` )}`)}
function logError(message: string) { console.error(colourD(message)) process.exitCode = 1}
function getHackmudPath() { const hackmudPathOption = popOption(`hackmud-path`)
if (hackmudPathOption) { if (typeof hackmudPathOption.value != `string`) { logError(`Option ${colourN(`--hackmud-path`)} must be a string, got ${colourV(hackmudPathOption.value)}\n`) logHelp() process.exit(1) }
if (!hackmudPathOption.value) { logError(`Option ${colourN(`--hackmud-path`)} was specified but empty\n`) logHelp() process.exit(1) }
return hackmudPathOption.value }
if (process.env.HSM_HACKMUD_PATH != undefined) { if (!process.env.HSM_HACKMUD_PATH) { logError(`Environment variable ${colourN(`HSM_HACKMUD_PATH`)} was specified but empty\n`) logHelp() process.exit(1) }
return process.env.HSM_HACKMUD_PATH }
return process.platform == `win32` ? resolvePath(process.env.APPDATA!, `hackmud`) : resolvePath(getHomeDirectory(), `.config/hackmud`)}
type Option = { name: string, value: OptionValue }
function assertOptionIsBoolean(option: Option): asserts option is Replace<Option, { value: boolean }> { if (typeof option.value != `boolean`) { logError(`The value for ${formatOption(option.name)} must be ${colourV(`true`)} or ${colourV(`false`)}\n`) logHelp() process.exit(1) }}
function popOption(...names: string[]): Option | undefined { const presentOptionNames = names.filter(name => options.has(name))
if (!presentOptionNames.length) return undefined
if (presentOptionNames.length > 1) { logError(`The options ${presentOptionNames.map(formatOption).join(`, `) } are aliases for each other. Please only specify one`)
process.exit(1) }
const value = options.get(presentOptionNames[0]!)!
options.delete(presentOptionNames[0]!)
return { name: presentOptionNames[0]!, value }}
function complainAboutUnrecognisedOptions(): void { if (options.size) { logError( `Unrecognised option${options.size > 1 ? `s` : ``}: ${[ ...options.keys() ].map(formatOption).join(`, `)}` )
process.exit(1) }}