Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/cli",
"version": "4.25.0",
"version": "4.25.1",
"description": "Botpress CLI",
"scripts": {
"build": "pnpm run build:types && pnpm run bundle && pnpm run template:gen",
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/command-implementations/add-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export class AddCommand extends GlobalCommand<AddCommandDefinition> {
if (ref) {
return await this._addNewSinglePackage({ ...ref, alias: this.argv.alias })
}
const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath)

const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath).catch((thrown) => {
throw errors.BotpressCLIError.wrap(thrown, 'failed to read package.json file')
})

if (!pkgJson) {
this.logger.warn('No package.json found in the install path')
return
Expand Down
52 changes: 28 additions & 24 deletions packages/cli/src/command-implementations/global-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,39 @@ export abstract class GlobalCommand<C extends GlobalCommandDefinition> extends B
}

protected async getAuthenticatedClient(credentials: Partial<YargsConfig<typeof config.schemas.credentials>>) {
const cache = this.globalCache

let token: string | undefined
let workspaceId: string | undefined
let apiUrl: string | undefined
try {
const cache = this.globalCache

let token: string | undefined
let workspaceId: string | undefined
let apiUrl: string | undefined

if (this.argv.profile) {
if (credentials.token || credentials.workspaceId || credentials.apiUrl) {
this.logger.warn(
'You are currently using credential command line arguments or environment variables as well as a profile. Your profile has overwritten the variables'
)
}
;({ token, workspaceId, apiUrl } = await this.readProfileFromFS(this.argv.profile))
this.logger.log(`Using profile "${this.argv.profile}"`, { prefix: '👤' })
} else {
token = credentials.token ?? (await cache.get('token'))
workspaceId = credentials.workspaceId ?? (await cache.get('workspaceId'))
apiUrl = credentials.apiUrl ?? (await cache.get('apiUrl'))
}

if (this.argv.profile) {
if (credentials.token || credentials.workspaceId || credentials.apiUrl) {
this.logger.warn(
'You are currently using credential command line arguments or environment variables as well as a profile. Your profile has overwritten the variables'
)
if (!(token && workspaceId && apiUrl)) {
return null
}
;({ token, workspaceId, apiUrl } = await this.readProfileFromFS(this.argv.profile))
this.logger.log(`Using profile "${this.argv.profile}"`, { prefix: '👤' })
} else {
token = credentials.token ?? (await cache.get('token'))
workspaceId = credentials.workspaceId ?? (await cache.get('workspaceId'))
apiUrl = credentials.apiUrl ?? (await cache.get('apiUrl'))
}

if (!(token && workspaceId && apiUrl)) {
return null
}
if (apiUrl !== consts.defaultBotpressApiUrl) {
this.logger.log(`Using custom url ${apiUrl}`, { prefix: '🔗' })
}

if (apiUrl !== consts.defaultBotpressApiUrl) {
this.logger.log(`Using custom url ${apiUrl}`, { prefix: '🔗' })
return this.api.newClient({ apiUrl, token, workspaceId }, this.logger)
} catch (thrown) {
throw errors.BotpressCLIError.wrap(thrown, 'failed to create authenticated client')
}

return this.api.newClient({ apiUrl, token, workspaceId }, this.logger)
}

protected async readProfileFromFS(profile: string): Promise<ProfileCredentials> {
Expand Down
Loading