Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add $ROOT_DIR #70

Merged
merged 6 commits into from Mar 23, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -47,9 +47,11 @@ Station Core is configured using environment variables (see

The following configuration options are shared by all Station commands:

- `$XDG_STATE_HOME` _(string; optional)_: Station stores logs and module state
in the directory `$XDG_STATE_HOME/filecoin-station`. State home defaults to
`~/.local/state`.
- `$ROOT_DIR`_(string; optional)_: Station stores logs and module state in this
directory. Defaults to
- Linux: `${XDG_STATE_HOME:-~/.local/state}/filecoin-station-core`
- macOS: `~/Library/Application Support/app.filstation.core`
- Windows: `%LOCALAPPDATA%/Filecoin Station Core`

## Commands

Expand Down
50 changes: 39 additions & 11 deletions lib/paths.js
@@ -1,20 +1,48 @@
import { join, dirname } from 'node:path'
import { homedir } from 'node:os'
import { homedir, platform } from 'node:os'
import { fileURLToPath } from 'node:url'
import assert from 'node:assert'

const {
ROOT_DIR,
LOCALAPPDATA,
XDG_STATE_HOME = join(homedir(), '.local', 'state')
} = process.env

const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..')

export const getPaths = xdgStateHome => ({
export const getPaths = root => ({
repoRoot,
metrics: join(xdgStateHome, 'filecoin-station', 'logs', 'metrics.log'),
activity: join(xdgStateHome, 'filecoin-station', 'logs', 'activity.log'),
moduleStorage: join(xdgStateHome, 'filecoin-station', 'modules'),
moduleLogs: join(xdgStateHome, 'filecoin-station', 'logs', 'modules'),
allLogs: join(xdgStateHome, 'filecoin-station', 'logs', 'all.log'),
metrics: join(root, 'logs', 'metrics.log'),
activity: join(root, 'logs', 'activity.log'),
moduleStorage: join(root, 'modules'),
moduleLogs: join(root, 'logs', 'modules'),
allLogs: join(root, 'logs', 'all.log'),
moduleBinaries: join(repoRoot, 'modules'),
lockFile: join(xdgStateHome, 'filecoin-station', '.lock')
lockFile: join(root, '.lock')
})

export const paths = getPaths(
process.env.XDG_STATE_HOME || join(homedir(), '.local', 'state')
)
const getRoot = () => {
if (ROOT_DIR) {
return ROOT_DIR
}

switch (platform()) {
case 'darwin':
return join(
homedir(),
'Library',
'Application Support',
'app.filstation.core'
)
case 'win32':
assert(LOCALAPPDATA, '%LOCALAPPDATA% required')
return join(LOCALAPPDATA, 'Filecoin Station Core')
case 'linux':
return join(XDG_STATE_HOME, 'filecoin-station-core')
default:
throw new Error(`Unsupported platform: ${platform()}`)
}
}

export const paths = getPaths(getRoot())