Refactor Code to typescript
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
export function grabAuthDirs(): {
|
||||
root: string;
|
||||
auth: string;
|
||||
};
|
||||
export function initAuthFiles(): boolean;
|
||||
/**
|
||||
* # Write Auth Files
|
||||
* @param {string} name
|
||||
* @param {string} data
|
||||
*/
|
||||
export function writeAuthFile(name: string, data: string): boolean;
|
||||
/**
|
||||
* # Get Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
export function getAuthFile(name: string): string;
|
||||
/**
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
export function deleteAuthFile(name: string): void;
|
||||
/**
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
export function checkAuthFile(name: string): boolean;
|
||||
+13
-25
@@ -1,9 +1,7 @@
|
||||
// @ts-check
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const grabAuthDirs = () => {
|
||||
export const grabAuthDirs = () => {
|
||||
const DSQL_AUTH_DIR = process.env.DSQL_AUTH_DIR;
|
||||
const ROOT_DIR = DSQL_AUTH_DIR?.match(/./)
|
||||
? DSQL_AUTH_DIR
|
||||
@@ -13,7 +11,7 @@ const grabAuthDirs = () => {
|
||||
return { root: ROOT_DIR, auth: AUTH_DIR };
|
||||
};
|
||||
|
||||
const initAuthFiles = () => {
|
||||
export const initAuthFiles = () => {
|
||||
try {
|
||||
const authDirs = grabAuthDirs();
|
||||
|
||||
@@ -22,7 +20,7 @@ const initAuthFiles = () => {
|
||||
if (!fs.existsSync(authDirs.auth))
|
||||
fs.mkdirSync(authDirs.auth, { recursive: true });
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (error: any) {
|
||||
console.log(`Error initializing Auth Files: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
@@ -30,15 +28,13 @@ const initAuthFiles = () => {
|
||||
|
||||
/**
|
||||
* # Write Auth Files
|
||||
* @param {string} name
|
||||
* @param {string} data
|
||||
*/
|
||||
const writeAuthFile = (name, data) => {
|
||||
export const writeAuthFile = (name: string, data: string) => {
|
||||
initAuthFiles();
|
||||
try {
|
||||
fs.writeFileSync(path.join(grabAuthDirs().auth, name), data);
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error writing Auth File: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
@@ -46,13 +42,12 @@ const writeAuthFile = (name, data) => {
|
||||
|
||||
/**
|
||||
* # Get Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
const getAuthFile = (name) => {
|
||||
export const getAuthFile = (name: string) => {
|
||||
try {
|
||||
const authFilePath = path.join(grabAuthDirs().auth, name);
|
||||
return fs.readFileSync(authFilePath, "utf-8");
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error getting Auth File: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
@@ -62,10 +57,10 @@ const getAuthFile = (name) => {
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
const deleteAuthFile = (name) => {
|
||||
export const deleteAuthFile = (name: string) => {
|
||||
try {
|
||||
return fs.rmSync(path.join(grabAuthDirs().auth, name));
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error deleting Auth File: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
@@ -75,19 +70,12 @@ const deleteAuthFile = (name) => {
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
const checkAuthFile = (name) => {
|
||||
export const checkAuthFile = (name: string) => {
|
||||
try {
|
||||
return fs.existsSync(path.join(grabAuthDirs().auth, name));
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error checking Auth File: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
exports.grabAuthDirs = grabAuthDirs;
|
||||
exports.initAuthFiles = initAuthFiles;
|
||||
exports.writeAuthFile = writeAuthFile;
|
||||
exports.getAuthFile = getAuthFile;
|
||||
exports.deleteAuthFile = deleteAuthFile;
|
||||
exports.checkAuthFile = checkAuthFile;
|
||||
Reference in New Issue
Block a user