Skip to content

Commit

Permalink
fix: change resolve to resolvePath (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 authored Apr 5, 2022
1 parent 8810c8b commit 99c5054
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
29 changes: 17 additions & 12 deletions src/launcher.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { spawn } from 'child_process'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
import fetch from 'node-fetch'
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'
import { exit } from 'process'
import { resolve } from 'path'
import { spawn } from 'child_process'
import { rebuildElectronTray } from './electron'
import { BeeManager } from './lifecycle'
import { resolvePath } from './path'
import { rebuildElectronTray } from './electron'

export async function createConfigFileAndAddress() {
writeFileSync(resolvePath('config.yaml'), createStubConfiguration())
Expand All @@ -25,7 +24,7 @@ export async function createInitialTransaction() {
export async function runLauncher() {
const abortController = new AbortController()
if (!existsSync(resolvePath('bee'))) {
console.error(`Please compile bee and place it as follows: ${resolve('bee')}`)
console.error(`Please compile bee and place it as follows: ${resolvePath('bee')}`)
exit(1)
}
if (!existsSync(resolvePath('data-dir'))) {
Expand Down Expand Up @@ -74,26 +73,26 @@ full-node: false
chain-enable: false
cors-allowed-origins: '*'
use-postage-snapshot: true
data-dir: ${resolve('data-dir')}`
data-dir: ${resolvePath('data-dir')}`
}

function createConfiguration(transaction:string, blockHash: string) {
function createConfiguration(transaction: string, blockHash: string) {
return `${createStubConfiguration()}
transaction: ${transaction}
block-hash: ${blockHash}`
}

async function initializeBee() {
const configPath = resolve('config.yaml')
return runProcess(resolve('bee'), ['init', `--config=${configPath}`], onStdout, onStderr, new AbortController())
const configPath = resolvePath('config.yaml')
return runProcess(resolvePath('bee'), ['init', `--config=${configPath}`], onStdout, onStderr, new AbortController())
}

async function launchBee(abortController?: AbortController) {
if (!abortController) {
abortController = new AbortController()
}
const configPath = resolve('config.yaml')
return runProcess(resolve('bee'), ['start', `--config=${configPath}`], onStdout, onStderr, abortController)
const configPath = resolvePath('config.yaml')
return runProcess(resolvePath('bee'), ['start', `--config=${configPath}`], onStdout, onStderr, abortController)
}

function onStdout(data: string | Uint8Array) {
Expand All @@ -104,7 +103,13 @@ function onStderr(data: string | Uint8Array) {
process.stderr.write(data)
}

async function runProcess(command: string, args: string[], onStdout: (chunk: string | Uint8Array) => void, onStderr: (chunk: string | Uint8Array) => void, abortController: AbortController): Promise<number> {
async function runProcess(
command: string,
args: string[],
onStdout: (chunk: string | Uint8Array) => void,
onStderr: (chunk: string | Uint8Array) => void,
abortController: AbortController
): Promise<number> {
return new Promise((resolve, reject) => {
const subprocess = spawn(command, args, { signal: abortController.signal, killSignal: 'SIGINT' })
subprocess.stdout.on('data', onStdout)
Expand Down
4 changes: 2 additions & 2 deletions src/path.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join } from 'path'
import { app } from 'electron'
import { join, resolve } from 'path'

export function resolvePath(path: string) {
if (process.execPath.includes('node_modules/electron/dist/Electron.app')) {
return path
return resolve(path)
}
const appName = `${app.getName()}.app`
let execPath = process.execPath
Expand Down

0 comments on commit 99c5054

Please sign in to comment.