diff --git a/packages/cli/package.json b/packages/cli/package.json index e2309695a17..217164c0b95 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@botpress/cli", - "version": "4.14.1", + "version": "4.14.3", "description": "Botpress CLI", "scripts": { "build": "pnpm run bundle && pnpm run template:gen", diff --git a/packages/cli/src/command-implementations/global-command.ts b/packages/cli/src/command-implementations/global-command.ts index aacc82ce207..ab5a47b926a 100644 --- a/packages/cli/src/command-implementations/global-command.ts +++ b/packages/cli/src/command-implementations/global-command.ts @@ -94,6 +94,7 @@ export abstract class GlobalCommand extends B ) } ;({ 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')) diff --git a/packages/cli/src/command-implementations/init-command.ts b/packages/cli/src/command-implementations/init-command.ts index 865717525f2..ef8d10fa4b7 100644 --- a/packages/cli/src/command-implementations/init-command.ts +++ b/packages/cli/src/command-implementations/init-command.ts @@ -80,14 +80,22 @@ export class InitCommand extends GlobalCommand { const name = await this._getName('plugin', template.defaultProjectName) const { fullName, shortName } = this._getFullNameAndShortName({ workspaceHandle, name }) - await this._copy({ - srcDir: template.absolutePath, - destDir: workDir, - name: shortName, - pkgJson: { - pluginName: fullName, - }, - }) + try { + await this._copy({ + srcDir: template.absolutePath, + destDir: workDir, + name: shortName, + pkgJson: { + pluginName: fullName, + }, + }) + } catch (error) { + if (error instanceof errors.AbortedOperationError) { + this.logger.log('Aborted') + return + } + throw error + } this.logger.success(`Plugin project initialized in ${chalk.bold(pathlib.join(workDir, shortName))}`) } @@ -182,9 +190,9 @@ export class InitCommand extends GlobalCommand { const dirName = utils.casing.to.kebabCase(name) const destination = pathlib.join(destDir, dirName) - const exist = await this._checkIfDestinationExists(destination) - if (exist) { - return + const destinationCanBeUsed = await this._checkIfDestinationCanBeUsed(destination) + if (!destinationCanBeUsed) { + throw new errors.AbortedOperationError() } await fs.promises.cp(srcDir, destination, { recursive: true }) @@ -198,17 +206,16 @@ export class InitCommand extends GlobalCommand { await fs.promises.writeFile(pkgJsonPath, JSON.stringify(updatedJson, null, 2)) } - private _checkIfDestinationExists = async (destination: string) => { + private _checkIfDestinationCanBeUsed = async (destination: string) => { if (fs.existsSync(destination)) { const override = await this.prompt.confirm( `Directory ${chalk.bold(destination)} already exists. Do you want to overwrite it?` ) if (!override) { - this.logger.log('Aborting') - return true + return false } } - return false + return true } } diff --git a/packages/cli/src/config.ts b/packages/cli/src/config.ts index 4439d99c3af..bbe020674fb 100644 --- a/packages/cli/src/config.ts +++ b/packages/cli/src/config.ts @@ -127,7 +127,7 @@ const globalSchema = { }, profile: { type: 'string', - description: 'The CLI profile defined in the $BP_BOTPRESS_HOME/.profiles json format file', + description: 'The CLI profile defined in the $BP_BOTPRESS_HOME/profiles.json json format file', }, } satisfies CommandSchema diff --git a/packages/cli/src/consts.ts b/packages/cli/src/consts.ts index 0d3465b480b..bd6dbd31a1e 100644 --- a/packages/cli/src/consts.ts +++ b/packages/cli/src/consts.ts @@ -18,7 +18,7 @@ export const cliRootDir = CLI_ROOT_DIR export const installDirName = 'bp_modules' export const outDirName = '.botpress' export const distDirName = 'dist' -export const profileFileName = '.profiles' +export const profileFileName = 'profiles.json' export const fromCliRootDir = {} diff --git a/packages/cli/src/errors.ts b/packages/cli/src/errors.ts index a3d806502a7..c3d48c6e488 100644 --- a/packages/cli/src/errors.ts +++ b/packages/cli/src/errors.ts @@ -163,3 +163,9 @@ export class ProjectDefinitionNotFoundError extends BotpressCLIError { super(message) } } + +export class AbortedOperationError extends BotpressCLIError { + public constructor() { + super('Aborted') + } +}