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 1 commit
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`.
- `$STATION_ROOT`_(string; optional)_: Station stores logs and module state in
bajtos marked this conversation as resolved.
Show resolved Hide resolved
this directory. Defaults to
- Linux: `${XDG_STATE_HOME:-~/.local/state}/@filecoin-station/core`
- macOS: `~/Library/Application Support/@filecoin-station/core`
- Windows: `%LOCALAPPDATA%/@filecoin-station/core`
bajtos marked this conversation as resolved.
Show resolved Hide resolved

## Commands

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

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

const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
const pkg = JSON.parse(await fs.readFile(join(repoRoot, 'package.json')))

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 (STATION_ROOT) {
return STATION_ROOT
}

switch (platform()) {
case 'darwin':
return join(homedir(), 'Library', 'Application Support', pkg.name)
case 'win32':
assert(LOCALAPPDATA, '%LOCALAPPDATA% required')
return join(LOCALAPPDATA, pkg.name)
case 'linux':
return join(XDG_STATE_HOME, pkg.name)
default:
throw new Error(`Unsupported platform: ${platform()}`)
}
}

export const paths = getPaths(getRoot())