diff --git a/src/argv.ts b/src/argv.ts new file mode 100644 index 00000000..0a29f903 --- /dev/null +++ b/src/argv.ts @@ -0,0 +1,3 @@ +import minimist from 'minimist' + +export const argv = minimist(process.argv.slice(2)) diff --git a/src/commands.ts b/src/commands.ts index 96a9cb13..f34f88e1 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -6,13 +6,14 @@ import _ from 'lodash' import { getUpdates, update } from './update' import { openAdmin } from './listen' import yaml from 'yaml' -import { argv, BUILD_TIMESTAMP, VERSION } from './const' +import { BUILD_TIMESTAMP, VERSION } from './const' import { createInterface } from 'readline' import { getAvailablePlugins, mapPlugins, startPlugin, stopPlugin } from './plugins' import { purgeFileAttr } from './fileAttr' import { downloadPlugin } from './github' import { Dict, formatBytes, formatSpeed, formatTimestamp, makeMatcher } from './cross' import apiMonitor from './api.monitor' +import { argv } from './argv' if (!argv.updating) try { diff --git a/src/config.ts b/src/config.ts index fc1471d9..a18e58c7 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,6 @@ // This file is part of HFS - Copyright 2021-2023, Massimo Melina - License https://www.gnu.org/licenses/gpl-3.0.txt -import { argv, ORIGINAL_CWD, VERSION, CONFIG_FILE } from './const' +import { ORIGINAL_CWD, VERSION, CONFIG_FILE } from './const' import { watchLoad } from './watchLoad' import yaml from 'yaml' import _ from 'lodash' @@ -10,6 +10,7 @@ import { join, resolve } from 'path' import events from './events' import { copyFile, stat } from 'fs/promises' import produce, { setAutoFreeze } from 'immer' +import { argv } from './argv' setAutoFreeze(false) // we still want to mess with objects later (eg: account.belongs) diff --git a/src/consoleLog.ts b/src/consoleLog.ts index de0234a2..15fef76f 100644 --- a/src/consoleLog.ts +++ b/src/consoleLog.ts @@ -1,7 +1,7 @@ import events from './events' import { formatTime, formatTimestamp } from './cross' import { createWriteStream } from 'fs' -import { argv } from './const' +import { argv } from './argv' export const consoleLog: Array<{ ts: Date, k: string, msg: string }> = [] const f = argv.consoleFile ? createWriteStream(argv.consoleFile, 'utf-8') : null diff --git a/src/const.ts b/src/const.ts index 09438686..acca60f1 100644 --- a/src/const.ts +++ b/src/const.ts @@ -6,12 +6,12 @@ import { homedir } from 'os' import _ from 'lodash' import { basename, dirname, join } from 'path' import { formatTimestamp } from './cross' +import { argv } from './argv' export * from './cross-const' export const API_VERSION = 10.3 export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION -export const argv = minimist(process.argv.slice(2)) // you can add arguments with this file, currently used for the update process on mac/linux export const ARGS_FILE = join(homedir(), 'hfs-args') try { diff --git a/src/github.ts b/src/github.ts index f5eb5fb4..1ad01260 100644 --- a/src/github.ts +++ b/src/github.ts @@ -11,13 +11,14 @@ import { import { ApiError } from './apiMiddleware' import _ from 'lodash' import { - argv, HFS_REPO, HFS_REPO_BRANCH, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_FORBIDDEN, HTTP_NOT_ACCEPTABLE, + HFS_REPO, HFS_REPO_BRANCH, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_FORBIDDEN, HTTP_NOT_ACCEPTABLE, HTTP_SERVER_ERROR, VERSION } from './const' import { rename, rm } from 'fs/promises' import { join } from 'path' import { readFileSync } from 'fs' import { storedMap } from './persistence' +import { argv } from './argv' const DIST_ROOT = 'dist' diff --git a/src/listen.ts b/src/listen.ts index 2f5eb263..7ec65dde 100644 --- a/src/listen.ts +++ b/src/listen.ts @@ -11,7 +11,7 @@ import open from 'open' import { CFG, debounceAsync, ipForUrl, makeNetMatcher, MINUTE, objSameKeys, onlyTruthy, prefix, runAt, wait, xlate } from './misc' -import { PORT_DISABLED, ADMIN_URI, argv, DEV, IS_WINDOWS } from './const' +import { PORT_DISABLED, ADMIN_URI, DEV, IS_WINDOWS } from './const' import findProcess from 'find-process' import { anyAccountCanLoginAdmin } from './adminApis' import _ from 'lodash' @@ -20,6 +20,7 @@ import events from './events' import { isIPv6 } from 'net' import { defaultBaseUrl } from './nat' import { storedMap } from './persistence' +import { argv } from './argv' interface ServerExtra { name: string, error?: string, busy?: Promise } let httpSrv: undefined | http.Server & ServerExtra diff --git a/src/update.ts b/src/update.ts index 58f66b97..9248d8a8 100644 --- a/src/update.ts +++ b/src/update.ts @@ -1,7 +1,7 @@ // This file is part of HFS - Copyright 2021-2023, Massimo Melina - License https://www.gnu.org/licenses/gpl-3.0.txt import { getProjectInfo, getRepoInfo } from './github' -import { ARGS_FILE, argv, HFS_REPO, IS_BINARY, IS_WINDOWS, RUNNING_BETA } from './const' +import { ARGS_FILE, HFS_REPO, IS_BINARY, IS_WINDOWS, RUNNING_BETA } from './const' import { dirname, join } from 'path' import { spawn, spawnSync } from 'child_process' import { DAY, exists, debounceAsync, httpStream, unzip, prefix, xlate, HOUR } from './misc' @@ -15,6 +15,7 @@ import { cmdEscape, RUNNING_AS_SERVICE } from './util-os' import { onProcessExit } from './first' import { storedMap } from './persistence' import _ from 'lodash' +import { argv } from './argv' const updateToBeta = defineConfig('update_to_beta', false) const autoCheckUpdate = defineConfig('auto_check_update', true)