Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #115 from web3-storage/merge_old_settings
Browse files Browse the repository at this point in the history
Merge old settings
  • Loading branch information
ice-breaker-tg committed Oct 4, 2022
2 parents b791339 + e7aab80 commit b301f2e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
49 changes: 26 additions & 23 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,43 @@ const serialize = ({ ...data }) =>
*/
const deserialize = (text) => CBOR.codec.decode(Buffer.from(text, 'binary'))

// @ts-ignore
// export const settings = new Conf({
// projectName: cliSettings.projectName,
// fileExtension: 'cbor',
// serialize,
// deserialize,
// })

// const client = new W3Client({
// //@ts-ignore
// serviceDID: cliSettings.W3_STORE_DID,
// serviceURL: cliSettings.SERVICE_URL,
// //@ts-ignore
// accessDID: cliSettings.ACCESS_DID,
// accessURL: cliSettings.ACCESS_URL,
// settings,
// })
//
// export default client

export function getSettings(profile = 'main') {
// TODO this will go away later?
function mergeSettings(profileSettings) {
if (profileSettings.size) {
return
}

const oldSettings = new Conf({
projectName: cliSettings.projectName,
fileExtension: 'cbor',
serialize,
deserialize,
})

if (oldSettings.size) {
profileSettings.store = { ...oldSettings.store }
}
}

export function getProfileSettings(profile = 'main') {
// @ts-ignore
return new Conf({
const profileSettings = new Conf({
projectName: 'w3up',
projectSuffix: '',
configName: profile,
fileExtension: 'cbor',
serialize,
deserialize,
})

// TODO: remove this when no longer needed.
mergeSettings(profileSettings)

return profileSettings
}

export function getClient(profile = 'main') {
const settings = getSettings(profile)
const settings = getProfileSettings(profile)

const client = new W3Client({
//@ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/commands/id.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ora from 'ora'

import { getClient, getSettings } from '../client.js'
import { getClient, getProfileSettings } from '../client.js'

/**
* @typedef {{reset?:boolean, profile: string}} Id
Expand All @@ -16,7 +16,7 @@ const exe = async (args) => {
const view = ora({ spinner: 'line' })

if (args.reset) {
getSettings(args.profile)?.clear()
getProfileSettings(args.profile)?.clear()
}

const client = getClient(args.profile)
Expand Down
6 changes: 3 additions & 3 deletions src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs'
import path from 'path'
import { pathToFileURL } from 'url'

import { getSettings } from './client.js'
import { getProfileSettings } from './client.js'

/**
*
Expand Down Expand Up @@ -76,7 +76,7 @@ export const checkPath = ({ path }) => {
* @param {import('yargs').Arguments<{profile?:string}>} argv
*/
export const hasID = ({ profile }) => {
const settings = getSettings(profile)
const settings = getProfileSettings(profile)

if (!settings.has('secret') && !settings.has('account_secret')) {
throw new Error(`You have not setup an id, please run w3up id first.`)
Expand All @@ -88,7 +88,7 @@ export const hasID = ({ profile }) => {
* @param {import('yargs').Arguments<{profile?:string}>} argv
*/
export const hasEmail = ({ profile }) => {
const settings = getSettings(profile)
const settings = getProfileSettings(profile)

if (!settings.has('email')) {
throw new Error(
Expand Down

0 comments on commit b301f2e

Please sign in to comment.