From c7eb72e73b09ddf7f02f355086cbdbe29ceb66c3 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Thu, 5 Jan 2023 19:57:28 +0000 Subject: [PATCH] JSDoc for extra/ Signed-off-by: Matthew Nickson --- extra/beta/update-version.js | 13 +++++++++++++ extra/download-cloudflared.js | 4 ++++ extra/remove-2fa.js | 5 +++++ extra/reset-password.js | 5 +++++ extra/simple-dns-server.js | 5 +++++ extra/simple-mqtt-server.js | 1 + extra/update-version.js | 17 +++++++++-------- extra/update-wiki-version.js | 8 ++++++++ 8 files changed, 50 insertions(+), 8 deletions(-) diff --git a/extra/beta/update-version.js b/extra/beta/update-version.js index df2cb40a..7abac5ef 100644 --- a/extra/beta/update-version.js +++ b/extra/beta/update-version.js @@ -32,6 +32,10 @@ if (! exists) { process.exit(1); } +/** + * Commit updated files + * @param {string} version Version to update to + */ function commit(version) { let msg = "Update to " + version; @@ -47,6 +51,10 @@ function commit(version) { console.log(res.stdout.toString().trim()); } +/** + * Create a tag with the specified version + * @param {string} version Tag to create + */ function tag(version) { let res = childProcess.spawnSync("git", [ "tag", version ]); console.log(res.stdout.toString().trim()); @@ -55,6 +63,11 @@ function tag(version) { console.log(res.stdout.toString().trim()); } +/** + * Check if a tag exists for the specified version + * @param {string} version Version to check + * @returns {boolean} Does the tag already exist + */ function tagExists(version) { if (! version) { throw new Error("invalid version"); diff --git a/extra/download-cloudflared.js b/extra/download-cloudflared.js index 41519b7c..74b9bad2 100644 --- a/extra/download-cloudflared.js +++ b/extra/download-cloudflared.js @@ -25,6 +25,10 @@ if (platform === "linux/amd64") { const file = fs.createWriteStream("cloudflared.deb"); get("https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-" + arch + ".deb"); +/** + * Download specified file + * @param {string} url URL to request + */ function get(url) { http.get(url, function (res) { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { diff --git a/extra/remove-2fa.js b/extra/remove-2fa.js index 0f3f6346..f88c43fc 100644 --- a/extra/remove-2fa.js +++ b/extra/remove-2fa.js @@ -43,6 +43,11 @@ const main = async () => { console.log("Finished."); }; +/** + * Ask question of user + * @param {string} question Question to ask + * @returns {Promise} Users response + */ function question(question) { return new Promise((resolve) => { rl.question(question, (answer) => { diff --git a/extra/reset-password.js b/extra/reset-password.js index 8036a456..16898331 100644 --- a/extra/reset-password.js +++ b/extra/reset-password.js @@ -53,6 +53,11 @@ const main = async () => { console.log("Finished."); }; +/** + * Ask question of user + * @param {string} question Question to ask + * @returns {Promise} Users response + */ function question(question) { return new Promise((resolve) => { rl.question(question, (answer) => { diff --git a/extra/simple-dns-server.js b/extra/simple-dns-server.js index 376dbdd0..a6946dcb 100644 --- a/extra/simple-dns-server.js +++ b/extra/simple-dns-server.js @@ -135,6 +135,11 @@ server.listen({ udp: 5300 }); +/** + * Get human readable request type from request code + * @param {number} code Request code to translate + * @returns {string} Human readable request type + */ function type(code) { for (let name in Packet.TYPE) { if (Packet.TYPE[name] === code) { diff --git a/extra/simple-mqtt-server.js b/extra/simple-mqtt-server.js index 238d2772..b970a380 100644 --- a/extra/simple-mqtt-server.js +++ b/extra/simple-mqtt-server.js @@ -11,6 +11,7 @@ class SimpleMqttServer { this.port = port; } + /** Start the MQTT server */ start() { this.server.listen(this.port, () => { console.log("server started and listening on port ", this.port); diff --git a/extra/update-version.js b/extra/update-version.js index d5c2ee5c..246e1c1c 100644 --- a/extra/update-version.js +++ b/extra/update-version.js @@ -36,10 +36,8 @@ if (! exists) { } /** - * Updates the version number in package.json and commits it to git. - * @param {string} version - The new version number - * - * Generated by Trelent + * Commit updated files + * @param {string} version Version to update to */ function commit(version) { let msg = "Update to " + version; @@ -53,16 +51,19 @@ function commit(version) { } } +/** + * Create a tag with the specified version + * @param {string} version Tag to create + */ function tag(version) { let res = childProcess.spawnSync("git", [ "tag", version ]); console.log(res.stdout.toString().trim()); } /** - * Checks if a given version is already tagged in the git repository. - * @param {string} version - The version to check for. - * - * Generated by Trelent + * Check if a tag exists for the specified version + * @param {string} version Version to check + * @returns {boolean} Does the tag already exist */ function tagExists(version) { if (! version) { diff --git a/extra/update-wiki-version.js b/extra/update-wiki-version.js index 65b7e7b0..880bc556 100644 --- a/extra/update-wiki-version.js +++ b/extra/update-wiki-version.js @@ -10,6 +10,10 @@ if (!newVersion) { updateWiki(newVersion); +/** + * Update the wiki with new version number + * @param {string} newVersion Version to update to + */ function updateWiki(newVersion) { const wikiDir = "./tmp/wiki"; const howToUpdateFilename = "./tmp/wiki/🆙-How-to-Update.md"; @@ -39,6 +43,10 @@ function updateWiki(newVersion) { safeDelete(wikiDir); } +/** + * Check if a directory exists before deleting + * @param {string} dir Directory to delete + */ function safeDelete(dir) { if (fs.existsSync(dir)) { fs.rm(dir, {