Skip to content

Commit

Permalink
refactor(server): replace fetch client command to check installed pac…
Browse files Browse the repository at this point in the history
…kage not package.json
  • Loading branch information
NotExpectedYet committed Jun 19, 2022
1 parent 8d2a086 commit 752d0eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions server/app-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const instructionsReferralURL = "https://docs.octofarm.net/installation/setup-en
const deprecatedConfigFolder = "../middleware";
const deprecatedConfigFilePath = deprecatedConfigFolder + "db.js";
const packageJsonPath = path.join(__dirname, "package.json");
const clientPackageJsonPath = path.join(__dirname, "../client/package.json");
const clientPackageJson = require(clientPackageJsonPath);
const exec = require("child_process").exec;
let currentClientVersion;
const dotEnvPath = path.join(__dirname, "../.env");

/**
Expand Down Expand Up @@ -363,7 +363,15 @@ function isEnvProd() {
* @returns {string} Client version number #.#.#
*/
function fetchClientVersion() {
return clientPackageJson.version;
if (!currentClientVersion) {
exec("npm view @notexpectedyet/octofarm-client version", function (err, stdout, stderr) {
if (err) {
logger.error("Failed to grab client version!", err.toString());
}
currentClientVersion = stdout;
});
}
return currentClientVersion;
}

function fetchSuperSecretKey() {
Expand Down
2 changes: 2 additions & 0 deletions server/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { FileClean } = require("./services/file-cleaner.service");
const { sortCurrentOperations } = require("./services/printer-statistics.service");
const { initFarmInformation } = require("./services/farm-information.service");
const { notifySubscribers } = require("./services/server-side-events.service");
const { fetchClientVersion } = require("./app-env");
const { MESSAGE_TYPES } = require("./constants/sse.constants");
const { LOGGER_ROUTE_KEYS } = require("./constants/logger.constants");

Expand All @@ -38,6 +39,7 @@ const INITIALISE_SYSTEM_CACHE = async () => {
await getEventEmitterCache();
await initHistoryCache();
await getInfluxCleanerCache();
fetchClientVersion();
};

const INITIALISE_PRINTERS = async () => {
Expand Down

0 comments on commit 752d0eb

Please sign in to comment.