Skip to content

Commit

Permalink
stax home
Browse files Browse the repository at this point in the history
  • Loading branch information
kla committed Sep 12, 2024
1 parent d34f9ae commit c4d1d51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Command } from 'commander'
import { readFileSync } from 'fs'
import { existsSync, mkdirSync, readFileSync } from 'fs'
import { capture, run } from '~/shell'
import { exit, parseAndRemoveWildcardOptions, pp } from '~/utils'
import { StaxConfig } from '~/types'
import Stax from '~/stax'
import path from 'path'
import tmp from 'tmp'

const DEFAULT_CONTEXT_NAME = 'stax'
Expand Down Expand Up @@ -177,6 +178,12 @@ if (commandSeparator >= 0) {
}

tmp.setGracefulCleanup()

process.env.STAX_HOME = path.join(process.env.HOME, '.stax')

if (!existsSync(process.env.STAX_HOME))
mkdirSync(process.env.STAX_HOME)

process.on('SIGINT', () => { tmp.setGracefulCleanup(); process.exit() })
process.chdir(process.env.WORKING_DIRECTORY)
program.parse(args)
10 changes: 6 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { existsSync, readFileSync, writeFileSync } from 'fs'
import yaml from 'js-yaml'
import path = require('path')
import path from 'path'

const filename = path.resolve(process.env.HOME, '.stax')
function filename(): string {
return path.join(process.env.STAX_HOME, 'settings.yaml')
}

function load() {
return (existsSync(filename) && yaml.load(readFileSync(filename, 'utf-8'))) || {}
return (existsSync(filename()) && yaml.load(readFileSync(filename(), 'utf-8'))) || {}
}

const settings = {
Expand All @@ -17,7 +19,7 @@ const settings = {
write: function(name, value) {
const settings = { ...load() }
settings[name] = value
writeFileSync(filename, yaml.dump(settings), 'utf-8')
writeFileSync(filename(), yaml.dump(settings), 'utf-8')
}
}

Expand Down

0 comments on commit c4d1d51

Please sign in to comment.