From 9b4525e5a72857979386c70c3ee786b5fc4091b8 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Mon, 18 Mar 2019 16:50:40 -0400 Subject: [PATCH] Refactor logFile function for readability. Add comments to the log library. Build logs. --- app/lib/log/Readme.md | 8 +++++++ app/lib/log/index.js | 24 ++++++++++++++++++--- app/lib/log/index.js.map | 2 +- cli/lib/log/index.js | 24 ++++++++++++++++++--- cli/lib/log/index.js.map | 2 +- lib/log/index.js | 24 ++++++++++++++++++--- lib/log/index.js.map | 2 +- src/log/index.ts | 45 ++++++++++++++++++++++++++++------------ 8 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 app/lib/log/Readme.md diff --git a/app/lib/log/Readme.md b/app/lib/log/Readme.md new file mode 100644 index 0000000..4c3bea3 --- /dev/null +++ b/app/lib/log/Readme.md @@ -0,0 +1,8 @@ + + +## logFile() ⇒ string +Determine the location of the log file based on the operating system +and return as an absolute string from os.homedir() + +**Kind**: global function +**Returns**: string - Path to log file diff --git a/app/lib/log/index.js b/app/lib/log/index.js index 08b6e65..8a55c23 100644 --- a/app/lib/log/index.js +++ b/app/lib/log/index.js @@ -6,14 +6,24 @@ const fs = require('fs-extra'); const os = require('os'); const logTime = 'MM/DD/YY-HH:mm:ss'; let transport; +/** + * Determine the location of the log file based on the operating system + * and return as an absolute string from os.homedir() + * + * @returns {string} Path to log file + **/ async function logFile() { + const homeDir = os.homedir(); + const linuxDir = `/.config/mcopy-cli/`; + const macDir = `/Library/Logs/mcopy-cli/`; + const winDir = `/AppData/Roaming/mcopy-cli/`; + let logPath = path.join(homeDir, linuxDir); let exists; - let logPath = path.join(os.homedir(), `/.config/mcopy-cli/`); if (process.platform === 'darwin') { - logPath = path.join(os.homedir(), `/Library/Logs/mcopy-cli/`); + logPath = path.join(homeDir, macDir); } else if (process.platform === 'win32') { - logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy-cli/`); + logPath = path.join(homeDir, winDir); } exists = await fs.exists(logPath); if (!exists) { @@ -21,6 +31,14 @@ async function logFile() { } return path.join(logPath, 'mcopy-cli.log'); } +/** + * Create and return the logger transport based on settings determined in + * arguments object + * + * @param {object} arg Arguments from process + * + * @returns {object} Logger transport + **/ module.exports = async function (arg) { if (arg.quiet) { transport = { diff --git a/app/lib/log/index.js.map b/app/lib/log/index.js.map index c50dde5..6306148 100644 --- a/app/lib/log/index.js.map +++ b/app/lib/log/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/log/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAC/D,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;AACpD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAC9B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,MAAM,OAAO,GAAG,mBAAmB,CAAA;AACnC,IAAI,SAAe,CAAA;AAEnB,KAAK,UAAU,OAAO;IACrB,IAAI,MAAgB,CAAA;IACpB,IAAI,OAAO,GAAY,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,qBAAqB,CAAC,CAAA;IACrE,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE;QAClC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,0BAA0B,CAAC,CAAA;KAC7D;SAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QACxC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,6BAA6B,CAAC,CAAA;KAChE;IACD,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACjC,IAAI,CAAC,MAAM,EAAE;QACZ,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;KACvB;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,KAAK,WAAW,GAAS;IACzC,IAAI,GAAG,CAAC,KAAK,EAAE;QACd,SAAS,GAAG;YACX,IAAI,EAAG,cAAa,CAAC;YACrB,IAAI,EAAG,cAAa,CAAC;YACrB,KAAK,EAAG,cAAa,CAAC;SACtB,CAAA;KACD;SAAM;QACN,SAAS,GAAG,YAAY,CAAC;YACxB,UAAU,EAAE;gBACX,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;oBACxB,MAAM,EAAE,OAAO,CACd,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,MAAM,EAAE,CACf;iBACD,CAAC;gBACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBACrB,QAAQ,EAAE,MAAM,OAAO,EAAE;iBACzB,CAAC;aACF;SACD,CAAC,CAAA;KACF;IACD,OAAO,SAAS,CAAA;AACjB,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/log/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAC/D,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;AACpD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAC9B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,MAAM,OAAO,GAAG,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,MAAM,CAAC,MAAM,EAAE,CACf;iBACD,CAAC;gBACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBACrB,QAAQ,EAAE,MAAM,OAAO,EAAE;iBACzB,CAAC;aACF;SACD,CAAC,CAAA;KACF;IACD,OAAO,SAAS,CAAA;AACjB,CAAC,CAAA"} \ No newline at end of file diff --git a/cli/lib/log/index.js b/cli/lib/log/index.js index 08b6e65..8a55c23 100644 --- a/cli/lib/log/index.js +++ b/cli/lib/log/index.js @@ -6,14 +6,24 @@ const fs = require('fs-extra'); const os = require('os'); const logTime = 'MM/DD/YY-HH:mm:ss'; let transport; +/** + * Determine the location of the log file based on the operating system + * and return as an absolute string from os.homedir() + * + * @returns {string} Path to log file + **/ async function logFile() { + const homeDir = os.homedir(); + const linuxDir = `/.config/mcopy-cli/`; + const macDir = `/Library/Logs/mcopy-cli/`; + const winDir = `/AppData/Roaming/mcopy-cli/`; + let logPath = path.join(homeDir, linuxDir); let exists; - let logPath = path.join(os.homedir(), `/.config/mcopy-cli/`); if (process.platform === 'darwin') { - logPath = path.join(os.homedir(), `/Library/Logs/mcopy-cli/`); + logPath = path.join(homeDir, macDir); } else if (process.platform === 'win32') { - logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy-cli/`); + logPath = path.join(homeDir, winDir); } exists = await fs.exists(logPath); if (!exists) { @@ -21,6 +31,14 @@ async function logFile() { } return path.join(logPath, 'mcopy-cli.log'); } +/** + * Create and return the logger transport based on settings determined in + * arguments object + * + * @param {object} arg Arguments from process + * + * @returns {object} Logger transport + **/ module.exports = async function (arg) { if (arg.quiet) { transport = { diff --git a/cli/lib/log/index.js.map b/cli/lib/log/index.js.map index c50dde5..6306148 100644 --- a/cli/lib/log/index.js.map +++ b/cli/lib/log/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/log/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,YAAY,EAAE,MAAM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AAQ,KAAK,QAAQ,EAAE;QAClC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KACrC;SAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QACxC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KACrC;IACD,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,EAAE;QACZ,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KACxB;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC5C,CAAC;AACD;;;;;;;IAOI;AACJ,MAAM,CAAC,OAAO,GAAG,KAAK,WAAW,GAAS;IACzC,IAAI,GAAG,CAAC,KAAK,EAAE;QACd,SAAS,GAAG;YACX,IAAI,EAAG,cAAa,CAAC;YACrB,IAAI,EAAG,cAAa,CAAC;YACrB,KAAK,EAAG,cAAa,CAAC;SACtB,CAAA;KACD;SAAM;QACN,SAAS,GAAG,YAAY,CAAC;YACxB,UAAU,EAAE;gBACX,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;oBACxB,MAAM,EAAE,OAAO,CACd,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,MAAM,EAAE,CACf;iBACD,CAAC;gBACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBACrB,QAAQ,EAAE,MAAM,OAAO,EAAE;iBACzB,CAAC;aACF;SACD,CAAC,CAAA;KACF;IACD,OAAO,SAAS,CAAA;AACjB,CAAC,CAAA"} \ No newline at end of file diff --git a/lib/log/index.js b/lib/log/index.js index 08b6e65..8a55c23 100644 --- a/lib/log/index.js +++ b/lib/log/index.js @@ -6,14 +6,24 @@ const fs = require('fs-extra'); const os = require('os'); const logTime = 'MM/DD/YY-HH:mm:ss'; let transport; +/** + * Determine the location of the log file based on the operating system + * and return as an absolute string from os.homedir() + * + * @returns {string} Path to log file + **/ async function logFile() { + const homeDir = os.homedir(); + const linuxDir = `/.config/mcopy-cli/`; + const macDir = `/Library/Logs/mcopy-cli/`; + const winDir = `/AppData/Roaming/mcopy-cli/`; + let logPath = path.join(homeDir, linuxDir); let exists; - let logPath = path.join(os.homedir(), `/.config/mcopy-cli/`); if (process.platform === 'darwin') { - logPath = path.join(os.homedir(), `/Library/Logs/mcopy-cli/`); + logPath = path.join(homeDir, macDir); } else if (process.platform === 'win32') { - logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy-cli/`); + logPath = path.join(homeDir, winDir); } exists = await fs.exists(logPath); if (!exists) { @@ -21,6 +31,14 @@ async function logFile() { } return path.join(logPath, 'mcopy-cli.log'); } +/** + * Create and return the logger transport based on settings determined in + * arguments object + * + * @param {object} arg Arguments from process + * + * @returns {object} Logger transport + **/ module.exports = async function (arg) { if (arg.quiet) { transport = { diff --git a/lib/log/index.js.map b/lib/log/index.js.map index c50dde5..6306148 100644 --- a/lib/log/index.js.map +++ b/lib/log/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/log/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAC/D,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;AACpD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAC9B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,MAAM,OAAO,GAAG,mBAAmB,CAAA;AACnC,IAAI,SAAe,CAAA;AAEnB,KAAK,UAAU,OAAO;IACrB,IAAI,MAAg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AAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC5C,CAAC;AACD;;;;;;;IAOI;AACJ,MAAM,CAAC,OAAO,GAAG,KAAK,WAAW,GAAS;IACzC,IAAI,GAAG,CAAC,KAAK,EAAE;QACd,SAAS,GAAG;YACX,IAAI,EAAG,cAAa,CAAC;YACrB,IAAI,EAAG,cAAa,CAAC;YACrB,KAAK,EAAG,cAAa,CAAC;SACtB,CAAA;KACD;SAAM;QACN,SAAS,GAAG,YAAY,CAAC;YACxB,UAAU,EAAE;gBACX,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;oBACxB,MAAM,EAAE,OAAO,CACd,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,MAAM,EAAE,CACf;iBACD,CAAC;gBACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBACrB,QAAQ,EAAE,MAAM,OAAO,EAAE;iBACzB,CAAC;aACF;SACD,CAAC,CAAA;KACF;IACD,OAAO,SAAS,CAAA;AACjB,CAAC,CAAA"} \ No newline at end of file diff --git a/src/log/index.ts b/src/log/index.ts index 04f4a8d..aabf1d0 100644 --- a/src/log/index.ts +++ b/src/log/index.ts @@ -9,21 +9,40 @@ const os = require('os') const logTime = 'MM/DD/YY-HH:mm:ss' let transport : any +/** + * Determine the location of the log file based on the operating system + * and return as an absolute string from os.homedir() + * + * @returns {string} Path to log file + **/ async function logFile () { - let exists : boolean - let logPath : string = path.join(os.homedir(), `/.config/mcopy-cli/`) - if (process.platform === 'darwin') { - logPath = path.join(os.homedir(), `/Library/Logs/mcopy-cli/`) - } else if (process.platform === 'win32') { - logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy-cli/`) - } - exists = await fs.exists(logPath) - if (!exists) { - await fs.mkdir(logPath) - } - return path.join(logPath, 'mcopy-cli.log') -} + + const homeDir : string = os.homedir(); + const linuxDir : string = `/.config/mcopy-cli/`; + const macDir : string = `/Library/Logs/mcopy-cli/`; + const winDir : string = `/AppData/Roaming/mcopy-cli/`; + let logPath : string = path.join(homeDir, linuxDir); + let exists : boolean; + if (process.platform === 'darwin') { + logPath = path.join(homeDir, macDir); + } else if (process.platform === 'win32') { + logPath = path.join(homeDir, winDir); + } + exists = await fs.exists(logPath); + if (!exists) { + await fs.mkdir(logPath); + } + return path.join(logPath, 'mcopy-cli.log'); +} +/** + * Create and return the logger transport based on settings determined in + * arguments object + * + * @param {object} arg Arguments from process + * + * @returns {object} Logger transport + **/ module.exports = async function (arg : any) { if (arg.quiet) { transport = {