diff --git a/backend/package-lock.json b/backend/package-lock.json index 948aea87..d0aaa3c8 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -3221,6 +3221,14 @@ } } }, + "pkg-up": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-3.1.0.tgz", + "integrity": "sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==", + "requires": { + "find-up": "^3.0.0" + } + }, "plur": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/plur/-/plur-4.0.0.tgz", diff --git a/backend/package.json b/backend/package.json index 08212866..ea43b080 100644 --- a/backend/package.json +++ b/backend/package.json @@ -53,6 +53,7 @@ "passport": "^0.4.0", "passport-custom": "^1.0.5", "passport-oauth2": "^1.5.0", + "pkg-up": "^3.1.0", "reflect-metadata": "^0.1.12", "regexp-worker": "^1.1.0", "safe-regex": "^2.0.2", diff --git a/backend/src/paths.ts b/backend/src/paths.ts new file mode 100644 index 00000000..ad5dfed0 --- /dev/null +++ b/backend/src/paths.ts @@ -0,0 +1,9 @@ +import path from "path"; +import pkgUp from "pkg-up"; + +const backendPackageJson = pkgUp.sync({ + cwd: __dirname, +}); + +export const backendDir = path.dirname(backendPackageJson); +export const rootDir = path.resolve(backendDir, ".."); diff --git a/backend/src/plugins/Utility/commands/AboutCmd.ts b/backend/src/plugins/Utility/commands/AboutCmd.ts index 592dce23..7f6fd354 100644 --- a/backend/src/plugins/Utility/commands/AboutCmd.ts +++ b/backend/src/plugins/Utility/commands/AboutCmd.ts @@ -6,7 +6,9 @@ import humanizeDuration from "humanize-duration"; import LCL from "last-commit-log"; import path from "path"; import moment from "moment-timezone"; -import { getGuildTz } from "../../../utils/timezones"; +import { getGuildTz, inGuildTz } from "../../../utils/timezones"; +import { rootDir } from "../../../paths"; +import { getDateFormat } from "../../../utils/dateFormats"; export const AboutCmd = utilityCmd({ trigger: "about", @@ -20,9 +22,7 @@ export const AboutCmd = utilityCmd({ let lastCommit; try { - // From project root - // FIXME: Store these paths properly somewhere - const lcl = new LCL(path.resolve(__dirname, "..", "..", "..")); + const lcl = new LCL(rootDir); lastCommit = await lcl.getLastCommit(); } catch (e) {} // tslint:disable-line:no-empty @@ -30,7 +30,9 @@ export const AboutCmd = utilityCmd({ let version; if (lastCommit) { - lastUpdate = moment.utc(lastCommit.committer.date, "X").format("LL [at] H:mm z"); + lastUpdate = inGuildTz(pluginData, moment.utc(lastCommit.committer.date, "X")).format( + getDateFormat(pluginData, "pretty_datetime"), + ); version = lastCommit.shortHash; } else { lastUpdate = "?";