From c30c09adaf889fc5bb6666fa7c05394eea074cb2 Mon Sep 17 00:00:00 2001 From: Eric Woodward Date: Sat, 27 Jan 2024 20:42:43 -0500 Subject: [PATCH] moar TS fixes --- lib/cjs/loadConfig.d.ts | 2 +- lib/cjs/loadConfig.d.ts.map | 2 +- lib/cjs/loadConfig.js | 17 ++++++++++++++--- lib/cjs/utils.d.ts | 7 ------- lib/cjs/utils.d.ts.map | 2 +- lib/cjs/utils.js | 21 ++------------------- lib/esm/loadConfig.d.ts | 2 +- lib/esm/loadConfig.d.ts.map | 2 +- lib/esm/loadConfig.js | 17 ++++++++++++++--- lib/esm/utils.d.ts | 7 ------- lib/esm/utils.d.ts.map | 2 +- lib/esm/utils.js | 21 ++------------------- package.json | 2 +- src/loadConfig.ts | 26 ++++++++++++-------------- src/utils.ts | 17 ----------------- 15 files changed, 51 insertions(+), 96 deletions(-) diff --git a/lib/cjs/loadConfig.d.ts b/lib/cjs/loadConfig.d.ts index f7434fa..7454dd6 100644 --- a/lib/cjs/loadConfig.d.ts +++ b/lib/cjs/loadConfig.d.ts @@ -1,4 +1,4 @@ -declare const _default: (opts: Partial, envKey: string, localDefaultFilePath?: string) => { +declare const _default: (opts: Partial, envKey: string, filePath?: string) => { [x: string]: any; }; export default _default; diff --git a/lib/cjs/loadConfig.d.ts.map b/lib/cjs/loadConfig.d.ts.map index 795eba3..109e608 100644 --- a/lib/cjs/loadConfig.d.ts.map +++ b/lib/cjs/loadConfig.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../../src/loadConfig.ts"],"names":[],"mappings":"sDAUS,MAAM;;;AAFf,wBAyCE"} \ No newline at end of file +{"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../../src/loadConfig.ts"],"names":[],"mappings":"sDAI6C,MAAM;;;AAAnD,wBA+CE"} \ No newline at end of file diff --git a/lib/cjs/loadConfig.js b/lib/cjs/loadConfig.js index 7077409..4102e68 100644 --- a/lib/cjs/loadConfig.js +++ b/lib/cjs/loadConfig.js @@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const utils_1 = require("./utils"); -exports.default = (opts, envKey, localDefaultFilePath = "") => { - const { env } = process, { __dirname } = (0, utils_1.getDirname)(), def = (0, utils_1.readJsonIfExists)(path_1.default.join(__dirname, localDefaultFilePath || "./defaults.json5")), +exports.default = (opts, envKey, filePath = "") => { + const { env } = process, defPath = filePath || path_1.default.join(process.cwd() ?? ".", "defaults.json5"), def = (0, utils_1.readJsonIfExists)(defPath), // gets value from ENV || options || defaults (in that order) getVal = (envName) => { const snakeEnvName = `${envKey}_${(0, utils_1.convertCamelToUpperSnakeCase)(envName)}`; @@ -30,6 +30,17 @@ exports.default = (opts, envKey, localDefaultFilePath = "") => { return opts[optName]; return def[optName]; }; + console.log({ def }); + const retVal = { + ...Object.keys(def).reduce((acc, curr) => { + if (Array.isArray(def[curr])) + acc[curr] = getArray(curr); + else + acc[curr] = getVal(curr); + return acc; + }, {}), + }; + console.log({ retVal }); return { ...Object.keys(def).reduce((acc, curr) => { if (Array.isArray(def[curr])) @@ -40,4 +51,4 @@ exports.default = (opts, envKey, localDefaultFilePath = "") => { }, {}), }; }; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZENvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sb2FkQ29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsZ0RBQXdCO0FBRXhCLG1DQUlpQjtBQUVqQixrQkFBZSxDQUNkLElBQWdCLEVBQ2hCLE1BQWMsRUFDZCxvQkFBb0IsR0FBRyxFQUFFLEVBQ3hCLEVBQUU7SUFDSCxNQUFNLEVBQUUsR0FBRyxFQUFFLEdBQUcsT0FBTyxFQUN0QixFQUFFLFNB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RcdC4uLk9iamVjdC5rZXlzKGRlZikucmVkdWNlKChhY2M6IFBhcnRpYWw8dHlwZW9mIGRlZj4sIGN1cnIpID0+IHtcblx0XHRcdGlmIChBcnJheS5pc0FycmF5KGRlZltjdXJyXSkpIGFjY1tjdXJyXSA9IGdldEFycmF5KGN1cnIgYXMga2V5b2YgVCk7XG5cdFx0XHRlbHNlIGFjY1tjdXJyXSA9IGdldFZhbChjdXJyIGFzIGtleW9mIFQpO1xuXHRcdFx0cmV0dXJuIGFjYztcblx0XHR9LCB7fSksXG5cdH07XG5cblx0Y29uc29sZS5sb2coeyByZXRWYWwgfSk7XG5cblx0cmV0dXJuIHtcblx0XHQuLi5PYmplY3Qua2V5cyhkZWYpLnJlZHVjZSgoYWNjOiBQYXJ0aWFsPHR5cGVvZiBkZWY+LCBjdXJyKSA9PiB7XG5cdFx0XHRpZiAoQXJyYXkuaXNBcnJheShkZWZbY3Vycl0pKSBhY2NbY3Vycl0gPSBnZXRBcnJheShjdXJyIGFzIGtleW9mIFQpO1xuXHRcdFx0ZWxzZSBhY2NbY3Vycl0gPSBnZXRWYWwoY3VyciBhcyBrZXlvZiBUKTtcblx0XHRcdHJldHVybiBhY2M7XG5cdFx0fSwge30pLFxuXHR9O1xufTtcbiJdfQ== \ No newline at end of file diff --git a/lib/cjs/utils.d.ts b/lib/cjs/utils.d.ts index 991d592..fe6daed 100644 --- a/lib/cjs/utils.d.ts +++ b/lib/cjs/utils.d.ts @@ -3,13 +3,6 @@ export interface ErrorWithCode { code: string; } export declare const convertCamelToUpperSnakeCase: (str: string) => string; -/** - * From: https://www.webmanajemen.com/2022/05/use-import-meta-cjs.html - */ -export declare const getDirname: () => { - __dirname: string; - __filename: string; -}; export declare const getTime: () => string; export declare const log: (...msg: unknown[]) => void; export declare const readJsonIfExists: (filePath: string | URL) => any; diff --git a/lib/cjs/utils.d.ts.map b/lib/cjs/utils.d.ts.map index 5d0f3f3..b37b38e 100644 --- a/lib/cjs/utils.d.ts.map +++ b/lib/cjs/utils.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAIA,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,4BAA4B,QAAS,MAAM,WACM,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,UAAU;;;CAYtB,CAAC;AAEF,eAAO,MAAM,OAAO,cAyBnB,CAAC;AAEF,eAAO,MAAM,GAAG,WAAY,OAAO,EAAE,SACgB,CAAC;AAEtD,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG,GAAG,QAQtD,CAAC"} \ No newline at end of file +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAIA,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,4BAA4B,QAAS,MAAM,WACM,CAAC;AAE/D,eAAO,MAAM,OAAO,cAyBnB,CAAC;AAEF,eAAO,MAAM,GAAG,WAAY,OAAO,EAAE,SACgB,CAAC;AAEtD,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG,GAAG,QAQtD,CAAC"} \ No newline at end of file diff --git a/lib/cjs/utils.js b/lib/cjs/utils.js index 5120555..8228558 100644 --- a/lib/cjs/utils.js +++ b/lib/cjs/utils.js @@ -3,29 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.readJsonIfExists = exports.log = exports.getTime = exports.getDirname = exports.convertCamelToUpperSnakeCase = void 0; +exports.readJsonIfExists = exports.log = exports.getTime = exports.convertCamelToUpperSnakeCase = void 0; const chalk_1 = __importDefault(require("chalk")); const fs_1 = __importDefault(require("fs")); const json5_1 = __importDefault(require("json5")); const convertCamelToUpperSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter}`).toUpperCase(); exports.convertCamelToUpperSnakeCase = convertCamelToUpperSnakeCase; -/** - * From: https://www.webmanajemen.com/2022/05/use-import-meta-cjs.html - */ -const getDirname = () => { - // get the stack - const { stack } = new Error(); - // get the third line (the original invoker) - const invokeFileLine = (stack || "").split(`\n`)[2]; - // match the file url from file://(.+.(ts|js)) and get the first capturing group - const __filename = (invokeFileLine.match(/file:\/\/(.+.(ts|js))/) || - [])[1].slice(1); - // match the file URL from file://(.+)/ and get the first capturing group - // the (.+) is a greedy quantifier and will make the RegExp expand to the largest match - const __dirname = (invokeFileLine.match(/file:\/\/(.+)\//) || [])[1].slice(1); - return { __dirname, __filename }; -}; -exports.getDirname = getDirname; const getTime = () => { const now = new Date(), tzo = -now.getTimezoneOffset(), dif = tzo >= 0 ? "+" : "-", pad = (num) => { const norm = Math.floor(Math.abs(num)); @@ -64,4 +47,4 @@ const readJsonIfExists = (filePath) => { } }; exports.readJsonIfExists = readJsonIfExists; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsa0RBQTBCO0FBQzFCLDRDQUFvQjtBQUNwQixrREFBMEI7QUFNbkIsTUFBTSw0QkFBNEIsR0FBRyxDQUFDLEdBQVcsRUFBRSxFQUFFLENBQzNELEdBQUcsQ0FBQyxPQUFPLENBQUMsUUFBUSxFQUFFLENBQUMsTUFBTSxFQUFFLEVBQUUsQ0FBQyxJQUFJLE1BQU0sRUFBRSxDQUFDLENBQUMsV0FBVyxFQUFFLENBQUM7QUFEbEQsUUFBQSw0QkFBNEIsZ0NBQ3NCO0FBRS9EOztHQUVHO0FBQ0ksTUFBTSxVQUFVLEdBQUcsR0FBRyxFQUFFO0lBQzlCLGdCQUFnQjtJQUNoQixNQUFNLEVBQUUsS0FBSyxF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n0ke25vcm19YDtcblx0XHR9O1xuXHRyZXR1cm4gW1xuXHRcdG5vdy5nZXRGdWxsWWVhcigpLFxuXHRcdFwiLVwiLFxuXHRcdHBhZChub3cuZ2V0TW9udGgoKSArIDEpLFxuXHRcdFwiLVwiLFxuXHRcdHBhZChub3cuZ2V0RGF0ZSgpKSxcblx0XHRcIlRcIixcblx0XHRwYWQobm93LmdldEhvdXJzKCkpLFxuXHRcdFwiOlwiLFxuXHRcdHBhZChub3cuZ2V0TWludXRlcygpKSxcblx0XHRcIjpcIixcblx0XHRwYWQobm93LmdldFNlY29uZHMoKSksXG5cdFx0ZGlmLFxuXHRcdHBhZCh0em8gLyA2MCksXG5cdFx0XCI6XCIsXG5cdFx0cGFkKHR6byAlIDYwKSxcblx0XS5qb2luKFwiXCIpO1xufTtcblxuZXhwb3J0IGNvbnN0IGxvZyA9ICguLi5tc2c6IHVua25vd25bXSkgPT5cblx0Y29uc29sZS5sb2coYCR7Y2hhbGsuZ3JleShgJHtnZXRUaW1lKCl9OmApfSAke21zZ31gKTtcblxuZXhwb3J0IGNvbnN0IHJlYWRKc29uSWZFeGlzdHMgPSAoZmlsZVBhdGg6IHN0cmluZyB8IFVSTCkgPT4ge1xuXHR0cnkge1xuXHRcdHJldHVybiBqc29uNS5wYXJzZShmcy5yZWFkRmlsZVN5bmMoZmlsZVBhdGgsIHsgZW5jb2Rpbmc6IFwidXRmOFwiIH0pKTtcblx0fSBjYXRjaCAoZXJyKSB7XG5cdFx0Ly8gaWYgbm8gZmlsZSwgcmV0dXJuIGVtcHR5IG9iamVjdFxuXHRcdGlmICgoZXJyIGFzIEVycm9yV2l0aENvZGUpPy5jb2RlID09PSBcIkVOT0VOVFwiKSByZXR1cm4ge307XG5cdFx0dGhyb3cgZXJyO1xuXHR9XG59O1xuIl19 \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNl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cGFkKG5vdy5nZXRNaW51dGVzKCkpLFxuXHRcdFwiOlwiLFxuXHRcdHBhZChub3cuZ2V0U2Vjb25kcygpKSxcblx0XHRkaWYsXG5cdFx0cGFkKHR6byAvIDYwKSxcblx0XHRcIjpcIixcblx0XHRwYWQodHpvICUgNjApLFxuXHRdLmpvaW4oXCJcIik7XG59O1xuXG5leHBvcnQgY29uc3QgbG9nID0gKC4uLm1zZzogdW5rbm93bltdKSA9PlxuXHRjb25zb2xlLmxvZyhgJHtjaGFsay5ncmV5KGAke2dldFRpbWUoKX06YCl9ICR7bXNnfWApO1xuXG5leHBvcnQgY29uc3QgcmVhZEpzb25JZkV4aXN0cyA9IChmaWxlUGF0aDogc3RyaW5nIHwgVVJMKSA9PiB7XG5cdHRyeSB7XG5cdFx0cmV0dXJuIGpzb241LnBhcnNlKGZzLnJlYWRGaWxlU3luYyhmaWxlUGF0aCwgeyBlbmNvZGluZzogXCJ1dGY4XCIgfSkpO1xuXHR9IGNhdGNoIChlcnIpIHtcblx0XHQvLyBpZiBubyBmaWxlLCByZXR1cm4gZW1wdHkgb2JqZWN0XG5cdFx0aWYgKChlcnIgYXMgRXJyb3JXaXRoQ29kZSk/LmNvZGUgPT09IFwiRU5PRU5UXCIpIHJldHVybiB7fTtcblx0XHR0aHJvdyBlcnI7XG5cdH1cbn07XG4iXX0= \ No newline at end of file diff --git a/lib/esm/loadConfig.d.ts b/lib/esm/loadConfig.d.ts index f7434fa..7454dd6 100644 --- a/lib/esm/loadConfig.d.ts +++ b/lib/esm/loadConfig.d.ts @@ -1,4 +1,4 @@ -declare const _default: (opts: Partial, envKey: string, localDefaultFilePath?: string) => { +declare const _default: (opts: Partial, envKey: string, filePath?: string) => { [x: string]: any; }; export default _default; diff --git a/lib/esm/loadConfig.d.ts.map b/lib/esm/loadConfig.d.ts.map index 795eba3..109e608 100644 --- a/lib/esm/loadConfig.d.ts.map +++ b/lib/esm/loadConfig.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../../src/loadConfig.ts"],"names":[],"mappings":"sDAUS,MAAM;;;AAFf,wBAyCE"} \ No newline at end of file +{"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../../src/loadConfig.ts"],"names":[],"mappings":"sDAI6C,MAAM;;;AAAnD,wBA+CE"} \ No newline at end of file diff --git a/lib/esm/loadConfig.js b/lib/esm/loadConfig.js index 7077409..4102e68 100644 --- a/lib/esm/loadConfig.js +++ b/lib/esm/loadConfig.js @@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const utils_1 = require("./utils"); -exports.default = (opts, envKey, localDefaultFilePath = "") => { - const { env } = process, { __dirname } = (0, utils_1.getDirname)(), def = (0, utils_1.readJsonIfExists)(path_1.default.join(__dirname, localDefaultFilePath || "./defaults.json5")), +exports.default = (opts, envKey, filePath = "") => { + const { env } = process, defPath = filePath || path_1.default.join(process.cwd() ?? ".", "defaults.json5"), def = (0, utils_1.readJsonIfExists)(defPath), // gets value from ENV || options || defaults (in that order) getVal = (envName) => { const snakeEnvName = `${envKey}_${(0, utils_1.convertCamelToUpperSnakeCase)(envName)}`; @@ -30,6 +30,17 @@ exports.default = (opts, envKey, localDefaultFilePath = "") => { return opts[optName]; return def[optName]; }; + console.log({ def }); + const retVal = { + ...Object.keys(def).reduce((acc, curr) => { + if (Array.isArray(def[curr])) + acc[curr] = getArray(curr); + else + acc[curr] = getVal(curr); + return acc; + }, {}), + }; + console.log({ retVal }); return { ...Object.keys(def).reduce((acc, curr) => { if (Array.isArray(def[curr])) @@ -40,4 +51,4 @@ exports.default = (opts, envKey, localDefaultFilePath = "") => { }, {}), }; }; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZENvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sb2FkQ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RcdFx0aWYgKEFycmF5LmlzQXJyYXkob3B0c1tvcHROYW1lXSkgJiYgKG9wdHNbb3B0TmFtZV0gYXMgW10pLmxlbmd0aClcblx0XHRcdFx0cmV0dXJuIG9wdHNbb3B0TmFtZV07XG5cdFx0XHRyZXR1cm4gZGVmW29wdE5hbWVdO1xuXHRcdH07XG5cblx0Y29uc29sZS5sb2coeyBkZWYgfSk7XG5cblx0Y29uc3QgcmV0VmFsID0ge1xuXHRcdC4uLk9iamVjdC5rZXlzKGRlZikucmVkdWNlKChhY2M6IFBhcnRpYWw8dHlwZW9mIGRlZj4sIGN1cnIpID0+IHtcblx0XHRcdGlmIChBcnJheS5pc0FycmF5KGRlZltjdXJyXSkpIGFjY1tjdXJyXSA9IGdldEFycmF5KGN1cnIgYXMga2V5b2YgVCk7XG5cdFx0XHRlbHNlIGFjY1tjdXJyXSA9IGdldFZhbChjdXJyIGFzIGtleW9mIFQpO1xuXHRcdFx0cmV0dXJuIGFjYztcblx0XHR9LCB7fSksXG5cdH07XG5cblx0Y29uc29sZS5sb2coeyByZXRWYWwgfSk7XG5cblx0cmV0dXJuIHtcblx0XHQuLi5PYmplY3Qua2V5cyhkZWYpLnJlZHVjZSgoYWNjOiBQYXJ0aWFsPHR5cGVvZiBkZWY+LCBjdXJyKSA9PiB7XG5cdFx0XHRpZiAoQXJyYXkuaXNBcnJheShkZWZbY3Vycl0pKSBhY2NbY3Vycl0gPSBnZXRBcnJheShjdXJyIGFzIGtleW9mIFQpO1xuXHRcdFx0ZWxzZSBhY2NbY3Vycl0gPSBnZXRWYWwoY3VyciBhcyBrZXlvZiBUKTtcblx0XHRcdHJldHVybiBhY2M7XG5cdFx0fSwge30pLFxuXHR9O1xufTtcbiJdfQ== \ No newline at end of file diff --git a/lib/esm/utils.d.ts b/lib/esm/utils.d.ts index 991d592..fe6daed 100644 --- a/lib/esm/utils.d.ts +++ b/lib/esm/utils.d.ts @@ -3,13 +3,6 @@ export interface ErrorWithCode { code: string; } export declare const convertCamelToUpperSnakeCase: (str: string) => string; -/** - * From: https://www.webmanajemen.com/2022/05/use-import-meta-cjs.html - */ -export declare const getDirname: () => { - __dirname: string; - __filename: string; -}; export declare const getTime: () => string; export declare const log: (...msg: unknown[]) => void; export declare const readJsonIfExists: (filePath: string | URL) => any; diff --git a/lib/esm/utils.d.ts.map b/lib/esm/utils.d.ts.map index 5d0f3f3..b37b38e 100644 --- a/lib/esm/utils.d.ts.map +++ b/lib/esm/utils.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAIA,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,4BAA4B,QAAS,MAAM,WACM,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,UAAU;;;CAYtB,CAAC;AAEF,eAAO,MAAM,OAAO,cAyBnB,CAAC;AAEF,eAAO,MAAM,GAAG,WAAY,OAAO,EAAE,SACgB,CAAC;AAEtD,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG,GAAG,QAQtD,CAAC"} \ No newline at end of file +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAIA,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,4BAA4B,QAAS,MAAM,WACM,CAAC;AAE/D,eAAO,MAAM,OAAO,cAyBnB,CAAC;AAEF,eAAO,MAAM,GAAG,WAAY,OAAO,EAAE,SACgB,CAAC;AAEtD,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG,GAAG,QAQtD,CAAC"} \ No newline at end of file diff --git a/lib/esm/utils.js b/lib/esm/utils.js index 5120555..8228558 100644 --- a/lib/esm/utils.js +++ b/lib/esm/utils.js @@ -3,29 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.readJsonIfExists = exports.log = exports.getTime = exports.getDirname = exports.convertCamelToUpperSnakeCase = void 0; +exports.readJsonIfExists = exports.log = exports.getTime = exports.convertCamelToUpperSnakeCase = void 0; const chalk_1 = __importDefault(require("chalk")); const fs_1 = __importDefault(require("fs")); const json5_1 = __importDefault(require("json5")); const convertCamelToUpperSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter}`).toUpperCase(); exports.convertCamelToUpperSnakeCase = convertCamelToUpperSnakeCase; -/** - * From: https://www.webmanajemen.com/2022/05/use-import-meta-cjs.html - */ -const getDirname = () => { - // get the stack - const { stack } = new Error(); - // get the third line (the original invoker) - const invokeFileLine = (stack || "").split(`\n`)[2]; - // match the file url from file://(.+.(ts|js)) and get the first capturing group - const __filename = (invokeFileLine.match(/file:\/\/(.+.(ts|js))/) || - [])[1].slice(1); - // match the file URL from file://(.+)/ and get the first capturing group - // the (.+) is a greedy quantifier and will make the RegExp expand to the largest match - const __dirname = (invokeFileLine.match(/file:\/\/(.+)\//) || [])[1].slice(1); - return { __dirname, __filename }; -}; -exports.getDirname = getDirname; const getTime = () => { const now = new Date(), tzo = -now.getTimezoneOffset(), dif = tzo >= 0 ? "+" : "-", pad = (num) => { const norm = Math.floor(Math.abs(num)); @@ -64,4 +47,4 @@ const readJsonIfExists = (filePath) => { } }; exports.readJsonIfExists = readJsonIfExists; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsa0RBQTBCO0FBQzFCLDRDQUFvQjtBQUNwQixrREFBMEI7QUFNbkIsTUFBTSw0QkFBNEIsR0FBRyxDQUFDLEdBQVcsRUFBRSxFQUFFLENBQzNELEdBQUcsQ0FBQyxPQUFPLENBQUMsUUFBUSxFQ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gO1xuXHRcdH07XG5cdHJldHVybiBbXG5cdFx0bm93LmdldEZ1bGxZZWFyKCksXG5cdFx0XCItXCIsXG5cdFx0cGFkKG5vdy5nZXRNb250aCgpICsgMSksXG5cdFx0XCItXCIsXG5cdFx0cGFkKG5vdy5nZXREYXRlKCkpLFxuXHRcdFwiVFwiLFxuXHRcdHBhZChub3cuZ2V0SG91cnMoKSksXG5cdFx0XCI6XCIsXG5cdFx0cGFkKG5vdy5nZXRNaW51dGVzKCkpLFxuXHRcdFwiOlwiLFxuXHRcdHBhZChub3cuZ2V0U2Vjb25kcygpKSxcblx0XHRkaWYsXG5cdFx0cGFkKHR6byAvIDYwKSxcblx0XHRcIjpcIixcblx0XHRwYWQodHpvICUgNjApLFxuXHRdLmpvaW4oXCJcIik7XG59O1xuXG5leHBvcnQgY29uc3QgbG9nID0gKC4uLm1zZzogdW5rbm93bltdKSA9PlxuXHRjb25zb2xlLmxvZyhgJHtjaGFsay5ncmV5KGAke2dldFRpbWUoKX06YCl9ICR7bXNnfWApO1xuXG5leHBvcnQgY29uc3QgcmVhZEpzb25JZkV4aXN0cyA9IChmaWxlUGF0aDogc3RyaW5nIHwgVVJMKSA9PiB7XG5cdHRyeSB7XG5cdFx0cmV0dXJuIGpzb241LnBhcnNlKGZzLnJlYWRGaWxlU3luYyhmaWxlUGF0aCwgeyBlbmNvZGluZzogXCJ1dGY4XCIgfSkpO1xuXHR9IGNhdGNoIChlcnIpIHtcblx0XHQvLyBpZiBubyBmaWxlLCByZXR1cm4gZW1wdHkgb2JqZWN0XG5cdFx0aWYgKChlcnIgYXMgRXJyb3JXaXRoQ29kZSk/LmNvZGUgPT09IFwiRU5PRU5UXCIpIHJldHVybiB7fTtcblx0XHR0aHJvdyBlcnI7XG5cdH1cbn07XG4iXX0= \ No newline at end of file diff --git a/package.json b/package.json index e23b4c4..f0dbbf7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itsericwoodward/utils", - "version": "0.1.4", + "version": "0.1.5", "description": "A small collection of common libraries and functions the author likes to use in his Node applications.", "main": "./lib/cjs/index.js", "module": "./lib/esm/index.js", diff --git a/src/loadConfig.ts b/src/loadConfig.ts index da1755f..2bb7b2a 100644 --- a/src/loadConfig.ts +++ b/src/loadConfig.ts @@ -1,21 +1,11 @@ import path from "path"; -import { - convertCamelToUpperSnakeCase, - getDirname, - readJsonIfExists, -} from "./utils"; +import { convertCamelToUpperSnakeCase, readJsonIfExists } from "./utils"; -export default ( - opts: Partial, - envKey: string, - localDefaultFilePath = "" -) => { +export default (opts: Partial, envKey: string, filePath = "") => { const { env } = process, - { __dirname } = getDirname(), - def = readJsonIfExists( - path.join(__dirname, localDefaultFilePath || "./defaults.json5") - ), + defPath = filePath || path.join(process.cwd() ?? ".", "defaults.json5"), + def = readJsonIfExists(defPath), // gets value from ENV || options || defaults (in that order) getVal = (envName: keyof T) => { const snakeEnvName = `${envKey}_${convertCamelToUpperSnakeCase( @@ -40,6 +30,14 @@ export default ( return def[optName]; }; + const retVal = { + ...Object.keys(def).reduce((acc: Partial, curr) => { + if (Array.isArray(def[curr])) acc[curr] = getArray(curr as keyof T); + else acc[curr] = getVal(curr as keyof T); + return acc; + }, {}), + }; + return { ...Object.keys(def).reduce((acc: Partial, curr) => { if (Array.isArray(def[curr])) acc[curr] = getArray(curr as keyof T); diff --git a/src/utils.ts b/src/utils.ts index 5c19874..5053aea 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,23 +9,6 @@ export interface ErrorWithCode { export const convertCamelToUpperSnakeCase = (str: string) => str.replace(/[A-Z]/g, (letter) => `_${letter}`).toUpperCase(); -/** - * From: https://www.webmanajemen.com/2022/05/use-import-meta-cjs.html - */ -export const getDirname = () => { - // get the stack - const { stack } = new Error(); - // get the third line (the original invoker) - const invokeFileLine = (stack || "").split(`\n`)[2]; - // match the file url from file://(.+.(ts|js)) and get the first capturing group - const __filename = (invokeFileLine.match(/file:\/\/(.+.(ts|js))/) || - [])[1].slice(1); - // match the file URL from file://(.+)/ and get the first capturing group - // the (.+) is a greedy quantifier and will make the RegExp expand to the largest match - const __dirname = (invokeFileLine.match(/file:\/\/(.+)\//) || [])[1].slice(1); - return { __dirname, __filename }; -}; - export const getTime = () => { const now = new Date(), tzo = -now.getTimezoneOffset(),