Skip to content

Commit

Permalink
Merge branch 'naynay/file-restructure' into mixmix/deploy_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix authored Sep 22, 2024
2 parents 33ae44e + 96ec283 commit b7e62bb
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,32 @@ export async function init (configPath = CONFIG_PATH, oldConfigPath = OLD_CONFIG
await set(newConfig, configPath)
}
}
function noop () {}

export async function get (configPath = CONFIG_PATH) {
const configBuffer = await readFile(configPath)

return deserialize(configBuffer.toString())
return readFile(configPath, 'utf-8')
.then(deserialize)
.catch(makeGetErrorHandler(configPath))
}

export function getSync (configPath = CONFIG_PATH): EntropyConfig {
try {
const configBuffer = readFileSync(configPath, 'utf8')
return deserialize(configBuffer)
} catch (err) {
console.log('CODE', err.code)
return makeGetErrorHandler(configPath)(err)
}
}

export async function set (config: EntropyConfig, configPath = CONFIG_PATH) {
await mkdirp(dirname(configPath))
await writeFile(configPath, serialize(config))
}

/* util */
function noop () {}

function makeGetErrorHandler (configPath) {
return function getErrorHandler (err) {
if (err.code !== 'ENOENT') throw err

const newConfig = migrateData(allMigrations, {})
Expand All @@ -76,8 +88,3 @@ export function getSync (configPath = CONFIG_PATH): EntropyConfig {
return newConfig
}
}

export async function set (config: EntropyConfig, configPath = CONFIG_PATH) {
await mkdirp(dirname(configPath))
await writeFile(configPath, serialize(config))
}

0 comments on commit b7e62bb

Please sign in to comment.