From fbd1d8c94fa75defd6cc9f4ee0770d4a4734c9e7 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Wed, 28 Jan 2026 05:29:43 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Add=20SSHHostConfig=20t?= =?UTF-8?q?ypedef=20and=20improve=20argument=20parsing=20with=20validation?= =?UTF-8?q?=20for=20target?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/utils/deploy-pokedex.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/code/utils/deploy-pokedex.js b/code/utils/deploy-pokedex.js index 259b592..fce537a 100644 --- a/code/utils/deploy-pokedex.js +++ b/code/utils/deploy-pokedex.js @@ -29,6 +29,16 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Configuration +/** + * @typedef {Object} SSHHostConfig + * @property {string} host + * @property {number} port + * @property {string} username + * @property {string} privateKeyPath + * @property {string} password + */ + +/** @type {Record<'internal'|'external', SSHHostConfig>} */ const SSH_HOSTS = { internal: { host: '10.0.0.81', @@ -55,8 +65,12 @@ const DIST_DIR = path.join(SOURCE_DIR, 'dist'); * Parse command line arguments * @returns {Object} Parsed arguments */ +/** + * @returns {{ target: keyof typeof SSH_HOSTS, port: number, sslPort: number|null }} + */ function parseArgs() { const args = process.argv.slice(2); + /** @type {{ target: keyof typeof SSH_HOSTS, port: number, sslPort: number|null }} */ const config = { target: 'internal', port: 8080, @@ -65,7 +79,15 @@ function parseArgs() { for (let i = 0; i < args.length; i++) { if (args[i] === '--target' && args[i + 1]) { - config.target = args[i + 1]; + /** @type {any} */ + const t = args[i + 1]; + if (t === 'internal' || t === 'external') { + config.target = t; + } else { + throw new Error( + `Invalid target: ${t}. Must be 'internal' or 'external'.` + ); + } i++; } else if (args[i] === '--port' && args[i + 1]) { config.port = parseInt(args[i + 1], 10); @@ -76,13 +98,6 @@ function parseArgs() { } } - // Validate target - if (!SSH_HOSTS[config.target]) { - throw new Error( - `Invalid target: ${config.target}. Must be 'internal' or 'external'.` - ); - } - // Validate port if (isNaN(config.port) || config.port < 1 || config.port > 65535) { throw new Error(