@botpress/cli 0.0.15 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.js +1 -0
- package/dist/api-client.js.map +7 -0
- package/dist/code-generation/action.js +1 -0
- package/dist/code-generation/action.js.map +7 -0
- package/dist/code-generation/channel.js +1 -0
- package/dist/code-generation/channel.js.map +7 -0
- package/dist/code-generation/configuration.js +1 -0
- package/dist/code-generation/configuration.js.map +7 -0
- package/dist/code-generation/const.js +1 -0
- package/dist/code-generation/const.js.map +7 -0
- package/dist/code-generation/event.js +1 -0
- package/dist/code-generation/event.js.map +7 -0
- package/dist/code-generation/index.js +1 -0
- package/dist/code-generation/index.js.map +7 -0
- package/dist/code-generation/integration-impl.js +1 -0
- package/dist/code-generation/integration-impl.js.map +7 -0
- package/dist/code-generation/integration-instance.js +1 -0
- package/dist/code-generation/integration-instance.js.map +7 -0
- package/dist/code-generation/integration-secret.js +1 -0
- package/dist/code-generation/integration-secret.js.map +7 -0
- package/dist/code-generation/message.js +1 -0
- package/dist/code-generation/message.js.map +7 -0
- package/dist/code-generation/module.js +1 -0
- package/dist/code-generation/module.js.map +7 -0
- package/dist/code-generation/typings.js +1 -0
- package/dist/code-generation/typings.js.map +7 -0
- package/dist/command-definitions.js +1 -0
- package/dist/command-definitions.js.map +7 -0
- package/dist/command-implementations/add-command.js +1 -0
- package/dist/command-implementations/add-command.js.map +7 -0
- package/dist/command-implementations/base-command.js +8 -1
- package/dist/command-implementations/base-command.js.map +7 -0
- package/dist/command-implementations/bot-commands.js +1 -0
- package/dist/command-implementations/bot-commands.js.map +7 -0
- package/dist/command-implementations/build-command.js +1 -0
- package/dist/command-implementations/build-command.js.map +7 -0
- package/dist/command-implementations/bundle-command.js +9 -1
- package/dist/command-implementations/bundle-command.js.map +7 -0
- package/dist/command-implementations/deploy-command.js +21 -3
- package/dist/command-implementations/deploy-command.js.map +7 -0
- package/dist/command-implementations/dev-command.js +1 -0
- package/dist/command-implementations/dev-command.js.map +7 -0
- package/dist/command-implementations/gen-command.js +1 -0
- package/dist/command-implementations/gen-command.js.map +7 -0
- package/dist/command-implementations/global-command.js +4 -1
- package/dist/command-implementations/global-command.js.map +7 -0
- package/dist/command-implementations/index.js +1 -0
- package/dist/command-implementations/index.js.map +7 -0
- package/dist/command-implementations/init-command.js +1 -0
- package/dist/command-implementations/init-command.js.map +7 -0
- package/dist/command-implementations/integration-commands.js +1 -0
- package/dist/command-implementations/integration-commands.js.map +7 -0
- package/dist/command-implementations/login-command.js +1 -0
- package/dist/command-implementations/login-command.js.map +7 -0
- package/dist/command-implementations/logout-command.js +1 -0
- package/dist/command-implementations/logout-command.js.map +7 -0
- package/dist/command-implementations/project-command.js +1 -0
- package/dist/command-implementations/project-command.js.map +7 -0
- package/dist/command-implementations/serve-command.js +1 -0
- package/dist/command-implementations/serve-command.js.map +7 -0
- package/dist/command-tree.js +1 -0
- package/dist/command-tree.js.map +7 -0
- package/dist/config.js +10 -4
- package/dist/config.js.map +7 -0
- package/dist/consts.js +1 -0
- package/dist/consts.js.map +7 -0
- package/dist/errors.js +27 -1
- package/dist/errors.js.map +7 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +7 -0
- package/dist/init.js +1 -0
- package/dist/init.js.map +7 -0
- package/dist/integration-ref.js +1 -0
- package/dist/integration-ref.js.map +7 -0
- package/dist/logger/base-logger.js +1 -0
- package/dist/logger/base-logger.js.map +7 -0
- package/dist/logger/index.js +1 -0
- package/dist/logger/index.js.map +7 -0
- package/dist/register-yargs.js +1 -0
- package/dist/register-yargs.js.map +7 -0
- package/dist/typings.js +1 -0
- package/dist/typings.js.map +7 -0
- package/dist/utils/cache-utils.js +1 -0
- package/dist/utils/cache-utils.js.map +7 -0
- package/dist/utils/case-utils.js +1 -0
- package/dist/utils/case-utils.js.map +7 -0
- package/dist/utils/esbuild-utils.js +1 -0
- package/dist/utils/esbuild-utils.js.map +7 -0
- package/dist/utils/event-emitter.js +1 -0
- package/dist/utils/event-emitter.js.map +7 -0
- package/dist/utils/file-watcher.js +1 -0
- package/dist/utils/file-watcher.js.map +7 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/path-utils.js +1 -0
- package/dist/utils/path-utils.js.map +7 -0
- package/dist/utils/prompt-utils.js +1 -0
- package/dist/utils/prompt-utils.js.map +7 -0
- package/dist/utils/require-utils.js +1 -0
- package/dist/utils/require-utils.js.map +7 -0
- package/dist/worker/child-entrypoint.js +1 -0
- package/dist/worker/child-entrypoint.js.map +7 -0
- package/dist/worker/child-wrapper.js +1 -0
- package/dist/worker/child-wrapper.js.map +7 -0
- package/dist/worker/config.js +1 -0
- package/dist/worker/config.js.map +7 -0
- package/dist/worker/index.js +1 -0
- package/dist/worker/index.js.map +7 -0
- package/dist/worker/is-child.js +1 -0
- package/dist/worker/is-child.js.map +7 -0
- package/dist/worker/worker-state.js +1 -0
- package/dist/worker/worker-state.js.map +7 -0
- package/dist/worker/worker.js +1 -0
- package/dist/worker/worker.js.map +7 -0
- package/package.json +5 -6
- package/templates/echo-bot/package.json +3 -3
- package/templates/empty-integration/.botpress/implementation/channels/channel/audio.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/card.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/carousel.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/choice.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/dropdown.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/file.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/image.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/location.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/markdown.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/text.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/channels/channel/video.ts +1 -1
- package/templates/empty-integration/.botpress/implementation/configuration.ts +1 -1
- package/templates/empty-integration/package.json +3 -3
- package/build.ts +0 -12
package/dist/api-client.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/api-client.ts"],
|
|
4
|
+
"sourcesContent": ["import { Client, Integration, isApiError } from '@botpress/client'\nimport _ from 'lodash'\nimport { formatIntegrationRef, IntegrationRef } from './integration-ref'\nimport type { Logger } from './logger'\n\nexport type PageLister<R extends object> = (t: { nextToken?: string }) => Promise<R & { meta: { nextToken?: string } }>\n\nexport type ApiClientProps = {\n host: string\n token: string\n workspaceId?: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: Client\n public readonly host: string\n public readonly token: string\n public readonly workspaceId?: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(props: ApiClientProps, private _logger: Logger) {\n const { host, token, workspaceId } = props\n this.client = new Client({ host, token, workspaceId })\n this.host = host\n this.token = token\n this.workspaceId = workspaceId\n }\n\n public async findIntegration(ref: IntegrationRef): Promise<Integration | undefined> {\n const formatted = formatIntegrationRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: IntegrationRef): Promise<Integration | undefined> {\n if (ref.type === 'id') {\n return this.validateStatus(() => this.client.getIntegration(ref).then((r) => r.integration), [404, 500]) // TODO: fix that\n }\n return this.validateStatus(() => this.client.getIntegrationByName(ref).then((r) => r.integration), [404, 500])\n }\n\n public async findPublicIntegration(ref: IntegrationRef): Promise<Integration | undefined> {\n if (ref.type === 'id') {\n return this.validateStatus(() => this.client.getPublicIntegrationById(ref).then((r) => r.integration), [404, 500])\n }\n return this.validateStatus(() => this.client.getPublicIntegration(ref).then((r) => r.integration), [404, 500])\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public async listAllPages<R extends object>(lister: PageLister<R>): Promise<R[]>\n public async listAllPages<R extends object, M>(lister: PageLister<R>, mapper?: (r: R) => M[]): Promise<M[]>\n public async listAllPages<R extends object, M>(lister: PageLister<R>, mapper?: (r: R) => M[]) {\n let nextToken: string | undefined\n const all: R[] = []\n\n do {\n const { meta, ...r } = await lister({ nextToken })\n all.push(r as R)\n nextToken = meta.nextToken\n } while (nextToken)\n\n if (!mapper) {\n return all\n }\n\n const mapped: M[] = all.flatMap((r) => mapper(r))\n return mapped\n }\n\n public async validateStatus<V>(fn: () => Promise<V>, allowedStatuses: number | number[]): Promise<V | undefined> {\n try {\n const v = await fn()\n return v\n } catch (err) {\n const allowedStatusesArray = _.isArray(allowedStatuses) ? allowedStatuses : [allowedStatuses]\n const isAllowed = isApiError(err) && err.code && allowedStatusesArray.includes(err.code)\n if (isAllowed) {\n return\n }\n throw err\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgD;AAChD,oBAAc;AACd,6BAAqD;AAkB9C,MAAM,UAAU;AAAA,EAQd,YAAY,OAA+B,SAAiB;AAAjB;AAChD,UAAM,EAAE,MAAM,OAAO,YAAY,IAAI;AACrC,SAAK,SAAS,IAAI,qBAAO,EAAE,MAAM,OAAO,YAAY,CAAC;AACrD,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAbgB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,OAAc,YAAY,CAAC,OAAuB,WAAmB,IAAI,UAAU,OAAO,MAAM;AAAA,EAUhG,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,CAAC;AACjD,UAAI,KAAK,CAAM;AACf,kBAAY,KAAK;AAAA,IACnB,SAAS;AAET,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AAEA,UAAM,SAAc,IAAI,QAAQ,CAAC,MAAM,OAAO,CAAC,CAAC;AAChD,WAAO;AAAA,EACT;AAAA,EAEA,MAAa,eAAkB,IAAsB,iBAA4D;AAC/G,QAAI;AACF,YAAM,IAAI,MAAM,GAAG;AACnB,aAAO;AAAA,IACT,SAAS,KAAP;AACA,YAAM,uBAAuB,cAAAA,QAAE,QAAQ,eAAe,IAAI,kBAAkB,CAAC,eAAe;AAC5F,YAAM,gBAAY,0BAAW,GAAG,KAAK,IAAI,QAAQ,qBAAqB,SAAS,IAAI,IAAI;AACvF,UAAI,WAAW;AACb;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["_"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/action.ts"],
|
|
4
|
+
"sourcesContent": ["import { compile } from 'json-schema-to-typescript'\nimport { casing } from '../utils'\nimport { Module, ModuleDef, ReExportTypeModule } from './module'\nimport type * as types from './typings'\n\ntype ActionInput = types.Action['input']\ntype ActionOutput = types.Action['output']\n\nexport class ActionInputModule extends Module {\n public static async create(input: ActionInput): Promise<ActionInputModule> {\n const schema = input.schema ?? {}\n const filename = 'input.ts'\n const def: ModuleDef = {\n path: filename,\n exportName: 'Input',\n content: await compile(schema, filename),\n }\n return new ActionInputModule(def)\n }\n}\n\nexport class ActionOutputModule extends Module {\n public static async create(output: ActionOutput): Promise<ActionOutputModule> {\n const schema = output.schema ?? {}\n const filename = 'output.ts'\n const def: ModuleDef = {\n path: filename,\n exportName: 'Output',\n content: await compile(schema, filename),\n }\n return new ActionOutputModule(def)\n }\n}\n\nexport class ActionModule extends ReExportTypeModule {\n public static async create(actionName: string, action: types.Action): Promise<ActionModule> {\n const inputModule = await ActionInputModule.create(action.input ?? {})\n const outputModule = await ActionOutputModule.create(action.output ?? {})\n\n const inst = new ActionModule({\n exportName: `Action${casing.to.pascalCase(actionName)}`,\n })\n\n inst.pushDep(inputModule)\n inst.pushDep(outputModule)\n\n return inst\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uCAAwB;AACxB,mBAAuB;AACvB,oBAAsD;AAM/C,MAAM,0BAA0B,qBAAO;AAAA,EAC5C,aAAoB,OAAO,OAAgD;AACzE,UAAM,SAAS,MAAM,UAAU,CAAC;AAChC,UAAM,WAAW;AACjB,UAAM,MAAiB;AAAA,MACrB,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,SAAS,UAAM,0CAAQ,QAAQ,QAAQ;AAAA,IACzC;AACA,WAAO,IAAI,kBAAkB,GAAG;AAAA,EAClC;AACF;AAEO,MAAM,2BAA2B,qBAAO;AAAA,EAC7C,aAAoB,OAAO,QAAmD;AAC5E,UAAM,SAAS,OAAO,UAAU,CAAC;AACjC,UAAM,WAAW;AACjB,UAAM,MAAiB;AAAA,MACrB,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,SAAS,UAAM,0CAAQ,QAAQ,QAAQ;AAAA,IACzC;AACA,WAAO,IAAI,mBAAmB,GAAG;AAAA,EACnC;AACF;AAEO,MAAM,qBAAqB,iCAAmB;AAAA,EACnD,aAAoB,OAAO,YAAoB,QAA6C;AAC1F,UAAM,cAAc,MAAM,kBAAkB,OAAO,OAAO,SAAS,CAAC,CAAC;AACrE,UAAM,eAAe,MAAM,mBAAmB,OAAO,OAAO,UAAU,CAAC,CAAC;AAExE,UAAM,OAAO,IAAI,aAAa;AAAA,MAC5B,YAAY,SAAS,oBAAO,GAAG,WAAW,UAAU;AAAA,IACtD,CAAC;AAED,SAAK,QAAQ,WAAW;AACxB,SAAK,QAAQ,YAAY;AAEzB,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/channel.ts"],
|
|
4
|
+
"sourcesContent": ["import bluebird from 'bluebird'\nimport { casing } from '../utils'\nimport { MessageModule } from './message'\nimport { ReExportTypeModule } from './module'\nimport type { Channel } from './typings'\n\nexport class ChannelModule extends ReExportTypeModule {\n public static async create(channelName: string, channel: Channel): Promise<ChannelModule> {\n const messages = channel.messages ?? {}\n const messageModules = await bluebird.map(Object.entries(messages), ([messageName, message]) =>\n MessageModule.create(messageName, message)\n )\n\n const inst = new ChannelModule({\n exportName: `Channel${casing.to.pascalCase(channelName)}`,\n })\n inst.pushDep(...messageModules)\n return inst\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAqB;AACrB,mBAAuB;AACvB,qBAA8B;AAC9B,oBAAmC;AAG5B,MAAM,sBAAsB,iCAAmB;AAAA,EACpD,aAAoB,OAAO,aAAqB,SAA0C;AACxF,UAAM,WAAW,QAAQ,YAAY,CAAC;AACtC,UAAM,iBAAiB,MAAM,gBAAAA,QAAS;AAAA,MAAI,OAAO,QAAQ,QAAQ;AAAA,MAAG,CAAC,CAAC,aAAa,OAAO,MACxF,6BAAc,OAAO,aAAa,OAAO;AAAA,IAC3C;AAEA,UAAM,OAAO,IAAI,cAAc;AAAA,MAC7B,YAAY,UAAU,oBAAO,GAAG,WAAW,WAAW;AAAA,IACxD,CAAC;AACD,SAAK,QAAQ,GAAG,cAAc;AAC9B,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["bluebird"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/configuration.ts"],
|
|
4
|
+
"sourcesContent": ["import { compile } from 'json-schema-to-typescript'\nimport { Module } from './module'\nimport type * as types from './typings'\n\nexport class ConfigurationModule extends Module {\n public static async create(configuration: types.Config): Promise<ConfigurationModule> {\n const schema = configuration.schema ?? {}\n const filename = 'configuration'\n return new ConfigurationModule({\n path: `${filename}.ts`,\n exportName: 'Configuration',\n content: await compile(schema, filename),\n })\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uCAAwB;AACxB,oBAAuB;AAGhB,MAAM,4BAA4B,qBAAO;AAAA,EAC9C,aAAoB,OAAO,eAA2D;AACpF,UAAM,SAAS,cAAc,UAAU,CAAC;AACxC,UAAM,WAAW;AACjB,WAAO,IAAI,oBAAoB;AAAA,MAC7B,MAAM,GAAG;AAAA,MACT,YAAY;AAAA,MACZ,SAAS,UAAM,0CAAQ,QAAQ,QAAQ;AAAA,IACzC,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/const.ts"],
|
|
4
|
+
"sourcesContent": ["export const GENERATED_HEADER = '/* tslint:disable */\\n// This file is generated\\n// Do not edit this file\\n\\n'\nexport const INDEX_FILE = 'index.ts'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,mBAAmB;AACzB,MAAM,aAAa;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/event.ts"],
|
|
4
|
+
"sourcesContent": ["import { compile } from 'json-schema-to-typescript'\nimport { casing } from '../utils'\nimport { Module, ModuleDef } from './module'\nimport type { Event } from './typings'\n\nexport class EventModule extends Module {\n public static async create(name: string, event: Event): Promise<EventModule> {\n const schema = event.schema ?? {}\n const def: ModuleDef = {\n path: `${name}.ts`,\n exportName: casing.to.pascalCase(name),\n content: await compile(schema, name),\n }\n return new EventModule(def)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uCAAwB;AACxB,mBAAuB;AACvB,oBAAkC;AAG3B,MAAM,oBAAoB,qBAAO;AAAA,EACtC,aAAoB,OAAO,MAAc,OAAoC;AAC3E,UAAM,SAAS,MAAM,UAAU,CAAC;AAChC,UAAM,MAAiB;AAAA,MACrB,MAAM,GAAG;AAAA,MACT,YAAY,oBAAO,GAAG,WAAW,IAAI;AAAA,MACrC,SAAS,UAAM,0CAAQ,QAAQ,IAAI;AAAA,IACrC;AACA,WAAO,IAAI,YAAY,GAAG;AAAA,EAC5B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/index.ts"],
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type { IntegrationDefinition } from '@botpress/sdk'\nimport pathlib from 'path'\nimport { casing } from '../utils'\nimport { INDEX_FILE } from './const'\nimport { IntegrationImplementationIndexModule } from './integration-impl'\nimport { IntegrationInstanceIndexModule } from './integration-instance'\nimport { IntegrationSecretIndexModule } from './integration-secret'\nimport type * as types from './typings'\n\nexport { File } from './typings'\nexport { secretEnvVariableName } from './integration-secret'\nexport const INTEGRATION_JSON = 'integration.json'\n\nexport const generateIntegrationImplementationTypings = async (\n integration: IntegrationDefinition,\n implementationTypingsPath: string\n): Promise<types.File[]> => {\n const indexModule = await IntegrationImplementationIndexModule.create(integration)\n indexModule.unshift(implementationTypingsPath)\n return indexModule.flatten()\n}\n\nexport const generateIntegrationSecrets = async (\n integration: IntegrationDefinition,\n secretsPath: string\n): Promise<types.File[]> => {\n const indexModule = await IntegrationSecretIndexModule.create(integration)\n indexModule.unshift(secretsPath)\n return indexModule.flatten()\n}\n\nexport const generateIntegrationIndex = async (\n implementationTypingsPath: string,\n implementationSecretsPath: string\n): Promise<types.File> => {\n let content = ''\n content += `export * from './${implementationTypingsPath}'\\n`\n content += `export * from './${implementationSecretsPath}'\\n`\n return {\n path: INDEX_FILE,\n content,\n }\n}\n\nexport type IntegrationInstanceJson = {\n name: string\n version: string\n id: string\n}\n\nexport const generateIntegrationInstance = async (\n integration: client.Integration,\n installPath: string\n): Promise<types.File[]> => {\n const indexModule = await IntegrationInstanceIndexModule.create(integration)\n const dirname = casing.to.kebabCase(integration.name)\n indexModule.unshift(installPath, dirname)\n const files = indexModule.flatten()\n\n const { name, version, id } = integration\n const json: IntegrationInstanceJson = {\n name,\n version,\n id,\n }\n files.push({\n path: pathlib.join(installPath, dirname, INTEGRATION_JSON),\n content: JSON.stringify(json, null, 2),\n })\n\n return files\n}\n\nexport const generateBotIndex = async (installPath: string, instances: string[]): Promise<types.File> => ({\n path: INDEX_FILE,\n content: instances.map((instance) => `export * from './${installPath}/${instance}'`).join('\\n'),\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAoB;AACpB,mBAAuB;AACvB,mBAA2B;AAC3B,8BAAqD;AACrD,kCAA+C;AAC/C,gCAA6C;AAG7C,qBAAqB;AACrB,IAAAA,6BAAsC;AAC/B,MAAM,mBAAmB;AAEzB,MAAM,2CAA2C,OACtD,aACA,8BAC0B;AAC1B,QAAM,cAAc,MAAM,6DAAqC,OAAO,WAAW;AACjF,cAAY,QAAQ,yBAAyB;AAC7C,SAAO,YAAY,QAAQ;AAC7B;AAEO,MAAM,6BAA6B,OACxC,aACA,gBAC0B;AAC1B,QAAM,cAAc,MAAM,uDAA6B,OAAO,WAAW;AACzE,cAAY,QAAQ,WAAW;AAC/B,SAAO,YAAY,QAAQ;AAC7B;AAEO,MAAM,2BAA2B,OACtC,2BACA,8BACwB;AACxB,MAAI,UAAU;AACd,aAAW,oBAAoB;AAAA;AAC/B,aAAW,oBAAoB;AAAA;AAC/B,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,EACF;AACF;AAQO,MAAM,8BAA8B,OACzC,aACA,gBAC0B;AAC1B,QAAM,cAAc,MAAM,2DAA+B,OAAO,WAAW;AAC3E,QAAM,UAAU,oBAAO,GAAG,UAAU,YAAY,IAAI;AACpD,cAAY,QAAQ,aAAa,OAAO;AACxC,QAAM,QAAQ,YAAY,QAAQ;AAElC,QAAM,EAAE,MAAM,SAAS,GAAG,IAAI;AAC9B,QAAM,OAAgC;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,KAAK;AAAA,IACT,MAAM,YAAAC,QAAQ,KAAK,aAAa,SAAS,gBAAgB;AAAA,IACzD,SAAS,KAAK,UAAU,MAAM,MAAM,CAAC;AAAA,EACvC,CAAC;AAED,SAAO;AACT;AAEO,MAAM,mBAAmB,OAAO,aAAqB,eAA8C;AAAA,EACxG,MAAM;AAAA,EACN,SAAS,UAAU,IAAI,CAAC,aAAa,oBAAoB,eAAe,WAAW,EAAE,KAAK,IAAI;AAChG;",
|
|
6
|
+
"names": ["import_integration_secret", "pathlib"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/integration-impl.ts"],
|
|
4
|
+
"sourcesContent": ["import type { IntegrationDefinition } from '@botpress/sdk'\nimport bluebird from 'bluebird'\nimport { ActionModule } from './action'\nimport { ChannelModule } from './channel'\nimport { ConfigurationModule } from './configuration'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { EventModule } from './event'\nimport { Module, ModuleDef, ReExportTypeModule } from './module'\nimport type * as types from './typings'\n\nexport class IntegrationImplementationIndexModule extends Module {\n public static async create(integration: IntegrationDefinition): Promise<IntegrationImplementationIndexModule> {\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n\n const actionsModule = await ActionsModule.create(integration.actions ?? {})\n actionsModule.unshift('actions')\n\n const channelsModule = await ChannelsModule.create(integration.channels ?? {})\n channelsModule.unshift('channels')\n\n const eventsModule = await EventsModule.create(integration.events ?? {})\n eventsModule.unshift('events')\n\n const { name, version } = integration\n const inst = new IntegrationImplementationIndexModule(\n configModule,\n actionsModule,\n channelsModule,\n eventsModule,\n { name, version },\n {\n path: INDEX_FILE,\n exportName: 'Integration',\n content: '',\n }\n )\n\n inst.pushDep(configModule)\n inst.pushDep(actionsModule)\n inst.pushDep(channelsModule)\n inst.pushDep(eventsModule)\n return inst\n }\n\n private constructor(\n private configModule: ConfigurationModule,\n private actionsModule: ActionsModule,\n private channelsModule: ChannelsModule,\n private eventsModule: EventsModule,\n private integrationID: { name: string; version: string },\n def: ModuleDef\n ) {\n super(def)\n }\n\n public override get content(): string {\n let content = GENERATED_HEADER\n\n const { configModule, actionsModule, channelsModule, eventsModule } = this\n\n content += 'import * as sdk from \"@botpress/sdk\";\\n\\n'\n\n const configImport = configModule.import(this)\n const actionsImport = actionsModule.import(this)\n const channelsImport = channelsModule.import(this)\n const eventsImport = eventsModule.import(this)\n\n content += `import type * as ${configModule.name} from \"./${configImport}\";\\n`\n content += `import type * as ${actionsModule.name} from \"./${actionsImport}\";\\n`\n content += `import type * as ${channelsModule.name} from \"./${channelsImport}\";\\n`\n content += `import type * as ${eventsModule.name} from \"./${eventsImport}\";\\n`\n content += `export * as ${configModule.name} from \"./${configImport}\";\\n`\n content += `export * as ${actionsModule.name} from \"./${actionsImport}\";\\n`\n content += `export * as ${channelsModule.name} from \"./${channelsImport}\";\\n`\n content += `export * as ${eventsModule.name} from \"./${eventsImport}\";\\n`\n\n content += '\\n'\n\n content += `export class Integration\n extends sdk.Integration<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}> {}\\n`\n\n return content\n }\n}\n\nclass ChannelsModule extends ReExportTypeModule {\n public static async create(channels: Record<string, types.Channel>): Promise<ChannelsModule> {\n const channelModules = await bluebird.map(Object.entries(channels), async ([channelName, channel]) => {\n const mod = await ChannelModule.create(channelName, channel)\n return mod.unshift(channelName)\n })\n const inst = new ChannelsModule({ exportName: 'Channels' })\n inst.pushDep(...channelModules)\n return inst\n }\n}\n\nclass ActionsModule extends ReExportTypeModule {\n public static async create(actions: Record<string, types.Action>): Promise<ActionsModule> {\n const actionModules = await bluebird.map(Object.entries(actions), async ([actionName, action]) => {\n const mod = await ActionModule.create(actionName, action)\n return mod.unshift(actionName)\n })\n\n const inst = new ActionsModule({\n exportName: 'Actions',\n })\n\n inst.pushDep(...actionModules)\n return inst\n }\n}\n\nclass EventsModule extends ReExportTypeModule {\n public static async create(events: Record<string, types.Event>): Promise<EventsModule> {\n const eventModules = await bluebird.map(Object.entries(events), async ([eventName, event]) =>\n EventModule.create(eventName, event)\n )\n\n const inst = new EventsModule({\n exportName: 'Events',\n })\n inst.pushDep(...eventModules)\n return inst\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqB;AACrB,oBAA6B;AAC7B,qBAA8B;AAC9B,2BAAoC;AACpC,mBAA6C;AAC7C,mBAA4B;AAC5B,oBAAsD;AAG/C,MAAM,6CAA6C,qBAAO;AAAA,EAkCvD,YACE,cACA,eACA,gBACA,cACA,eACR,KACA;AACA,UAAM,GAAG;AAPD;AACA;AACA;AACA;AACA;AAAA,EAIV;AAAA,EA1CA,aAAoB,OAAO,aAAmF;AAC5G,UAAM,eAAe,MAAM,yCAAoB,OAAO,YAAY,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CAAC;AAEjG,UAAM,gBAAgB,MAAM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
+
"names": ["bluebird"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/integration-instance.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Integration } from '@botpress/client'\nimport { casing } from '../utils'\nimport { ConfigurationModule } from './configuration'\nimport { INDEX_FILE } from './const'\nimport { Module, ModuleDef } from './module'\n\nconst CONTENT = ({\n name,\n className,\n propsName,\n version,\n id,\n}: {\n name: string\n className: string\n propsName: string\n version: string\n id: string\n}) => `\nimport type { IntegrationInstance } from '@botpress/sdk'\nimport type { Configuration } from './configuration'\n\n\nexport type ${propsName} = {\n enabled: true\n config: Configuration\n} | {\n enabled: false\n config?: Configuration\n}\n\nexport class ${className} implements IntegrationInstance {\n \n public readonly enabled: boolean\n\n public readonly name = '${name}'\n public readonly version = '${version}'\n public readonly id = '${id}'\n\n public readonly configuration: Configuration\n\n constructor(props?: ${propsName}) {\n this.enabled = props?.enabled ?? false\n this.configuration = props?.config ?? <Configuration>{}\n }\n}\n`\n\nexport class IntegrationInstanceIndexModule extends Module {\n public static async create(integration: Integration): Promise<IntegrationInstanceIndexModule> {\n const { name, version, id } = integration\n\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n\n const exportName = casing.to.pascalCase(name)\n\n const content = CONTENT({ name, className: exportName, propsName: `${exportName}Props`, version, id })\n const inst = new IntegrationInstanceIndexModule({ path: INDEX_FILE, content, exportName })\n\n inst.pushDep(configModule)\n\n return inst\n }\n\n private constructor(def: ModuleDef) {\n super(def)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuB;AACvB,2BAAoC;AACpC,mBAA2B;AAC3B,oBAAkC;AAElC,MAAM,UAAU,CAAC;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AAAA;AAAA;AAAA;AAAA;AAAA,cAKQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAQC;AAAA;AAAA;AAAA;AAAA,4BAIa;AAAA,+BACG;AAAA,0BACL;AAAA;AAAA;AAAA;AAAA,wBAIF;AAAA;AAAA;AAAA;AAAA;AAAA;AAOjB,MAAM,uCAAuC,qBAAO;AAAA,EACzD,aAAoB,OAAO,aAAmE;AAC5F,UAAM,EAAE,MAAM,SAAS,GAAG,IAAI;AAE9B,UAAM,eAAe,MAAM,yCAAoB,OAAO,YAAY,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CAAC;AAEjG,UAAM,aAAa,oBAAO,GAAG,WAAW,IAAI;AAE5C,UAAM,UAAU,QAAQ,EAAE,MAAM,WAAW,YAAY,WAAW,GAAG,mBAAmB,SAAS,GAAG,CAAC;AACrG,UAAM,OAAO,IAAI,+BAA+B,EAAE,MAAM,yBAAY,SAAS,WAAW,CAAC;AAEzF,SAAK,QAAQ,YAAY;AAEzB,WAAO;AAAA,EACT;AAAA,EAEQ,YAAY,KAAgB;AAClC,UAAM,GAAG;AAAA,EACX;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/integration-secret.ts"],
|
|
4
|
+
"sourcesContent": ["import type { IntegrationDefinition } from '@botpress/sdk'\nimport { casing } from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { Module } from './module'\n\nexport const secretEnvVariableName = (secretName: string) => `SECRET_${casing.to.screamingSnakeCase(secretName)}`\n\nexport class IntegrationSecretIndexModule extends Module {\n public static async create(integration: IntegrationDefinition): Promise<IntegrationSecretIndexModule> {\n let content = GENERATED_HEADER\n content += 'class Secrets {\\n'\n for (const secretName of integration.secrets ?? []) {\n const envVariableName = secretEnvVariableName(secretName)\n const fieldName = casing.to.screamingSnakeCase(secretName)\n content += ` public get ${fieldName}(): string {\\n`\n content += ` const envVarValue = process.env.${envVariableName}\\n`\n content += ` if (!envVarValue) { throw new Error('Missing environment variable ${envVariableName}') }\\n`\n content += ' return envVarValue\\n'\n content += ' }\\n'\n }\n content += '}\\n'\n content += 'export const secrets = new Secrets()\\n'\n return new IntegrationSecretIndexModule({ content, exportName: 'secrets', path: INDEX_FILE })\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuB;AACvB,mBAA6C;AAC7C,oBAAuB;AAEhB,MAAM,wBAAwB,CAAC,eAAuB,UAAU,oBAAO,GAAG,mBAAmB,UAAU;AAEvG,MAAM,qCAAqC,qBAAO;AAAA,EACvD,aAAoB,OAAO,aAA2E;AACpG,QAAI,UAAU;AACd,eAAW;AACX,eAAW,cAAc,YAAY,WAAW,CAAC,GAAG;AAClD,YAAM,kBAAkB,sBAAsB,UAAU;AACxD,YAAM,YAAY,oBAAO,GAAG,mBAAmB,UAAU;AACzD,iBAAW,gBAAgB;AAAA;AAC3B,iBAAW,uCAAuC;AAAA;AAClD,iBAAW,yEAAyE;AAAA;AACpF,iBAAW;AACX,iBAAW;AAAA,IACb;AACA,eAAW;AACX,eAAW;AACX,WAAO,IAAI,6BAA6B,EAAE,SAAS,YAAY,WAAW,MAAM,wBAAW,CAAC;AAAA,EAC9F;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/message.ts"],
|
|
4
|
+
"sourcesContent": ["import { compile } from 'json-schema-to-typescript'\nimport { casing } from '../utils'\nimport { Module, ModuleDef } from './module'\nimport type { Message } from './typings'\n\nexport class MessageModule extends Module {\n public static async create(name: string, message: Message): Promise<MessageModule> {\n const schema = message.schema ?? {}\n const def: ModuleDef = {\n path: `${name}.ts`,\n exportName: casing.to.pascalCase(name),\n content: await compile(schema, name),\n }\n return new MessageModule(def)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uCAAwB;AACxB,mBAAuB;AACvB,oBAAkC;AAG3B,MAAM,sBAAsB,qBAAO;AAAA,EACxC,aAAoB,OAAO,MAAc,SAA0C;AACjF,UAAM,SAAS,QAAQ,UAAU,CAAC;AAClC,UAAM,MAAiB;AAAA,MACrB,MAAM,GAAG;AAAA,MACT,YAAY,oBAAO,GAAG,WAAW,IAAI;AAAA,MACrC,SAAS,UAAM,0CAAQ,QAAQ,IAAI;AAAA,IACrC;AACA,WAAO,IAAI,cAAc,GAAG;AAAA,EAC9B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/module.ts"],
|
|
4
|
+
"sourcesContent": ["import { posix as pathlib } from 'path'\nimport * as utils from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport type { File } from './typings'\n\nexport type ModuleDef = File & {\n exportName: string\n}\n\nexport abstract class Module implements File {\n private _localDependencies: Module[] = []\n\n public get path(): string {\n return this._def.path\n }\n\n public get content(): string {\n return this._def.content\n }\n\n public get name(): string {\n const basename = pathlib.basename(this.path)\n if (basename === INDEX_FILE) {\n const dirname = pathlib.basename(pathlib.dirname(this.path))\n return utils.casing.to.camelCase(dirname)\n }\n const withoutExtension = utils.path.rmExtension(basename)\n return utils.casing.to.camelCase(withoutExtension)\n }\n\n public get exports(): string {\n return this._def.exportName\n }\n\n public get deps(): Module[] {\n return [...this._localDependencies]\n }\n\n protected constructor(private _def: ModuleDef) {}\n\n public pushDep(...dependencies: Module[]): this {\n this._localDependencies.push(...dependencies)\n return this\n }\n\n public unshift(...basePath: string[]): this {\n this._def = {\n ...this._def,\n path: pathlib.join(...basePath, this._def.path),\n }\n this._localDependencies = this._localDependencies.map((d) => d.unshift(...basePath))\n return this\n }\n\n public flatten(): File[] {\n return [this, ...this._localDependencies.flatMap((d) => d.flatten())]\n }\n\n public import(base: Module): string {\n let relativePath = pathlib.relative(pathlib.dirname(base.path), this.path)\n relativePath = pathlib.join('.', relativePath)\n return utils.path.rmExtension(relativePath)\n }\n}\n\nexport abstract class ReExportTypeModule extends Module {\n protected constructor(def: { exportName: string }) {\n super({\n ...def,\n path: INDEX_FILE,\n content: '',\n })\n }\n\n public override get content(): string {\n let content = GENERATED_HEADER\n const dependencies = this.deps\n const { exports: className } = this\n\n for (const m of dependencies) {\n const { name } = m\n const importFrom = m.import(this)\n content += `import type * as ${name} from \"./${importFrom}\";\\n`\n content += `export * as ${name} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n content += `export type ${className} = {\\n`\n for (const { name, exports } of dependencies) {\n content += ` ${name}: ${name}.${exports};\\n`\n }\n content += '}\\n'\n\n return content\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AACjC,YAAuB;AACvB,mBAA6C;AAOtC,MAAe,OAAuB;AAAA,EA6BjC,YAAoB,MAAiB;AAAjB;AAAA,EAAkB;AAAA,EA5BxC,qBAA+B,CAAC;AAAA,EAExC,IAAW,OAAe;AACxB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAW,UAAkB;AAC3B,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAW,OAAe;AACxB,UAAM,WAAW,YAAAA,MAAQ,SAAS,KAAK,IAAI;AAC3C,QAAI,aAAa,yBAAY;AAC3B,YAAM,UAAU,YAAAA,MAAQ,SAAS,YAAAA,MAAQ,QAAQ,KAAK,IAAI,CAAC;AAC3D,aAAO,MAAM,OAAO,GAAG,UAAU,OAAO;AAAA,IAC1C;AACA,UAAM,mBAAmB,MAAM,KAAK,YAAY,QAA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W,oBAAoB,gBAAgB;AAAA;AAC/C,iBAAW,eAAe,gBAAgB;AAAA;AAAA,IAC5C;AAEA,eAAW;AAEX,eAAW,eAAe;AAAA;AAC1B,eAAW,EAAE,MAAM,QAAQ,KAAK,cAAc;AAC5C,iBAAW,KAAK,SAAS,QAAQ;AAAA;AAAA,IACnC;AACA,eAAW;AAEX,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["pathlib"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/code-generation/typings.ts"],
|
|
4
|
+
"sourcesContent": ["import type { IntegrationDefinition } from '@botpress/sdk'\nimport type { compile } from 'json-schema-to-typescript'\n\nexport type File = { path: string; content: string }\nexport type Schema = Parameters<typeof compile>[0]\n\nexport type Def<T> = Exclude<T, undefined>\nexport type Config = Def<IntegrationDefinition['configuration']>\nexport type Channel = Def<IntegrationDefinition['channels']>[string]\nexport type Message = Def<Channel['messages']>[string]\nexport type Action = Def<IntegrationDefinition['actions']>[string]\nexport type Event = Def<IntegrationDefinition['events']>[string]\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/command-definitions.ts"],
|
|
4
|
+
"sourcesContent": ["import type { DefinitionTree } from './command-tree'\nimport * as config from './config'\n\nexport default {\n login: { description: 'Login to Botpress Cloud', schema: config.schemas.login },\n logout: { description: 'Logout of Botpress Cloud', schema: config.schemas.logout },\n bots: {\n description: 'Bot related commands',\n subcommands: {\n create: { description: 'Create new bot', schema: config.schemas.createBot, alias: 'new' },\n get: { description: 'Get bot', schema: config.schemas.getBot },\n delete: { description: 'Delete bot', schema: config.schemas.deleteBot },\n list: { description: 'List bots', schema: config.schemas.listBots, alias: 'ls' },\n },\n },\n integrations: {\n description: 'Integration related commands',\n subcommands: {\n get: { description: 'Get integration', schema: config.schemas.getIntegration },\n delete: { description: 'Delete integration', schema: config.schemas.deleteIntegration },\n list: { description: 'List integrations', schema: config.schemas.listIntegrations, alias: 'ls' },\n },\n },\n init: { description: 'Initialize a new project', schema: config.schemas.init },\n generate: { description: 'Generate typings for intellisense', schema: config.schemas.generate, alias: 'gen' },\n bundle: { description: 'Bundle a botpress project', schema: config.schemas.bundle },\n build: { description: 'Generate typings and bundle a botpress project', schema: config.schemas.build },\n serve: { description: 'Serve your project locally', schema: config.schemas.serve },\n deploy: { description: 'Deploy your project to the cloud', schema: config.schemas.deploy },\n add: { description: 'Install an integration in your bot', schema: config.schemas.add },\n dev: { description: 'Run your project in dev mode', schema: config.schemas.dev },\n} satisfies DefinitionTree\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AAExB,IAAO,8BAAQ;AAAA,EACb,OAAO,EAAE,aAAa,2BAA2B,QAAQ,OAAO,QAAQ,MAAM;AAAA,EAC9E,QAAQ,EAAE,aAAa,4BAA4B,QAAQ,OAAO,QAAQ,OAAO;AAAA,EACjF,MAAM;AAAA,IACJ,aAAa;AAAA,IACb,aAAa;AAAA,MACX,QAAQ,EAAE,aAAa,kBAAkB,QAAQ,OAAO,QAAQ,WAAW,OAAO,MAAM;AAAA,MACxF,KAAK,EAAE,aAAa,WAAW,QAAQ,OAAO,QAAQ,OAAO;AAAA,MAC7D,QAAQ,EAAE,aAAa,cAAc,QAAQ,OAAO,QAAQ,UAAU;AAAA,MACtE,MAAM,EAAE,aAAa,aAAa,QAAQ,OAAO,QAAQ,UAAU,OAAO,KAAK;AAAA,IACjF;AAAA,EACF;AAAA,EACA,cAAc;AAAA,IACZ,aAAa;AAAA,IACb,aAAa;AAAA,MACX,KAAK,EAAE,aAAa,mBAAmB,QAAQ,OAAO,QAAQ,eAAe;AAAA,MAC7E,QAAQ,EAAE,aAAa,sBAAsB,QAAQ,OAAO,QAAQ,kBAAkB;AAAA,MACtF,MAAM,EAAE,aAAa,qBAAqB,QAAQ,OAAO,QAAQ,kBAAkB,OAAO,KAAK;AAAA,IACjG;AAAA,EACF;AAAA,EACA,MAAM,EAAE,aAAa,4BAA4B,QAAQ,OAAO,QAAQ,KAAK;AAAA,EAC7E,UAAU,EAAE,aAAa,qCAAqC,QAAQ,OAAO,QAAQ,UAAU,OAAO,MAAM;AAAA,EAC5G,QAAQ,EAAE,aAAa,6BAA6B,QAAQ,OAAO,QAAQ,OAAO;AAAA,EAClF,OAAO,EAAE,aAAa,kDAAkD,QAAQ,OAAO,QAAQ,MAAM;AAAA,EACrG,OAAO,EAAE,aAAa,8BAA8B,QAAQ,OAAO,QAAQ,MAAM;AAAA,EACjF,QAAQ,EAAE,aAAa,oCAAoC,QAAQ,OAAO,QAAQ,OAAO;AAAA,EACzF,KAAK,EAAE,aAAa,sCAAsC,QAAQ,OAAO,QAAQ,IAAI;AAAA,EACrF,KAAK,EAAE,aAAa,gCAAgC,QAAQ,OAAO,QAAQ,IAAI;AACjF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/add-command.ts"],
|
|
4
|
+
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport * as pathlib from 'path'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parseIntegrationRef } from '../integration-ref'\nimport { ProjectCommand } from './project-command'\n\ntype IntegrationInstallDir = codegen.IntegrationInstanceJson & {\n dirname: string\n}\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends ProjectCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n throw new errors.ExclusiveBotFeatureError()\n }\n\n const integrationRef = this.argv.integrationRef\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(integrationRef)\n }\n\n const integration = await api.findIntegration(parsedRef)\n if (!integration) {\n throw new errors.BotpressCLIError(`Integration \"${integrationRef}\" not found`)\n }\n\n const allInstances = await this._listIntegrationInstances()\n const existingInstance = allInstances.find((i) => i.name === integration.name)\n if (existingInstance) {\n this.logger.warn(`Integration with name \"${integration.name}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing instance?')\n if (!res) {\n this.logger.log('Aborted')\n return\n }\n\n await this._uninstallIntegration(existingInstance)\n }\n\n await this._generateIntegrationInstance(integration)\n }\n\n private async _listIntegrationInstances(): Promise<IntegrationInstallDir[]> {\n const installPath = this.projectPaths.abs.installDir\n if (!fs.existsSync(installPath)) {\n this.logger.debug('Install path does not exist. Skipping listing of integration instances')\n return []\n }\n\n const allFiles = await fs.promises.readdir(installPath)\n const allPaths = allFiles.map((name) => pathlib.join(installPath, name))\n const directories = await bluebird.filter(allPaths, async (path) => {\n const stat = await fs.promises.stat(path)\n return stat.isDirectory()\n })\n\n let jsons = directories.map((root) => ({ root, json: pathlib.join(root, codegen.INTEGRATION_JSON) }))\n jsons = jsons.filter(({ json: x }) => fs.existsSync(x))\n\n return bluebird.map(jsons, async ({ root, json }) => {\n const content: string = await fs.promises.readFile(json, 'utf-8')\n const { name, version, id } = JSON.parse(content) as codegen.IntegrationInstanceJson\n const dirname = pathlib.basename(root)\n return {\n dirname,\n id,\n name,\n version,\n }\n })\n }\n\n private async _uninstallIntegration(instance: IntegrationInstallDir) {\n const installDir = this.projectPaths.abs.installDir\n const instancePath = pathlib.join(installDir, instance.dirname)\n await fs.promises.rm(instancePath, { recursive: true })\n await this._generateBotIndex()\n }\n\n private async _generateIntegrationInstance(integration: bpclient.Integration) {\n const line = this.logger.line()\n\n const { name, version } = integration\n line.started(`Installing ${chalk.bold(name)} v${version}...`)\n\n const instanceFiles = await codegen.generateIntegrationInstance(\n integration,\n this.projectPaths.rel('outDir').installDir\n )\n await this.writeGeneratedFilesToOutFolder(instanceFiles)\n await this._generateBotIndex()\n\n const rel = this.projectPaths.rel('workDir')\n line.success(`Installed integration available at ${chalk.grey(rel.outDir)}`)\n }\n\n private async _generateBotIndex() {\n const allInstances = await this._listIntegrationInstances()\n const indexFile = await codegen.generateBotIndex(\n this.projectPaths.rel('outDir').installDir,\n allInstances.map((i) => i.dirname)\n )\n await this.writeGeneratedFilesToOutFolder([indexFile])\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqB;AACrB,mBAAkB;AAClB,SAAoB;AACpB,cAAyB;AACzB,cAAyB;AAEzB,aAAwB;AACxB,6BAAoC;AACpC,6BAA+B;AAOxB,MAAM,mBAAmB,sCAAqC;AAAA,EACnE,MAAa,MAAqB;AAChC,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,YAAM,IAAI,OAAO,yBAAyB;AAAA,IAC5C;AAEA,UAAM,iBAAiB,KAAK,KAAK;AAEjC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,4CAAoB,cAAc;AACpD,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,iCAAiC,cAAc;AAAA,IAClE;AAEA,UAAM,cAAc,MAAM,IAAI,gBAAgB,SAAS;AACvD,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,OAAO,iBAAiB,gBAAgB,2BAA2B;AAAA,IAC/E;AAEA,UAAM,eAAe,MAAM,KAAK,0BAA0B;AAC1D,UAAM,mBAAmB,aAAa,KAAK,CAAC,MAAM,EAAE,SAAS,YAAY,IAAI;AAC7E,QA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A,MAAc,sBAAsB,UAAiC;AACnE,UAAM,aAAa,KAAK,aAAa,IAAI;AACzC,UAAM,eAAe,QAAQ,KAAK,YAAY,SAAS,OAAO;AAC9D,UAAM,GAAG,SAAS,GAAG,cAAc,EAAE,WAAW,KAAK,CAAC;AACtD,UAAM,KAAK,kBAAkB;AAAA,EAC/B;AAAA,EAEA,MAAc,6BAA6B,aAAmC;AAC5E,UAAM,OAAO,KAAK,OAAO,KAAK;AAE9B,UAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,SAAK,QAAQ,cAAc,aAAAC,QAAM,KAAK,IAAI,MAAM,YAAY;AAE5D,UAAM,gBAAgB,MAAM,QAAQ;AAAA,MAClC;AAAA,MACA,KAAK,aAAa,IAAI,QAAQ,EAAE;AAAA,IAClC;AACA,UAAM,KAAK,+BAA+B,aAAa;AACvD,UAAM,KAAK,kBAAkB;AAE7B,UAAM,MAAM,KAAK,aAAa,IAAI,SAAS;AAC3C,SAAK,QAAQ,sCAAsC,aAAAA,QAAM,KAAK,IAAI,MAAM,GAAG;AAAA,EAC7E;AAAA,EAEA,MAAc,oBAAoB;AAChC,UAAM,eAAe,MAAM,KAAK,0BAA0B;AAC1D,UAAM,YAAY,MAAM,QAAQ;AAAA,MAC9B,KAAK,aAAa,IAAI,QAAQ,EAAE;AAAA,MAChC,aAAa,IAAI,CAAC,MAAM,EAAE,OAAO;AAAA,IACnC;AACA,UAAM,KAAK,+BAA+B,CAAC,SAAS,CAAC;AAAA,EACvD;AACF;",
|
|
6
|
+
"names": ["bluebird", "chalk"]
|
|
7
|
+
}
|
|
@@ -42,7 +42,13 @@ class BaseCommand {
|
|
|
42
42
|
await this.run();
|
|
43
43
|
} catch (thrown) {
|
|
44
44
|
const error = errors.BotpressCLIError.map(thrown);
|
|
45
|
-
|
|
45
|
+
if (error.debug) {
|
|
46
|
+
const msg = error.message + " (Run with verbose flag (-v) to see more details)";
|
|
47
|
+
this.logger.error(msg);
|
|
48
|
+
this.logger.debug(error.debug);
|
|
49
|
+
} else {
|
|
50
|
+
this.logger.error(error.message);
|
|
51
|
+
}
|
|
46
52
|
exitCode = 1;
|
|
47
53
|
} finally {
|
|
48
54
|
if (this.teardown) {
|
|
@@ -56,3 +62,4 @@ class BaseCommand {
|
|
|
56
62
|
0 && (module.exports = {
|
|
57
63
|
BaseCommand
|
|
58
64
|
});
|
|
65
|
+
//# sourceMappingURL=base-command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/base-command.ts"],
|
|
4
|
+
"sourcesContent": ["import * as errors from '../errors'\nimport type { Logger } from '../logger'\nimport type { CommandArgv, CommandDefinition } from '../typings'\n\nexport abstract class BaseCommand<C extends CommandDefinition> {\n public constructor(protected readonly logger: Logger, protected readonly argv: CommandArgv<C>) {}\n\n protected abstract run(): Promise<void>\n protected abstract bootstrap?: () => Promise<void>\n protected abstract teardown?: () => Promise<void>\n\n public async handler(): Promise<never> {\n let exitCode = 0\n try {\n if (this.bootstrap) {\n await this.bootstrap()\n }\n await this.run()\n } catch (thrown) {\n const error = errors.BotpressCLIError.map(thrown)\n\n if (error.debug) {\n const msg = error.message + ' (Run with verbose flag (-v) to see more details)'\n this.logger.error(msg)\n this.logger.debug(error.debug)\n } else {\n this.logger.error(error.message)\n }\n\n exitCode = 1\n } finally {\n if (this.teardown) {\n await this.teardown()\n }\n }\n\n process.exit(exitCode)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAIjB,MAAe,YAAyC;AAAA,EACtD,YAA+B,QAAmC,MAAsB;AAAzD;AAAmC;AAAA,EAAuB;AAAA,EAMhG,MAAa,UAA0B;AACrC,QAAI,WAAW;AACf,QAAI;AACF,UAAI,KAAK,WAAW;AAClB,cAAM,KAAK,UAAU;AAAA,MACvB;AACA,YAAM,KAAK,IAAI;AAAA,IACjB,SAAS,QAAP;AACA,YAAM,QAAQ,OAAO,iBAAiB,IAAI,MAAM;AAEhD,UAAI,MAAM,OAAO;AACf,cAAM,MAAM,MAAM,UAAU;AAC5B,aAAK,OAAO,MAAM,GAAG;AACrB,aAAK,OAAO,MAAM,MAAM,KAAK;AAAA,MAC/B,OAAO;AACL,aAAK,OAAO,MAAM,MAAM,OAAO;AAAA,MACjC;AAEA,iBAAW;AAAA,IACb,UAAE;AACA,UAAI,KAAK,UAAU;AACjB,cAAM,KAAK,SAAS;AAAA,MACtB;AAAA,IACF;AAEA,YAAQ,KAAK,QAAQ;AAAA,EACvB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/bot-commands.ts"],
|
|
4
|
+
"sourcesContent": ["import chalk from 'chalk'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { GlobalCommand } from './global-command'\n\nexport type GetBotCommandDefinition = typeof commandDefinitions.bots.subcommands.get\nexport class GetBotCommand extends GlobalCommand<GetBotCommandDefinition> {\n public async run(): Promise<void> {\n const { client } = await this.ensureLoginAndCreateClient(this.argv)\n\n try {\n const { bot } = await client.getBot({ id: this.argv.botRef })\n this.logger.success(`Bot ${chalk.bold(this.argv.botRef)}:`)\n this.logger.json(bot)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get bot ${this.argv.botRef}`)\n }\n }\n}\n\nexport type ListBotsCommandDefinition = typeof commandDefinitions.bots.subcommands.list\nexport class ListBotsCommand extends GlobalCommand<ListBotsCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n try {\n const bots = await api.listAllPages(api.client.listBots, (r) => r.bots)\n this.logger.success('Bots:')\n this.logger.json(bots)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list bots')\n }\n }\n}\n\nexport type DeleteBotCommandDefinition = typeof commandDefinitions.bots.subcommands.delete\nexport class DeleteBotCommand extends GlobalCommand<DeleteBotCommandDefinition> {\n public async run(): Promise<void> {\n const { client } = await this.ensureLoginAndCreateClient(this.argv)\n\n try {\n await client.deleteBot({ id: this.argv.botRef })\n this.logger.success(`Bot ${chalk.bold(this.argv.botRef)} deleted`)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not delete bot ${this.argv.botRef}`)\n }\n }\n}\n\nexport type CreateBotCommandDefinition = typeof commandDefinitions.bots.subcommands.create\nexport class CreateBotCommand extends GlobalCommand<CreateBotCommandDefinition> {\n public async run(): Promise<void> {\n const { client } = await this.ensureLoginAndCreateClient(this.argv)\n\n try {\n const { bot } = await client.createBot({ name: this.argv.name })\n this.logger.success(`Bot ${chalk.bold(bot.id)}:`)\n this.logger.json(bot)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,aAAwB;AACxB,4BAA8B;AAGvB,MAAM,sBAAsB,oCAAuC;AAAA,EACxE,MAAa,MAAqB;AAChC,UAAM,EAAE,OAAO,IAAI,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAElE,QAAI;AACF,YAAM,EAAE,IAAI,IAAI,MAAM,OAAO,OAAO,EAAE,IAAI,KAAK,KAAK,OAAO,CAAC;AAC5D,WAAK,OAAO,QAAQ,OAAO,aAAAA,QAAM,KAAK,KAAK,KAAK,MAAM,IAAI;AAC1D,WAAK,OAAO,KAAK,GAAG;AAAA,IACtB,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,qBAAqB,KAAK,KAAK,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;AAGO,MAAM,wBAAwB,oCAAyC;AAAA,EAC5E,MAAa,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-implementations/build-command.ts"],
|
|
4
|
+
"sourcesContent": ["import type commandDefinitions from '../command-definitions'\nimport { BundleCommand } from './bundle-command'\nimport { GenerateCommand } from './gen-command'\nimport { ProjectCommand } from './project-command'\n\nexport type BuildCommandDefinition = typeof commandDefinitions.build\nexport class BuildCommand extends ProjectCommand<BuildCommandDefinition> {\n public async run(): Promise<void> {\n const t0 = Date.now()\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n\n if (integrationDef) {\n await this._runGenerate()\n }\n\n await this._runBundle()\n const dt = Date.now() - t0\n this.logger.log(`Build completed in ${dt}ms`)\n }\n\n private _runGenerate() {\n return new GenerateCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private _runBundle() {\n return new BundleCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAA8B;AAC9B,yBAAgC;AAChC,6BAA+B;AAGxB,MAAM,qBAAqB,sCAAuC;AAAA,EACvE,MAAa,MAAqB;AAChC,UAAM,KAAK,KAAK,IAAI;AACpB,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAElE,QAAI,gBAAgB;AAClB,YAAM,KAAK,aAAa;AAAA,IAC1B;AAEA,UAAM,KAAK,WAAW;AACtB,UAAM,KAAK,KAAK,IAAI,IAAI;AACxB,SAAK,OAAO,IAAI,sBAAsB,MAAM;AAAA,EAC9C;AAAA,EAEQ,eAAe;AACrB,WAAO,IAAI,mCAAgB,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,IAAI,EAAE,IAAI;AAAA,EAChF;AAAA,EAEQ,aAAa;AACnB,WAAO,IAAI,oCAAc,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,IAAI,EAAE,IAAI;AAAA,EAC9E;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -48,7 +48,14 @@ class BundleCommand extends import_project_command.ProjectCommand {
|
|
|
48
48
|
const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`;
|
|
49
49
|
const outfile = abs.outFile;
|
|
50
50
|
line.debug(`Writing bundle to ${outfile}`);
|
|
51
|
-
await utils.esbuild.buildCode({
|
|
51
|
+
await utils.esbuild.buildCode({
|
|
52
|
+
code,
|
|
53
|
+
cwd: abs.workDir,
|
|
54
|
+
outfile,
|
|
55
|
+
logLevel,
|
|
56
|
+
write: true,
|
|
57
|
+
sourcemap: this.argv.sourceMap
|
|
58
|
+
});
|
|
52
59
|
line.success(`Bundle available at ${import_chalk.default.grey(rel.outDir)}`);
|
|
53
60
|
}
|
|
54
61
|
}
|
|
@@ -56,3 +63,4 @@ class BundleCommand extends import_project_command.ProjectCommand {
|
|
|
56
63
|
0 && (module.exports = {
|
|
57
64
|
BundleCommand
|
|
58
65
|
});
|
|
66
|
+
//# sourceMappingURL=bundle-command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/bundle-command.ts"],
|
|
4
|
+
"sourcesContent": ["import chalk from 'chalk'\nimport type commandDefinitions from '../command-definitions'\nimport * as utils from '../utils'\nimport { ProjectCommand } from './project-command'\n\nexport type BundleCommandDefinition = typeof commandDefinitions.bundle\nexport class BundleCommand extends ProjectCommand<BundleCommandDefinition> {\n public async run(): Promise<void> {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n\n const abs = this.projectPaths.abs\n const rel = this.projectPaths.rel('workDir')\n\n const line = this.logger.line()\n\n const logLevel = this.argv.verbose ? 'info' : 'silent'\n\n if (integrationDef) {\n const { name } = integrationDef\n line.started(`Bundling integration ${chalk.bold(name)}...`)\n } else {\n line.started('Bundling bot...')\n }\n\n const unixPath = utils.path.toUnix(rel.entryPoint)\n const importFrom = utils.path.rmExtension(unixPath)\n const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`\n\n const outfile = abs.outFile // TODO: ensure dir exists\n line.debug(`Writing bundle to ${outfile}`)\n\n await utils.esbuild.buildCode({\n code,\n cwd: abs.workDir,\n outfile,\n logLevel,\n write: true,\n sourcemap: this.argv.sourceMap,\n })\n\n line.success(`Bundle available at ${chalk.grey(rel.outDir)}`)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,YAAuB;AACvB,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAElE,UAAM,MAAM,KAAK,aAAa;AAC9B,UAAM,MAAM,KAAK,aAAa,IAAI,SAAS;AAE3C,UAAM,OAAO,KAAK,OAAO,KAAK;AAE9B,UAAM,WAAW,KAAK,KAAK,UAAU,SAAS;AAE9C,QAAI,gBAAgB;AAClB,YAAM,EAAE,KAAK,IAAI;AACjB,WAAK,QAAQ,wBAAwB,aAAAA,QAAM,KAAK,IAAI,MAAM;AAAA,IAC5D,OAAO;AACL,WAAK,QAAQ,iBAAiB;AAAA,IAChC;AAEA,UAAM,WAAW,MAAM,KAAK,OAAO,IAAI,UAAU;AACjD,UAAM,aAAa,MAAM,KAAK,YAAY,QAAQ;AAClD,UAAM,OAAO,oBAAoB;AAEjC,UAAM,UAAU,IAAI;AACpB,SAAK,MAAM,qBAAqB,SAAS;AAEzC,UAAM,MAAM,QAAQ,UAAU;AAAA,MAC5B;AAAA,MACA,KAAK,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,WAAW,KAAK,KAAK;AAAA,IACvB,CAAC;AAED,SAAK,QAAQ,uBAAuB,aAAAA,QAAM,KAAK,IAAI,MAAM,GAAG;AAAA,EAC9D;AACF;",
|
|
6
|
+
"names": ["chalk"]
|
|
7
|
+
}
|
|
@@ -59,7 +59,9 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
59
59
|
for (const [secretName, secretValue] of Object.entries(secrets)) {
|
|
60
60
|
code = code.replace(new RegExp(`process\\.env\\.${secretName}`, "g"), `"${secretValue}"`);
|
|
61
61
|
}
|
|
62
|
-
const { name, version } = integrationDef;
|
|
62
|
+
const { name, version, icon: iconRelativeFilePath, readme: readmeRelativeFilePath } = integrationDef;
|
|
63
|
+
const iconFileContent = await this._readMediaFile("icon", iconRelativeFilePath);
|
|
64
|
+
const readmeFileContent = await this._readMediaFile("readme", readmeRelativeFilePath);
|
|
63
65
|
const integration = await api.findIntegration({ type: "name", name, version });
|
|
64
66
|
let message;
|
|
65
67
|
if (integration) {
|
|
@@ -73,19 +75,34 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
73
75
|
this.logger.log("Aborted");
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
78
|
+
const publishBody = {
|
|
79
|
+
...integrationDef,
|
|
80
|
+
icon: iconFileContent,
|
|
81
|
+
readme: readmeFileContent,
|
|
82
|
+
code
|
|
83
|
+
};
|
|
76
84
|
const line = this.logger.line();
|
|
77
85
|
line.started(`Deploying integration ${import_chalk.default.bold(integrationDef.name)} v${integrationDef.version}...`);
|
|
78
86
|
if (integration) {
|
|
79
|
-
await api.client.updateIntegration({ id: integration.id, ...
|
|
87
|
+
await api.client.updateIntegration({ id: integration.id, ...publishBody }).catch((thrown) => {
|
|
80
88
|
throw errors.BotpressCLIError.wrap(thrown, `Could not update integration "${integrationDef.name}"`);
|
|
81
89
|
});
|
|
82
90
|
} else {
|
|
83
|
-
await api.client.createIntegration(
|
|
91
|
+
await api.client.createIntegration(publishBody).catch((thrown) => {
|
|
84
92
|
throw errors.BotpressCLIError.wrap(thrown, `Could not create integration "${integrationDef.name}"`);
|
|
85
93
|
});
|
|
86
94
|
}
|
|
87
95
|
line.success("Integration deployed");
|
|
88
96
|
}
|
|
97
|
+
_readMediaFile = async (filePurpose, filePath) => {
|
|
98
|
+
if (!filePath) {
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
101
|
+
const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath);
|
|
102
|
+
return fs.promises.readFile(absoluteFilePath, "base64").catch((thrown) => {
|
|
103
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file "${absoluteFilePath}"`);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
89
106
|
async _deployBot(api, argvBotId, argvCreateNew) {
|
|
90
107
|
const outfile = this.projectPaths.abs.outFile;
|
|
91
108
|
const code = await fs.promises.readFile(outfile, "utf-8");
|
|
@@ -164,3 +181,4 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
164
181
|
0 && (module.exports = {
|
|
165
182
|
DeployCommand
|
|
166
183
|
});
|
|
184
|
+
//# sourceMappingURL=deploy-command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/deploy-command.ts"],
|
|
4
|
+
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { Bot as BotImpl, IntegrationDefinition } from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport type { ApiClient } from 'src/api-client'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\nexport type DeployCommandDefinition = typeof commandDefinitions.deploy\nexport class DeployCommand extends ProjectCommand<DeployCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (api.host !== consts.defaultBotpressApi) {\n this.logger.log(`Using custom host ${api.host}`)\n }\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n return this._deployIntegration(api, integrationDef)\n }\n return this._deployBot(api, this.argv.botId, this.argv.createNewBot)\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployIntegration(api: ApiClient, integrationDef: IntegrationDefinition) {\n const outfile = this.projectPaths.abs.outFile\n let code = await fs.promises.readFile(outfile, 'utf-8')\n\n const secrets = await this.promptSecrets(integrationDef, this.argv)\n // TODO: provide these secrets to the backend by API and remove this string replacement hack\n for (const [secretName, secretValue] of Object.entries(secrets)) {\n code = code.replace(new RegExp(`process\\\\.env\\\\.${secretName}`, 'g'), `\"${secretValue}\"`)\n }\n\n const { name, version, icon: iconRelativeFilePath, readme: readmeRelativeFilePath } = integrationDef\n\n const iconFileContent = await this._readMediaFile('icon', iconRelativeFilePath)\n const readmeFileContent = await this._readMediaFile('readme', readmeRelativeFilePath)\n\n const integration = await api.findIntegration({ type: 'name', name, version })\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will overwrite the existing one.')\n message = `Are you sure you want to override integration ${integrationDef.name} v${integrationDef.version}?`\n } else {\n message = `Are you sure you want to deploy integration ${integrationDef.name} v${integrationDef.version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n const publishBody: Parameters<typeof api.client.createIntegration>[0] = {\n ...integrationDef,\n icon: iconFileContent,\n readme: readmeFileContent,\n code,\n }\n\n const line = this.logger.line()\n line.started(`Deploying integration ${chalk.bold(integrationDef.name)} v${integrationDef.version}...`)\n if (integration) {\n await api.client.updateIntegration({ id: integration.id, ...publishBody }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${integrationDef.name}\"`)\n })\n } else {\n await api.client.createIntegration(publishBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${integrationDef.name}\"`)\n })\n }\n line.success('Integration deployed')\n }\n\n private _readMediaFile = async (\n filePurpose: 'icon' | 'readme',\n filePath: string | undefined\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'base64').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file \"${absoluteFilePath}\"`)\n })\n }\n\n private async _deployBot(api: ApiClient, argvBotId: string | undefined, argvCreateNew: boolean | undefined) {\n const outfile = this.projectPaths.abs.outFile\n const code = await fs.promises.readFile(outfile, 'utf-8')\n const { default: botImpl } = utils.require.requireJsFile<{ default: BotImpl }>(outfile)\n\n const { tags, states, events, recurringEvents, configuration: botConfiguration } = botImpl\n\n let bot: bpclient.Bot\n if (argvBotId && argvCreateNew) {\n throw new errors.BotpressCLIError('Cannot specify both --botId and --createNew')\n } else if (argvCreateNew) {\n const confirm = await this.prompt.confirm('Are you sure you want to create a new bot ?')\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n bot = await this._createNewBot(api)\n } else {\n bot = await this._getExistingBot(api, argvBotId)\n\n const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot \"${bot.name}\"?`)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n }\n\n const integrations = this.prepareIntegrations(botImpl, bot)\n\n const line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n const { bot: updatedBot } = await api.client\n .updateBot({\n id: bot.id,\n code,\n states,\n recurringEvents,\n configuration: botConfiguration,\n events,\n tags,\n integrations,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update bot \"${bot.name}\"`)\n })\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _createNewBot(api: ApiClient): Promise<bpclient.Bot> {\n const line = this.logger.line()\n const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n })\n line.success(`Bot created with ID \"${createdBot.id}\" and name \"${createdBot.name}\"`)\n await this.projectCache.set('botId', createdBot.id)\n return createdBot\n }\n\n private async _getExistingBot(api: ApiClient, botId: string | undefined): Promise<bpclient.Bot> {\n const promptedBotId = await this.projectCache.sync('botId', botId, async (defaultId) => {\n const userBots = await api\n .listAllPages(api.client.listBots, (r) => r.bots)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch existing bots')\n })\n\n if (!userBots.length) {\n throw new errors.NoBotsFoundError()\n }\n\n const initial = userBots.find((bot) => bot.id === defaultId)\n\n const prompted = await this.prompt.select('Which bot do you want to deploy?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userBots.map((bot) => ({ title: bot.name, value: bot.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Bot Id')\n }\n\n return prompted\n })\n\n const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not get bot info')\n })\n\n return fetchedBot\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAClB,SAAoB;AAGpB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,QAAI,IAAI,SAAS,OAAO,oBAAoB;AAC1C,WAAK,OAAO,IAAI,qBAAqB,IAAI,MAAM;AAAA,IACjD;AAEA,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,aAAO,KAAK,mBAAmB,KAAK,cAAc;AAAA,IACpD;AACA,WAAO,KAAK,WAAW,KAAK,KAAK,KAAK,OAAO,KAAK,KAAK,YAAY;AAAA,EACrE;AAAA,EAEA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,EAAE,IAAI,EAC/C,MAAM,CAAC,WAAW;AACjB,cAAM,OAAO,iBAAiB,KAAK,QAAQ,+BAA+B;AAAA,MAC5E,CAAC;AAEH,UAAI,CAAC,SAAS,QAAQ;AACpB,cAAM,IAAI,OAAO,iBAAiB;AAAA,MACpC;AAEA,YAAM,UAAU,SAAS,KAAK,CAAC,QAAQ,IAAI,OAAO,SAAS;AAE3D,YAAM,WAAW,MAAM,KAAK,OAAO,OAAO,oCAAoC;AAAA,QAC5E,SAAS,WAAW,EAAE,OAAO,QAAQ,MAAM,OAAO,QAAQ,GAAG;AAAA,QAC7D,SAAS,SAAS,IAAI,CAAC,SAAS,EAAE,OAAO,IAAI,MAAM,OAAO,IAAI,GAAG,EAAE;AAAA,MACrE,CAAC;AAED,UAAI,CAAC,UAAU;AACb,cAAM,IAAI,OAAO,mBAAmB,QAAQ;AAAA,MAC9C;AAEA,aAAO;AAAA,IACT,CAAC;AAED,UAAM,EAAE,KAAK,WAAW,IAAI,MAAM,IAAI,OAAO,OAAO,EAAE,IAAI,cAAc,CAAC,EAAE,MAAM,CAAC,WAAW;AAC3F,YAAM,OAAO,iBAAiB,KAAK,QAAQ,wBAAwB;AAAA,IACrE,CAAC;AAED,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["chalk"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/dev-command.ts"],
|
|
4
|
+
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { Bot as BotImpl, IntegrationDefinition } from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as pathlib from 'path'\nimport type { ApiClient } from '../api-client'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n\n let env: Record<string, string> = {\n BP_API_URL: api.host,\n BP_TOKEN: api.token,\n }\n\n if (integrationDef) {\n await this._deployDevIntegration(api, this.argv.url, integrationDef)\n const secrets = await this.promptSecrets(integrationDef, this.argv)\n env = { ...env, ...secrets }\n } else {\n await this._deployDevBot(api, this.argv.url)\n }\n\n const outfile = this.projectPaths.abs.outFile\n const importPath = utils.path.toUnix(outfile)\n const requireFrom = utils.path.rmExtension(importPath)\n const code = `require('${requireFrom}').default.start(${this.argv.port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n try {\n const watcher = await utils.filewatcher.FileWatcher.watch(\n this.argv.workDir,\n async (events) => {\n const typescriptEvents = events.filter((e) => pathlib.extname(e.path) === '.ts')\n if (typescriptEvents.length === 0) {\n return\n }\n\n this.logger.log('Changes detected, reloading...')\n await this._runBuild()\n await worker.reload()\n },\n { ignore: [this.projectPaths.abs.outDir] }\n )\n\n await Promise.race([worker.wait(), watcher.wait()])\n await watcher.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev worker')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployDevIntegration(\n api: ApiClient,\n externalUrl: string,\n integrationDef: IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: bpclient.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n if (integration) {\n const resp = await api.client\n .updateIntegration({ ...integrationDef, id: integration.id, url: externalUrl })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n } else {\n const resp = await api.client\n .createIntegration({ ...integrationDef, dev: true, url: externalUrl })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n }\n\n line.success(`Dev Integration deployed with id \"${integration.id}\"`)\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: ApiClient, externalUrl: string): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: bpclient.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.success(`Dev Bot created with id \"${bot.id}\"`)\n await this.projectCache.set('devId', bot.id)\n }\n\n const outfile = this.projectPaths.abs.outFile\n const { default: botImpl } = utils.require.requireJsFile<{ default: BotImpl }>(outfile)\n\n const integrations = this.prepareIntegrations(botImpl, bot)\n\n const updateLine = this.logger.line()\n updateLine.started('Updating bot integrations...')\n\n const { bot: updatedBot } = await api.client\n .updateBot({ id: bot.id, integrations, url: externalUrl })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n updateLine.success('Integrations installed successfully')\n\n this.displayWebhookUrls(updatedBot)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAClB,cAAyB;AAGzB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAExB,MAAM,mBAAmB,sCAAqC;AAAA,EACnE,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAElE,QAAI,MAA8B;AAAA,MAChC,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB;AAEA,QAAI,gBAAgB;AAClB,YAAM,KAAK,sBAAsB,KAAK,KAAK,KAAK,KAAK,cAAc;AACnE,YAAM,UAAU,MAAM,KAAK,cAAc,gBAAgB,KAAK,IAAI;AAClE,YAAM,EAAE,GAAG,KAAK,GAAG,QAAQ;AAAA,IAC7B,OAAO;AACL,YAAM,KAAK,cAAc,KAAK,KAAK,KAAK,GAAG;AAAA,IAC7C;AAEA,UAAM,UAAU,KAAK,aAAa,IAAI;AACtC,UAAM,aAAa,MAAM,KAAK,OAAO,OAAO;AAC5C,UAAM,cAAc,MAAM,KAAK,YAAY,UAAU;AACrD,UAAM,OAAO,YAAY,+BAA+B,KAAK,KAAK;AAClE,UAAM,SAAS,MAAM,qBAAO;AAAA,MAC1B;AAAA,QACE,MAAM;A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U;AAAA,MAC1B,CAAC;AAED,UAAI,KAAK,KAAK,KAAK;AACjB,cAAM,KAAK;AAAA,MACb,OAAO;AACL,cAAM,KAAK,aAAa,GAAG,OAAO;AAAA,MACpC;AAAA,IACF;AAEA,QAAI,CAAC,KAAK;AACR,YAAM,aAAa,KAAK,OAAO,KAAK;AACpC,iBAAW,QAAQ,qBAAqB;AACxC,YAAM,OAAO,MAAM,IAAI,OACpB,UAAU;AAAA,QACT,KAAK;AAAA,QACL,KAAK;AAAA,MACP,CAAC,EACA,MAAM,CAAC,WAAW;AACjB,cAAM,OAAO,iBAAiB,KAAK,QAAQ,0BAA0B;AAAA,MACvE,CAAC;AAEH,YAAM,KAAK;AACX,iBAAW,QAAQ,4BAA4B,IAAI,KAAK;AACxD,YAAM,KAAK,aAAa,IAAI,SAAS,IAAI,EAAE;AAAA,IAC7C;AAEA,UAAM,UAAU,KAAK,aAAa,IAAI;AACtC,UAAM,EAAE,SAAS,QAAQ,IAAI,MAAM,QAAQ,cAAoC,OAAO;AAEtF,UAAM,eAAe,KAAK,oBAAoB,SAAS,GAAG;AAE1D,UAAM,aAAa,KAAK,OAAO,KAAK;AACpC,eAAW,QAAQ,8BAA8B;AAEjD,UAAM,EAAE,KAAK,WAAW,IAAI,MAAM,IAAI,OACnC,UAAU,EAAE,IAAI,IAAI,IAAI,cAAc,KAAK,YAAY,CAAC,EACxD,MAAM,CAAC,WAAW;AACjB,YAAM,OAAO,iBAAiB,KAAK,QAAQ,0BAA0B;AAAA,IACvE,CAAC;AACH,eAAW,QAAQ,qCAAqC;AAExD,SAAK,mBAAmB,UAAU;AAAA,EACpC;AACF;",
|
|
6
|
+
"names": ["chalk"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/gen-command.ts"],
|
|
4
|
+
"sourcesContent": ["import type { IntegrationDefinition } from '@botpress/sdk'\nimport chalk from 'chalk'\nimport _ from 'lodash'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { ProjectCommand } from './project-command'\n\nexport type GenerateCommandDefinition = typeof commandDefinitions.generate\nexport class GenerateCommand extends ProjectCommand<GenerateCommandDefinition> {\n public async run(): Promise<void> {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (!integrationDef) {\n this.logger.warn('No typings to generate for bot')\n return\n }\n\n this._validateSecrets(integrationDef)\n\n const line = this.logger.line()\n\n const { name } = integrationDef\n line.started(`Generating typings for integration ${chalk.bold(name)}...`)\n\n const fromWorkDir = this.projectPaths.rel('workDir')\n const fromOutDir = this.projectPaths.rel('outDir')\n\n const typingFiles = await codegen.generateIntegrationImplementationTypings(\n integrationDef,\n fromOutDir.implementationDir\n )\n\n const secretFiles = await codegen.generateIntegrationSecrets(integrationDef, fromOutDir.secretsDir)\n\n const indexFile = await codegen.generateIntegrationIndex(fromOutDir.implementationDir, fromOutDir.secretsDir)\n\n const generatedFiles = [...typingFiles, ...secretFiles, indexFile]\n\n await this.writeGeneratedFilesToOutFolder(generatedFiles)\n\n line.success(`Typings available at ${chalk.grey(fromWorkDir.outDir)}`)\n }\n\n private _validateSecrets(integrationDef: IntegrationDefinition): void {\n const { secrets } = integrationDef\n if (!secrets) {\n return\n }\n\n for (const secret of secrets) {\n if (!utils.casing.is.screamingSnakeCase(secret)) {\n throw new errors.BotpressCLIError(`Secret ${secret} should be in SCREAMING_SNAKE_CASE`)\n }\n }\n\n const groups = _(secrets)\n .groupBy()\n .mapValues((s) => s.length)\n .toPairs()\n .value()\n\n for (const [secret, count] of groups) {\n if (count > 1) {\n throw new errors.BotpressCLIError(`Secret ${secret} is dupplicated; It appears ${count} times`)\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAc;AACd,cAAyB;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pC,UAAI,QAAQ,GAAG;AACb,cAAM,IAAI,OAAO,iBAAiB,UAAU,qCAAqC,aAAa;AAAA,MAChG;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["chalk", "_"]
|
|
7
|
+
}
|
|
@@ -32,6 +32,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
32
32
|
var import_latest_version = __toESM(require("latest-version"));
|
|
33
33
|
var import_lodash = __toESM(require("lodash"));
|
|
34
34
|
var pathlib = __toESM(require("path"));
|
|
35
|
+
var import_semver = __toESM(require("semver"));
|
|
35
36
|
var consts = __toESM(require("../consts"));
|
|
36
37
|
var errors = __toESM(require("../errors"));
|
|
37
38
|
var utils = __toESM(require("../utils"));
|
|
@@ -93,7 +94,8 @@ class GlobalCommand extends import_base_command.BaseCommand {
|
|
|
93
94
|
_notifyUpdate = async (pkgJson) => {
|
|
94
95
|
try {
|
|
95
96
|
const latest = await (0, import_latest_version.default)(pkgJson.name);
|
|
96
|
-
|
|
97
|
+
const isOutdated = import_semver.default.lt(pkgJson.version, latest);
|
|
98
|
+
if (isOutdated) {
|
|
97
99
|
this.logger.box(UPDATE_MSG({ ...pkgJson, latest }));
|
|
98
100
|
}
|
|
99
101
|
} catch (thrown) {
|
|
@@ -112,3 +114,4 @@ class GlobalCommand extends import_base_command.BaseCommand {
|
|
|
112
114
|
0 && (module.exports = {
|
|
113
115
|
GlobalCommand
|
|
114
116
|
});
|
|
117
|
+
//# sourceMappingURL=global-command.js.map
|