From e858e91c85bb3a17f88079cf9a6745147da59059 Mon Sep 17 00:00:00 2001 From: Samual Date: Sun, 21 Apr 2024 18:05:52 +0100 Subject: [PATCH] style and minor changes --- src/bin/hsm.ts | 614 ++++++++++++-------------- src/generateTypeDeclaration.ts | 2 +- src/index.ts | 7 +- src/processScript/index.ts | 129 +++--- src/processScript/minify.ts | 297 +++++-------- src/processScript/postprocess.ts | 38 +- src/processScript/preprocess.ts | 27 +- src/processScript/shared.ts | 40 +- src/processScript/transform.ts | 736 ++++++++++++------------------- src/pull.ts | 18 +- src/push.ts | 191 ++++---- src/syncMacros.ts | 13 +- src/watch.ts | 146 +++--- 13 files changed, 955 insertions(+), 1303 deletions(-) diff --git a/src/bin/hsm.ts b/src/bin/hsm.ts index 297fd6f..d681443 100755 --- a/src/bin/hsm.ts +++ b/src/bin/hsm.ts @@ -10,11 +10,8 @@ import { writeFilePersistent } from "@samual/lib/writeFilePersistent" import { mkdir as makeDirectory, readFile, rmdir as removeDirectory, 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 + basename as getPathBaseName, dirname as getPathDirectory, extname as getPathFileExtension, + relative as getRelativePath, resolve as resolvePath } from "path" import type { Info } from ".." import { version as moduleVersion } from "../../package.json" @@ -23,7 +20,7 @@ import generateTypeDeclaration from "../generateTypeDeclaration" import pull from "../pull" import syncMacros from "../syncMacros" -type ArgumentValue = boolean | number | string/* | ArgValue[]*/ +type ArgumentValue = boolean | number | string type Config = Partial<{ hackmudPath: string }> & Record const configDirectoryPath = resolvePath(getHomeDirectory(), `.config`) @@ -50,245 +47,7 @@ Go up 2 directories and then copy the path Then in a terminal run "${colourC(`hsm`)} ${colourL(`config set`)} ${colourV(`hackmudPath`)} ${colourB(``)}"` )) -const 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 configCommandDescription = `Modify and view the config file` - const configGetCommandDescription = `Retrieve a value from the config file` - const configSetCommandDescription = `Assign a value to the config file` - const configDeleteCommandDescription = `Remove a key and value from the config file` - 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. Use ${colourN(`--force-quine-cheats`)}=${colourV(`false`)} to force off` - - console.log(colourN(`Version`) + colourS(`: `) + colourV(moduleVersion)) - - switch (commands[0]) { - case `config`: { - switch (commands[1]) { - case `get`: { - console.log(` -${colourJ(configGetCommandDescription)} - -${colourA(`Usage:`)} -${colourC(`hsm`)} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB(``)}` - ) - } break - - case `set`: { - console.log(` -${colourJ(configSetCommandDescription)} - -${colourA(`Usage:`)} -${colourC(`hsm`)} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB(` `)}` - ) - } break - - case `delete`: { - console.log(` -${colourJ(configDeleteCommandDescription)} - -${colourA(`Usage:`)} -${colourC(`hsm`)} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB(``)}` - ) - } break - - default: { - console.log(colourS(`\ -${colourN(`Config path`)}: ${colourV(configFilePath)} - -${colourJ(`Modify the config file`)} - -${colourA(`Usage:`)} -${colourC(`hsm`)} ${colourL(`${commands[0]} get`)} ${colourB(``)} - ${configGetCommandDescription} -${colourC(`hsm`)} ${colourL(`${commands[0]} set`)} ${colourB(` `)} - ${configSetCommandDescription} -${colourC(`hsm`)} ${colourL(`${commands[0]} delete`)} ${colourB(``)} - ${configDeleteCommandDescription}` - )) - } - } - } break - - case `dev`: - case `watch`: - case `push`: { - console.log(colourS(` -${colourJ(commands[0] == `push` ? pushCommandDescription : watchCommandDescription)} - -${colourA(`Usage:`)} -${colourC(`hsm`)} ${colourL(commands[0])} ${colourB(` ["