Skip to content

Commit

Permalink
can't find .runfile on non linux os (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
samyfodil authored Dec 13, 2024
1 parent 044f60b commit cc01700
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/spore-drive/clients/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@taubyte/spore-drive",
"version": "0.1.4",
"version": "0.1.5",
"service": "0.1.2",
"description": "",
"type": "module",
Expand Down
15 changes: 9 additions & 6 deletions pkg/spore-drive/clients/js/src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import cliProgress from "cli-progress";
import { spawn } from "child_process";
import * as tar from "tar";
import packageJson from "../package.json";
import { homedir } from "os";
import { homedir, platform } from "os";

import { fileURLToPath } from 'url';
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

Expand All @@ -32,11 +32,14 @@ export class Service {
}

private getConfigDir(): string {
const configDir = path.join(homedir(), ".config");
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir);
const plt = platform();
if (plt === "win32") {
return process.env.APPDATA || path.join(homedir(), "AppData", "Roaming");
} else if (plt === "darwin") {
return path.join(homedir(), "Library", "Application Support");
} else {
return process.env.XDG_CONFIG_HOME || path.join(homedir(), ".config");
}
return configDir;
}

private binaryExists(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion pkg/taucorder/clients/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@taubyte/taucorder",
"version": "0.1.0",
"version": "0.1.1",
"service": "0.2.0",
"description": "",
"type": "module",
Expand Down
21 changes: 14 additions & 7 deletions pkg/taucorder/clients/js/src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import cliProgress from "cli-progress";
import { spawn } from "child_process";
import * as tar from "tar";
import packageJson from "../package.json";
import { homedir } from "os";
import { homedir, platform } from "os";
import { TaucorderService } from "./Taucorder";

import { fileURLToPath } from 'url';
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

Expand All @@ -33,11 +33,14 @@ export class Service {
}

private getConfigDir(): string {
const configDir = path.join(homedir(), ".config");
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir);
const plt = platform();
if (plt === "win32") {
return process.env.APPDATA || path.join(homedir(), "AppData", "Roaming");
} else if (plt === "darwin") {
return path.join(homedir(), "Library", "Application Support");
} else {
return process.env.XDG_CONFIG_HOME || path.join(homedir(), ".config");
}
return configDir;
}

private binaryExists(): boolean {
Expand Down Expand Up @@ -186,7 +189,11 @@ export class Service {

public async getPort(): Promise<number | null> {
const runFile = this.loadRunFile();
if (runFile && this.isProcessRunning(runFile.pid) && await this.isServiceUp(runFile.port)) {
if (
runFile &&
this.isProcessRunning(runFile.pid) &&
(await this.isServiceUp(runFile.port))
) {
return runFile.port;
} else {
console.log("Service is not running.");
Expand Down

0 comments on commit cc01700

Please # to comment.