Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/utils/local/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ function killHttpMicroservice(microservice) {
const failMessage = `Failed to kill ${microservice.name}`;
async function do_kill() {
try {
const fetchFunc = typeof $fetch === "undefined" ? fetch : $fetch;
await fetchFunc(microservice.url, {
await fetch(microservice.url, {
method: microservice.method,
});
} catch (error) {
Expand Down
13 changes: 4 additions & 9 deletions app/utils/local/microservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,21 @@ import path from "node:path";
import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" with { type: "json" };

// Local imports
import { commandExistsSync, getAvailablePort, waitForReady } from "./scripts.js";
import { getAvailablePort, waitForReady } from "./scripts.js";
import { microservicesMetadatasPath, projectMicroservices } from "./cleanup.js";
import { executablePath } from "./path.js";

const MILLISECONDS_PER_SECOND = 1000;
const DEFAULT_TIMEOUT_SECONDS = 30;

function resolveCommand(execPath, execName) {
const command = commandExistsSync(execName) ? execName : executablePath(execPath, execName);
return command;
}

async function runScript(
execPath,
execName,
args,
expectedResponse,
timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
) {
const command = resolveCommand(execPath, execName);
const command = executablePath(execPath, execName);
console.log("runScript", command, args);

const child = child_process.spawn(command, args, {
Expand Down Expand Up @@ -69,7 +64,7 @@ async function runBack(execName, execPath, args = {}) {
const backArgs = [
"--port",
String(port),
"--data_folder_path",
"--project_folder_path",
projectFolderPath,
"--upload_folder_path",
uploadFolderPath,
Expand All @@ -95,7 +90,7 @@ async function runViewer(execName, execPath, args = {}) {
const viewerArgs = [
"--port",
String(port),
"--data_folder_path",
"--project_folder_path",
projectFolderPath,
"--timeout",
"0",
Expand Down
12 changes: 9 additions & 3 deletions app/utils/local/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@ import { v4 as uuidv4 } from "uuid";

// Local imports
import { appMode } from "./app_mode.js";
import { commandExistsSync } from "./scripts.js";

function executablePath(execPath, execName) {
const osExecutableName = executableName(execName);
const resourcesPath = process.env.RESOURCES_PATH;
const mode = process.env.MODE;
const nodeEnv = process.env.NODE_ENV;
console.log("[executablePath]", { execPath, execName, mode, nodeEnv, resourcesPath });
if (mode === appMode.DESKTOP && nodeEnv === "production") {
const execPathInResources = path.join(resourcesPath, executableName(execName));
const execPathInResources = path.join(resourcesPath, osExecutableName);
if (fs.existsSync(execPathInResources)) {
console.log(`[executablePath] Found executable in resources path: ${execPathInResources}`);
return execPathInResources;
}
}
const localExecPath = path.join(execPath, executableName(execName));
const localExecPath = path.join(execPath, osExecutableName);
if (fs.existsSync(localExecPath)) {
console.log(`[executablePath] Found executable in local path: ${localExecPath}`);
return localExecPath;
}
throw new Error(`Executable not found: ${execName}`);
if (commandExistsSync(osExecutableName)) {
console.log(`[executablePath] Found executable in PATH: ${osExecutableName}`);
return osExecutableName;
}
throw new Error(`Executable not found: ${osExecutableName}`);
}

function executableName(execName) {
Expand Down
Loading