Skip to content

Commit

Permalink
fix: use path.join
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoenig134 committed Feb 12, 2025
1 parent 5d4d6ae commit 15a4831
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/utils/ProcessManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "path"
import pm2 from "pm2"
import { Config } from "../connector-config/Config.js"
import { ReleaseManager } from "./ReleaseManager.js"
Expand Down Expand Up @@ -46,7 +47,7 @@ export class ProcessManager {
this.#pm2.start(
{
name: name,
script: `${connectorPath}/dist/index.js`,
script: path.join(connectorPath, "dist", "index.js"),
args: ["start", "-c", connectorFromConfig.configFilePath],
merge_logs: true,
output: connectorFromConfig.logFilePath,
Expand Down
13 changes: 7 additions & 6 deletions src/utils/ReleaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import chalk from "chalk"
import { spawn } from "child_process"
import fs from "fs"
import { Octokit } from "octokit"
import path from "path"
import { Readable } from "stream"
import { finished } from "stream/promises"
import { ReadableStream } from "stream/web"
import { getAppDir } from "./getAppDir.js"

export class ReleaseManager {
public async provideRelease(version: string): Promise<string> {
const releasesDir = `${getAppDir()}/releases`
const connectorDir = `${releasesDir}/connector-${version}`
const releasesDir = path.join(getAppDir(), "releases")
const connectorDir = path.join(releasesDir, `connector-${version}`)

if (fs.existsSync(`${connectorDir}/dist`) && fs.existsSync(`${connectorDir}/node_modules`)) return connectorDir
if (fs.existsSync(path.join(connectorDir, "dist")) && fs.existsSync(path.join(connectorDir, "node_modules"))) return connectorDir

const zipPath = await this.downloadConnector(releasesDir, version)

Expand Down Expand Up @@ -55,7 +56,7 @@ export class ReleaseManager {
private async downloadConnector(zipDir: string, version: string) {
if (!fs.existsSync(zipDir)) fs.mkdirSync(zipDir, { recursive: true })

const zipPath = `${zipDir}/connector-${version}.zip`
const zipPath = path.join(zipDir, `connector-${version}.zip`)
if (fs.existsSync(zipPath)) return zipPath

const release = await this.getGithubRelease(version)
Expand All @@ -74,14 +75,14 @@ export class ReleaseManager {
}

private extractConnector(connectorDir: string, zipPath: string) {
if (fs.existsSync(`${connectorDir}/dist`)) return
if (fs.existsSync(path.join(connectorDir, "dist"))) return

const zip = new AdmZip(zipPath)
zip.extractAllTo(connectorDir)
}

private async npmInstallConnector(connectorDir: string) {
if (fs.existsSync(`${connectorDir}/node_modules`)) return
if (fs.existsSync(path.join(connectorDir, "node_modules"))) return

await new Promise<void>((resolve, reject) => {
const npmInstall = spawn("npm", ["install", "--prefix", connectorDir, "--production"], { stdio: "ignore" })
Expand Down
5 changes: 3 additions & 2 deletions src/utils/getAppDir.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from "fs"
import path from "path"

export function getAppDir(): string {
const base = process.env.APPDATA ?? (process.platform === "darwin" ? `${process.env.HOME}/Library/Preferences` : `${process.env.HOME}/.local/share`)
const base = process.env.APPDATA ?? (process.platform === "darwin" ? path.join(process.env.HOME!, "Library", "Preferences") : path.join(process.env.HOME!, ".local", "share"))

const appDir = `${base}/enmeshed-connector-manager`
const appDir = path.join(base, "enmeshed-connector-manager")

if (!fs.existsSync(appDir)) {
fs.mkdirSync(appDir, { recursive: true })
Expand Down

0 comments on commit 15a4831

Please sign in to comment.