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.14.1",
"version": "4.14.3",
"description": "Botpress CLI",
"scripts": {
"build": "pnpm run bundle && pnpm run template:gen",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/command-implementations/global-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export abstract class GlobalCommand<C extends GlobalCommandDefinition> 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'))
Expand Down
37 changes: 22 additions & 15 deletions packages/cli/src/command-implementations/init-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,22 @@ export class InitCommand extends GlobalCommand<InitCommandDefinition> {
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))}`)
}

Expand Down Expand Up @@ -182,9 +190,9 @@ export class InitCommand extends GlobalCommand<InitCommandDefinition> {
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 })
Expand All @@ -198,17 +206,16 @@ export class InitCommand extends GlobalCommand<InitCommandDefinition> {
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
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,9 @@ export class ProjectDefinitionNotFoundError extends BotpressCLIError {
super(message)
}
}

export class AbortedOperationError extends BotpressCLIError {
public constructor() {
super('Aborted')
}
}
Loading