@botpress/cli 0.11.6 → 1.0.0
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/.turbo/turbo-build.log +9 -9
- package/dist/api/bot-body.js.map +2 -2
- package/dist/api/client.js +14 -28
- package/dist/api/client.js.map +3 -3
- package/dist/api/find-previous-version.js.map +1 -1
- package/dist/api/index.js +23 -0
- package/dist/api/index.js.map +7 -0
- package/dist/api/interface-body.js +25 -10
- package/dist/api/interface-body.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-implementation.js +92 -0
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +7 -0
- package/dist/code-generation/{integration-schemas → bot-implementation/bot-typings}/events-module.js +15 -22
- package/dist/code-generation/bot-implementation/bot-typings/events-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-typings/index.js +96 -0
- package/dist/code-generation/bot-implementation/bot-typings/index.js.map +7 -0
- package/dist/code-generation/{integration-schemas → bot-implementation/bot-typings}/states-module.js +17 -22
- package/dist/code-generation/bot-implementation/bot-typings/states-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/index.js +56 -0
- package/dist/code-generation/bot-implementation/index.js.map +7 -0
- package/dist/code-generation/{const.js → consts.js} +9 -4
- package/dist/code-generation/consts.js.map +7 -0
- package/dist/code-generation/generators.js +37 -7
- package/dist/code-generation/generators.js.map +2 -2
- package/dist/code-generation/index.js +15 -105
- package/dist/code-generation/index.js.map +3 -3
- package/dist/code-generation/integration-implementation/index.js +66 -0
- package/dist/code-generation/integration-implementation/index.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-implementation.js +110 -0
- package/dist/code-generation/integration-implementation/integration-implementation.js.map +7 -0
- package/dist/code-generation/{integration-secret.js → integration-implementation/integration-secret.js} +17 -7
- package/dist/code-generation/integration-implementation/integration-secret.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/actions-module.js +28 -40
- package/dist/code-generation/integration-implementation/integration-typings/actions-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/channels-module.js +103 -0
- package/dist/code-generation/integration-implementation/integration-typings/channels-module.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/configuration-module.js +18 -20
- package/dist/code-generation/integration-implementation/integration-typings/configuration-module.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/configurations-module.js +21 -27
- package/dist/code-generation/integration-implementation/integration-typings/configurations-module.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/entities-module.js +15 -22
- package/dist/code-generation/integration-implementation/integration-typings/entities-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/events-module.js +59 -0
- package/dist/code-generation/integration-implementation/integration-typings/events-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/index.js +128 -0
- package/dist/code-generation/integration-implementation/integration-typings/index.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/states-module.js +60 -0
- package/dist/code-generation/integration-implementation/integration-typings/states-module.js.map +7 -0
- package/dist/code-generation/integration-package/index.js +81 -0
- package/dist/code-generation/integration-package/index.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js +84 -0
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js +103 -0
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js +58 -0
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js +66 -0
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js +59 -0
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js +62 -0
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/index.js +136 -0
- package/dist/code-generation/integration-package/integration-package-definition/index.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js +62 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/typings.js +17 -0
- package/dist/code-generation/integration-package/integration-package-definition/typings.js.map +7 -0
- package/dist/code-generation/interface-package/index.js +81 -0
- package/dist/code-generation/interface-package/index.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js +84 -0
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js +94 -0
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js +59 -0
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js +62 -0
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/index.js +100 -0
- package/dist/code-generation/interface-package/interface-package-definition/index.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/typings.js +17 -0
- package/dist/code-generation/interface-package/interface-package-definition/typings.js.map +7 -0
- package/dist/code-generation/module.js +60 -16
- package/dist/code-generation/module.js.map +2 -2
- package/dist/code-generation/strings.js +5 -2
- package/dist/code-generation/strings.js.map +2 -2
- package/dist/code-generation/typings.js.map +1 -1
- package/dist/command-implementations/add-command.js +102 -91
- package/dist/command-implementations/add-command.js.map +3 -3
- package/dist/command-implementations/bundle-command.js +16 -9
- package/dist/command-implementations/bundle-command.js.map +2 -2
- package/dist/command-implementations/deploy-command.js +27 -19
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/dev-command.js +15 -12
- package/dist/command-implementations/dev-command.js.map +2 -2
- package/dist/command-implementations/gen-command.js +31 -12
- package/dist/command-implementations/gen-command.js.map +3 -3
- package/dist/command-implementations/init-command.js +2 -2
- package/dist/command-implementations/init-command.js.map +2 -2
- package/dist/command-implementations/integration-commands.js +5 -5
- package/dist/command-implementations/integration-commands.js.map +2 -2
- package/dist/command-implementations/interface-commands.js +5 -5
- package/dist/command-implementations/interface-commands.js.map +2 -2
- package/dist/command-implementations/lint-command.js +3 -1
- package/dist/command-implementations/lint-command.js.map +3 -3
- package/dist/command-implementations/project-command.js +40 -23
- package/dist/command-implementations/project-command.js.map +3 -3
- package/dist/command-implementations/read-command.js +0 -5
- package/dist/command-implementations/read-command.js.map +2 -2
- package/dist/config.js +22 -7
- package/dist/config.js.map +2 -2
- package/dist/consts.js +15 -6
- package/dist/consts.js.map +2 -2
- package/dist/errors.js +19 -11
- package/dist/errors.js.map +2 -2
- package/dist/logger/index.js +4 -2
- package/dist/logger/index.js.map +2 -2
- package/dist/{integration-ref.js → package-ref.js} +11 -11
- package/dist/package-ref.js.map +7 -0
- package/dist/{integration-ref.test.js → package-ref.test.js} +18 -18
- package/dist/package-ref.test.js.map +7 -0
- package/dist/sdk/index.js +21 -0
- package/dist/sdk/index.js.map +7 -0
- package/dist/sdk/resolve-bot-interfaces.js +38 -0
- package/dist/sdk/resolve-bot-interfaces.js.map +7 -0
- package/dist/sdk/resolve-integration-interfaces.js +148 -0
- package/dist/sdk/resolve-integration-interfaces.js.map +7 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/path-utils.js +25 -8
- package/dist/utils/path-utils.js.map +3 -3
- package/dist/utils/path-utils.test.js +69 -0
- package/dist/utils/path-utils.test.js.map +7 -0
- package/dist/utils/record-utils.js +25 -0
- package/dist/utils/record-utils.js.map +3 -3
- package/dist/utils/schema-utils.js +11 -0
- package/dist/utils/schema-utils.js.map +2 -2
- package/dist/utils/schema-utils.test.js +51 -0
- package/dist/utils/schema-utils.test.js.map +7 -0
- package/dist/utils/template-utils.js +47 -0
- package/dist/utils/template-utils.js.map +7 -0
- package/dist/utils/type-utils.js.map +1 -1
- package/e2e/index.ts +2 -0
- package/e2e/tests/install-package.ts +163 -0
- package/e2e/utils.ts +25 -2
- package/package.json +5 -4
- package/templates/empty-bot/.botpress/implementation/index.ts +41 -0
- package/templates/empty-bot/.botpress/implementation/typings/index.ts +17 -0
- package/templates/empty-bot/.botpress/implementation/typings/integrations/index.ts +6 -0
- package/templates/empty-bot/.botpress/index.ts +1 -0
- package/templates/empty-bot/bot.definition.ts +2 -0
- package/templates/{echo-bot → empty-bot}/package.json +2 -2
- package/templates/empty-bot/src/index.ts +5 -0
- package/templates/empty-integration/.botpress/implementation/index.ts +7 -35
- package/templates/empty-integration/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/empty-integration/.botpress/implementation/typings/index.ts +31 -0
- package/templates/empty-integration/package.json +1 -1
- package/templates/hello-world/.botpress/implementation/index.ts +7 -35
- package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/input.ts +5 -0
- package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/output.ts +5 -0
- package/templates/hello-world/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/hello-world/.botpress/implementation/typings/index.ts +31 -0
- package/templates/hello-world/package.json +1 -1
- package/templates/webhook-message/.botpress/implementation/index.ts +7 -35
- package/templates/webhook-message/.botpress/implementation/typings/channels/webhook/messages/text.ts +5 -0
- package/templates/webhook-message/.botpress/implementation/typings/configuration/index.ts +8 -0
- package/templates/webhook-message/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/webhook-message/.botpress/implementation/typings/index.ts +31 -0
- package/templates/webhook-message/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/webhook-message/package.json +1 -1
- package/dist/code-generation/const.js.map +0 -7
- package/dist/code-generation/integration-implementation.js +0 -192
- package/dist/code-generation/integration-implementation.js.map +0 -7
- package/dist/code-generation/integration-instance.js +0 -185
- package/dist/code-generation/integration-instance.js.map +0 -7
- package/dist/code-generation/integration-schemas/actions-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/channels-module.js +0 -117
- package/dist/code-generation/integration-schemas/channels-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/configuration-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/configurations-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/entities-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/events-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/states-module.js.map +0 -7
- package/dist/code-generation/integration-secret.js.map +0 -7
- package/dist/code-generation/map-integration.js +0 -76
- package/dist/code-generation/map-integration.js.map +0 -7
- package/dist/integration-ref.js.map +0 -7
- package/dist/integration-ref.test.js.map +0 -7
- package/templates/echo-bot/src/index.ts +0 -30
- package/templates/empty-integration/.botpress/implementation/configuration/index.ts +0 -10
- package/templates/hello-world/.botpress/implementation/actions/helloWorld/input.ts +0 -10
- package/templates/hello-world/.botpress/implementation/actions/helloWorld/output.ts +0 -10
- package/templates/hello-world/.botpress/implementation/configuration/index.ts +0 -10
- package/templates/webhook-message/.botpress/implementation/channels/webhook/messages/text.ts +0 -10
- package/templates/webhook-message/.botpress/implementation/configuration/index.ts +0 -13
- /package/templates/{empty-integration/.botpress/implementation → empty-bot/.botpress/implementation/typings}/events/index.ts +0 -0
- /package/templates/{empty-integration/.botpress/implementation → empty-bot/.botpress/implementation/typings}/states/index.ts +0 -0
- /package/templates/{echo-bot → empty-bot}/tsconfig.json +0 -0
- /package/templates/empty-integration/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
- /package/templates/empty-integration/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
- /package/templates/empty-integration/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
- /package/templates/empty-integration/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
- /package/templates/{hello-world/.botpress/implementation → empty-integration/.botpress/implementation/typings}/events/index.ts +0 -0
- /package/templates/{hello-world/.botpress/implementation → empty-integration/.botpress/implementation/typings}/states/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{actions → typings/actions}/helloWorld/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
- /package/templates/{webhook-message/.botpress/implementation → hello-world/.botpress/implementation/typings}/events/index.ts +0 -0
- /package/templates/{webhook-message/.botpress/implementation → hello-world/.botpress/implementation/typings}/states/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/webhook/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/webhook/messages/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/module.ts"],
|
|
4
|
-
"sourcesContent": ["import { posix as pathlib } from 'path'\nimport * as utils from '../utils'\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AACjC,YAAuB;AACvB,
|
|
4
|
+
"sourcesContent": ["import { posix as pathlib } from 'path'\nimport * as utils from '../utils'\nimport * as consts from './consts'\nimport * as strings from './strings'\nimport { File } from './typings'\n\nexport type ModuleProps = {\n path: string\n exportName: string\n}\n\nexport abstract class Module {\n private _localDependencies: Module[] = []\n\n public get path(): string {\n return this._def.path\n }\n\n /**\n * @returns file name without extension\n */\n public get name(): string {\n const basename = pathlib.basename(this.path)\n if (basename === consts.INDEX_FILE) {\n const dirname = pathlib.basename(pathlib.dirname(this.path))\n return dirname\n }\n const withoutExtension = utils.path.rmExtension(basename)\n return withoutExtension\n }\n\n public get isDefaultExport(): boolean {\n return this._def.exportName === consts.DEFAULT_EXPORT_NAME\n }\n\n public get exportName(): string {\n return this._def.exportName\n }\n\n public get deps(): Module[] {\n return [...this._localDependencies]\n }\n\n protected constructor(private _def: ModuleProps) {}\n\n public abstract getContent(): Promise<string>\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 async toFile(): Promise<File> {\n return {\n path: this.path,\n content: await this.getContent(),\n }\n }\n\n public async flatten(): Promise<File[]> {\n const self = await this.toFile()\n const allFiles: File[] = [self]\n for (const dep of this._localDependencies) {\n const depFiles = await dep.flatten()\n allFiles.push(...depFiles)\n }\n return allFiles\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 class ReExportTypeModule extends Module {\n protected constructor(def: { exportName: string }) {\n super({\n ...def,\n path: consts.INDEX_FILE,\n })\n }\n\n public async getContent(): Promise<string> {\n let content = consts.GENERATED_HEADER\n\n for (const m of this.deps) {\n const { name } = m\n const importAlias = strings.importAlias(name)\n const importFrom = m.import(this)\n content += `import * as ${importAlias} from \"./${importFrom}\";\\n`\n content += `export * as ${importAlias} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n content += `export type ${this.exportName} = {\\n`\n for (const { name, exportName: exports } of this.deps) {\n const importAlias = strings.importAlias(name)\n content += ` \"${name}\": ${importAlias}.${exports};\\n`\n }\n content += '}'\n\n content += '\\n'\n\n return content\n }\n}\n\nexport class ReExportVariableModule extends Module {\n protected constructor(def: { exportName: string }) {\n super({\n ...def,\n path: consts.INDEX_FILE,\n })\n }\n\n public async getContent(): Promise<string> {\n let content = consts.GENERATED_HEADER\n\n for (const m of this.deps) {\n const { name } = m\n const importAlias = strings.importAlias(name)\n const importFrom = m.import(this)\n content += `import * as ${importAlias} from \"./${importFrom}\";\\n`\n content += `export * as ${importAlias} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n content += `export const ${this.exportName} = {\\n`\n for (const { name, exportName: exports } of this.deps) {\n const importAlias = strings.importAlias(name)\n content += ` \"${name}\": ${importAlias}.${exports},\\n`\n }\n content += '}'\n\n content += '\\n'\n\n return content\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AACjC,YAAuB;AACvB,aAAwB;AACxB,cAAyB;AAQlB,MAAe,OAAO;AAAA,EAgCjB,YAAoB,MAAmB;AAAnB;AAAA,EAAoB;AAAA,EA/B1C,qBAA+B,CAAC;AAAA,EAExC,IAAW,OAAe;AACxB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAKA,IAAW,OAAe;AACxB,UAAM,WAAW,YAAAA,MAAQ,SAAS,KAAK,IAAI;AAC3C,QAAI,aAAa,OAAO,YAAY;AAClC,YAAM,UAAU,YAAAA,MAAQ,SAAS,YAAAA,MAAQ,QAAQ,KAAK,IAAI,CAAC;AAC3D,aAAO;AAAA,IACT;AACA,UAAM,mBAAmB,MAAM,KAAK,YAAY,QAAQ;AACxD,WAAO;AAAA,EACT;AAAA,EAEA,IAAW,kBAA2B;AACpC,WAAO,KAAK,KAAK,eAAe,OAAO;AAAA,EACzC;AAAA,EAEA,IAAW,aAAqB;AAC9B,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAW,OAAiB;AAC1B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;AAC5C,YAAM,aAAa,EAAE,OAAO,IAAI;AAChC,iBAAW,eAAe,uBAAuB;AAAA;AACjD,iBAAW,eAAe,uBAAuB;AAAA;AAAA,IACnD;AAEA,eAAW;AAEX,eAAW,eAAe,KAAK;AAAA;AAC/B,eAAW,EAAE,MAAM,YAAY,QAAQ,KAAK,KAAK,MAAM;AACrD,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,iBAAW,MAAM,UAAU,eAAe;AAAA;AAAA,IAC5C;AACA,eAAW;AAEX,eAAW;AAEX,WAAO;AAAA,EACT;AACF;AAEO,MAAM,+BAA+B,OAAO;AAAA,EACvC,YAAY,KAA6B;AACjD,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,MAAM,OAAO;AAAA,IACf,CAAC;AAAA,EACH;AAAA,EAEA,MAAa,aAA8B;AACzC,QAAI,UAAU,OAAO;AAErB,eAAW,KAAK,KAAK,MAAM;AACzB,YAAM,EAAE,KAAK,IAAI;AACjB,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,YAAM,aAAa,EAAE,OAAO,IAAI;AAChC,iBAAW,eAAe,uBAAuB;AAAA;AACjD,iBAAW,eAAe,uBAAuB;AAAA;AAAA,IACnD;AAEA,eAAW;AAEX,eAAW,gBAAgB,KAAK;AAAA;AAChC,eAAW,EAAE,MAAM,YAAY,QAAQ,KAAK,KAAK,MAAM;AACrD,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,iBAAW,MAAM,UAAU,eAAe;AAAA;AAAA,IAC5C;AACA,eAAW;AAEX,eAAW;AAEX,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["pathlib"]
|
|
7
7
|
}
|
|
@@ -25,16 +25,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var strings_exports = {};
|
|
26
26
|
__export(strings_exports, {
|
|
27
27
|
importAlias: () => importAlias,
|
|
28
|
-
typeName: () => typeName
|
|
28
|
+
typeName: () => typeName,
|
|
29
|
+
varName: () => varName
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(strings_exports);
|
|
31
32
|
var utils = __toESM(require("../utils"));
|
|
32
33
|
const apply = (str, ...transforms) => transforms.reduce((acc, transform) => transform(acc), str);
|
|
33
34
|
const typeName = (name) => apply(name, utils.casing.to.pascalCase);
|
|
34
35
|
const importAlias = (name) => apply(name, utils.casing.to.camelCase);
|
|
36
|
+
const varName = (name) => apply(name, utils.casing.to.camelCase);
|
|
35
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
38
|
0 && (module.exports = {
|
|
37
39
|
importAlias,
|
|
38
|
-
typeName
|
|
40
|
+
typeName,
|
|
41
|
+
varName
|
|
39
42
|
});
|
|
40
43
|
//# sourceMappingURL=strings.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/strings.ts"],
|
|
4
|
-
"sourcesContent": ["import * as utils from '../utils'\ntype StrTransform = (str: string) => string\n\nconst apply = (str: string, ...transforms: StrTransform[]) => transforms.reduce((acc, transform) => transform(acc), str)\n\nexport const typeName = (name: string) => apply(name, utils.casing.to.pascalCase)\nexport const importAlias = (name: string) => apply(name, utils.casing.to.camelCase)\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAGvB,MAAM,QAAQ,CAAC,QAAgB,eAA+B,WAAW,OAAO,CAAC,KAAK,cAAc,UAAU,GAAG,GAAG,GAAG;AAEhH,MAAM,WAAW,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,UAAU;AACzE,MAAM,cAAc,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,SAAS;",
|
|
4
|
+
"sourcesContent": ["import * as utils from '../utils'\ntype StrTransform = (str: string) => string\n\nconst apply = (str: string, ...transforms: StrTransform[]) => transforms.reduce((acc, transform) => transform(acc), str)\n\nexport const typeName = (name: string) => apply(name, utils.casing.to.pascalCase)\nexport const importAlias = (name: string) => apply(name, utils.casing.to.camelCase)\nexport const varName = (name: string) => apply(name, utils.casing.to.camelCase)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAGvB,MAAM,QAAQ,CAAC,QAAgB,eAA+B,WAAW,OAAO,CAAC,KAAK,cAAc,UAAU,GAAG,GAAG,GAAG;AAEhH,MAAM,WAAW,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,UAAU;AACzE,MAAM,cAAc,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,SAAS;AAC3E,MAAM,UAAU,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,SAAS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/typings.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
4
|
+
"sourcesContent": ["import * as client from '@botpress/client'\nimport * as utils from '../utils'\n\nexport type File = { path: string; content: string }\n\nexport type IntegrationInstallablePackage =\n | {\n source: 'remote'\n integration: client.Integration\n }\n | {\n source: 'local'\n path: utils.path.AbsolutePath\n }\n\nexport type InterfaceInstallablePackage =\n | {\n source: 'remote'\n interface: client.Interface\n }\n | {\n source: 'local'\n path: utils.path.AbsolutePath\n }\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,122 +27,133 @@ __export(add_command_exports, {
|
|
|
27
27
|
AddCommand: () => AddCommand
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(add_command_exports);
|
|
30
|
-
var
|
|
31
|
-
var import_chalk = __toESM(require("chalk"));
|
|
32
|
-
var fs = __toESM(require("fs"));
|
|
30
|
+
var fslib = __toESM(require("fs"));
|
|
33
31
|
var pathlib = __toESM(require("path"));
|
|
32
|
+
var import_api = require("../api");
|
|
34
33
|
var codegen = __toESM(require("../code-generation"));
|
|
35
34
|
var consts = __toESM(require("../consts"));
|
|
36
35
|
var errors = __toESM(require("../errors"));
|
|
37
|
-
var
|
|
36
|
+
var pkgRef = __toESM(require("../package-ref"));
|
|
38
37
|
var utils = __toESM(require("../utils"));
|
|
38
|
+
var import_global_command = require("./global-command");
|
|
39
39
|
var import_project_command = require("./project-command");
|
|
40
|
-
class AddCommand extends
|
|
40
|
+
class AddCommand extends import_global_command.GlobalCommand {
|
|
41
41
|
async run() {
|
|
42
|
-
const
|
|
43
|
-
if (projectDef.type !== "bot") {
|
|
44
|
-
throw new errors.ExclusiveBotFeatureError();
|
|
45
|
-
}
|
|
46
|
-
const integrationRef = this.argv.integrationRef;
|
|
47
|
-
const parsedRef = (0, import_integration_ref.parseIntegrationRef)(integrationRef);
|
|
42
|
+
const parsedRef = pkgRef.parsePackageRef(this.argv.packageRef);
|
|
48
43
|
if (!parsedRef) {
|
|
49
|
-
throw new errors.
|
|
44
|
+
throw new errors.InvalidPackageReferenceError(this.argv.packageRef);
|
|
45
|
+
}
|
|
46
|
+
const targetPackage = parsedRef.type === "path" ? await this._findLocalPackage(parsedRef) : await this._findRemotePackage(parsedRef);
|
|
47
|
+
if (!targetPackage) {
|
|
48
|
+
const notFoundMessage = this.argv.packageType ? `Could not find package "${this.argv.packageRef}" of type "${this.argv.packageType}"` : `Could not find package "${this.argv.packageRef}"`;
|
|
49
|
+
throw new errors.BotpressCLIError(notFoundMessage);
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const packageName = targetPackage.name;
|
|
52
|
+
const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath);
|
|
53
|
+
const packageDirName = utils.casing.to.kebabCase(packageName);
|
|
54
|
+
const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName);
|
|
55
|
+
const alreadyInstalled = fslib.existsSync(installPath);
|
|
56
|
+
if (alreadyInstalled) {
|
|
57
|
+
this.logger.warn(`Package with name "${packageName}" already installed.`);
|
|
58
|
+
const res = await this.prompt.confirm("Do you want to overwrite the existing package?");
|
|
57
59
|
if (!res) {
|
|
58
60
|
this.logger.log("Aborted");
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
|
-
await this.
|
|
63
|
+
await this._uninstall(installPath);
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
const workDir = integrationOrInterfaceRef.path;
|
|
70
|
-
const pathStore = new utils.path.PathStore({
|
|
71
|
-
workDir,
|
|
72
|
-
integrationDefinition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.integrationDefinition),
|
|
73
|
-
interfaceDefinition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.interfaceDefinition)
|
|
74
|
-
});
|
|
75
|
-
const projectDef = await this.readProjectDefinitionFromFS(pathStore);
|
|
76
|
-
if (projectDef.type === "bot") {
|
|
77
|
-
throw new errors.BotpressCLIError(`Integration definition not found at ${workDir}`);
|
|
78
|
-
} else if (projectDef.type === "interface") {
|
|
79
|
-
throw new errors.BotpressCLIError("Installing interfaces is not supported yet");
|
|
65
|
+
let files;
|
|
66
|
+
if (targetPackage.type === "integration") {
|
|
67
|
+
files = await codegen.generateIntegrationPackage(targetPackage.pkg);
|
|
68
|
+
} else {
|
|
69
|
+
files = await codegen.generateInterfacePackage(targetPackage.pkg);
|
|
80
70
|
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
71
|
+
await this._install(installPath, files);
|
|
72
|
+
}
|
|
73
|
+
async _findRemotePackage(ref) {
|
|
84
74
|
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
if (this._pkgCouldBe("integration")) {
|
|
76
|
+
const integration = await api.findIntegration(ref);
|
|
77
|
+
if (integration) {
|
|
78
|
+
return { type: "integration", name: integration.name, pkg: { source: "remote", integration } };
|
|
79
|
+
}
|
|
88
80
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
if (this._pkgCouldBe("interface")) {
|
|
82
|
+
const intrface = await api.findPublicInterface(ref);
|
|
83
|
+
if (intrface) {
|
|
84
|
+
return { type: "interface", name: intrface.name, pkg: { source: "remote", interface: intrface } };
|
|
85
|
+
}
|
|
92
86
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
async _findLocalPackage(ref) {
|
|
90
|
+
const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path);
|
|
91
|
+
const projectDefinition = await this._readProject(absPath);
|
|
92
|
+
if (this._pkgCouldBe("integration") && projectDefinition?.type === "integration") {
|
|
93
|
+
return {
|
|
94
|
+
type: "integration",
|
|
95
|
+
name: projectDefinition.definition.name,
|
|
96
|
+
pkg: { source: "local", path: absPath }
|
|
97
|
+
};
|
|
101
98
|
}
|
|
102
|
-
|
|
103
|
-
const allPaths = allFiles.map((name) => pathlib.join(installPath, name));
|
|
104
|
-
const directories = await import_bluebird.default.filter(allPaths, async (path) => {
|
|
105
|
-
const stat = await fs.promises.stat(path);
|
|
106
|
-
return stat.isDirectory();
|
|
107
|
-
});
|
|
108
|
-
let jsons = directories.map((root) => ({ root, json: pathlib.join(root, codegen.INTEGRATION_JSON) }));
|
|
109
|
-
jsons = jsons.filter(({ json: x }) => fs.existsSync(x));
|
|
110
|
-
return import_bluebird.default.map(jsons, async ({ root, json }) => {
|
|
111
|
-
const content = await fs.promises.readFile(json, "utf-8");
|
|
112
|
-
const { name, version, id } = JSON.parse(content);
|
|
113
|
-
const dirname = pathlib.basename(root);
|
|
99
|
+
if (this._pkgCouldBe("interface") && projectDefinition?.type === "interface") {
|
|
114
100
|
return {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
version
|
|
101
|
+
type: "interface",
|
|
102
|
+
name: projectDefinition.definition.name,
|
|
103
|
+
pkg: { source: "local", path: absPath }
|
|
119
104
|
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
await fs.promises.rm(instancePath, { recursive: true });
|
|
126
|
-
await this._generateBotIndex();
|
|
105
|
+
}
|
|
106
|
+
if (projectDefinition?.type === "bot") {
|
|
107
|
+
throw new errors.BotpressCLIError("Cannot install a bot as a package");
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
127
110
|
}
|
|
128
|
-
async
|
|
111
|
+
async _install(installPath, files) {
|
|
129
112
|
const line = this.logger.line();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
113
|
+
line.started(`Installing ${files.length} files to "${installPath}"`);
|
|
114
|
+
try {
|
|
115
|
+
for (const file of files) {
|
|
116
|
+
const filePath = utils.path.absoluteFrom(installPath, file.path);
|
|
117
|
+
const dirPath = pathlib.dirname(filePath);
|
|
118
|
+
await fslib.promises.mkdir(dirPath, { recursive: true });
|
|
119
|
+
await fslib.promises.writeFile(filePath, file.content);
|
|
120
|
+
}
|
|
121
|
+
line.success(`Installed ${files.length} files to "${installPath}"`);
|
|
122
|
+
} finally {
|
|
123
|
+
line.commit();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async _uninstall(installPath) {
|
|
127
|
+
await fslib.promises.rm(installPath, { recursive: true });
|
|
140
128
|
}
|
|
141
|
-
async
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
129
|
+
async _readProject(workDir) {
|
|
130
|
+
class AnyProjectCommand extends import_project_command.ProjectCommand {
|
|
131
|
+
async run() {
|
|
132
|
+
throw new errors.BotpressCLIError("Not implemented");
|
|
133
|
+
}
|
|
134
|
+
async readProjectDefinitionFromFS() {
|
|
135
|
+
return super.readProjectDefinitionFromFS();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const cmd = new AnyProjectCommand(import_api.ApiClient, this.prompt, this.logger, {
|
|
139
|
+
...this.argv,
|
|
140
|
+
entryPoint: consts.defaultEntrypoint,
|
|
141
|
+
outDir: consts.defaultOutputFolder,
|
|
142
|
+
workDir
|
|
143
|
+
});
|
|
144
|
+
return cmd.readProjectDefinitionFromFS().catch((thrown) => {
|
|
145
|
+
if (thrown instanceof errors.ProjectDefinitionNotFoundError) {
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
throw thrown;
|
|
149
|
+
});
|
|
145
150
|
}
|
|
151
|
+
_pkgCouldBe = (pkgType) => {
|
|
152
|
+
if (!this.argv.packageType) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return this.argv.packageType === pkgType;
|
|
156
|
+
};
|
|
146
157
|
}
|
|
147
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
148
159
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/add-command.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import * as fslib from 'fs'\nimport * as pathlib from 'path'\nimport { ApiClient } from '../api'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as pkgRef from '../package-ref'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\nimport { ProjectCommand, ProjectCommandDefinition, ProjectDefinition } from './project-command'\n\ntype InstallablePackage =\n | {\n type: 'integration'\n name: string\n pkg: codegen.IntegrationInstallablePackage\n }\n | {\n type: 'interface'\n name: string\n pkg: codegen.InterfaceInstallablePackage\n }\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends GlobalCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const parsedRef = pkgRef.parsePackageRef(this.argv.packageRef)\n if (!parsedRef) {\n throw new errors.InvalidPackageReferenceError(this.argv.packageRef)\n }\n\n const targetPackage =\n parsedRef.type === 'path' ? await this._findLocalPackage(parsedRef) : await this._findRemotePackage(parsedRef)\n\n if (!targetPackage) {\n const notFoundMessage = this.argv.packageType\n ? `Could not find package \"${this.argv.packageRef}\" of type \"${this.argv.packageType}\"`\n : `Could not find package \"${this.argv.packageRef}\"`\n throw new errors.BotpressCLIError(notFoundMessage)\n }\n\n const packageName = targetPackage.name // TODO: eventually replace name by alias (with argv --alias)\n const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath)\n const packageDirName = utils.casing.to.kebabCase(packageName)\n const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName)\n\n const alreadyInstalled = fslib.existsSync(installPath)\n if (alreadyInstalled) {\n this.logger.warn(`Package with name \"${packageName}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing package?')\n if (!res) {\n this.logger.log('Aborted')\n return\n }\n\n await this._uninstall(installPath)\n }\n\n let files: codegen.File[]\n if (targetPackage.type === 'integration') {\n files = await codegen.generateIntegrationPackage(targetPackage.pkg)\n } else {\n files = await codegen.generateInterfacePackage(targetPackage.pkg)\n }\n\n await this._install(installPath, files)\n }\n\n private async _findRemotePackage(ref: pkgRef.ApiPackageRef): Promise<InstallablePackage | undefined> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (this._pkgCouldBe('integration')) {\n const integration = await api.findIntegration(ref)\n if (integration) {\n return { type: 'integration', name: integration.name, pkg: { source: 'remote', integration } }\n }\n }\n if (this._pkgCouldBe('interface')) {\n const intrface = await api.findPublicInterface(ref)\n if (intrface) {\n return { type: 'interface', name: intrface.name, pkg: { source: 'remote', interface: intrface } }\n }\n }\n return\n }\n\n private async _findLocalPackage(ref: pkgRef.LocalPackageRef): Promise<InstallablePackage | undefined> {\n const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path)\n const projectDefinition = await this._readProject(absPath)\n if (this._pkgCouldBe('integration') && projectDefinition?.type === 'integration') {\n return {\n type: 'integration',\n name: projectDefinition.definition.name,\n pkg: { source: 'local', path: absPath },\n }\n }\n if (this._pkgCouldBe('interface') && projectDefinition?.type === 'interface') {\n return {\n type: 'interface',\n name: projectDefinition.definition.name,\n pkg: { source: 'local', path: absPath },\n }\n }\n if (projectDefinition?.type === 'bot') {\n throw new errors.BotpressCLIError('Cannot install a bot as a package')\n }\n return\n }\n\n private async _install(installPath: utils.path.AbsolutePath, files: codegen.File[]): Promise<void> {\n const line = this.logger.line()\n line.started(`Installing ${files.length} files to \"${installPath}\"`)\n try {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(installPath, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fslib.promises.mkdir(dirPath, { recursive: true })\n await fslib.promises.writeFile(filePath, file.content)\n }\n line.success(`Installed ${files.length} files to \"${installPath}\"`)\n } finally {\n line.commit()\n }\n }\n\n private async _uninstall(installPath: utils.path.AbsolutePath): Promise<void> {\n await fslib.promises.rm(installPath, { recursive: true })\n }\n\n private async _readProject(workDir: utils.path.AbsolutePath): Promise<ProjectDefinition | undefined> {\n // this is a hack to avoid refactoring the project command class\n class AnyProjectCommand extends ProjectCommand<ProjectCommandDefinition> {\n public async run(): Promise<void> {\n throw new errors.BotpressCLIError('Not implemented')\n }\n\n public async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n return super.readProjectDefinitionFromFS()\n }\n }\n\n const cmd = new AnyProjectCommand(ApiClient, this.prompt, this.logger, {\n ...this.argv,\n entryPoint: consts.defaultEntrypoint,\n outDir: consts.defaultOutputFolder,\n workDir,\n })\n\n return cmd.readProjectDefinitionFromFS().catch((thrown) => {\n if (thrown instanceof errors.ProjectDefinitionNotFoundError) {\n return undefined\n }\n throw thrown\n })\n }\n\n private _pkgCouldBe = (pkgType: InstallablePackage['type']) => {\n if (!this.argv.packageType) {\n return true\n }\n return this.argv.packageType === pkgType\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AACvB,cAAyB;AACzB,iBAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;AAC9B,6BAA4E;AAerE,MAAM,mBAAmB,oCAAoC;AAAA,EAClE,MAAa,MAAqB;AAChC,UAAM,YAAY,OAAO,gBAAgB,KAAK,KAAK,UAAU;AAC7D,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,6BAA6B,KAAK,KAAK,UAAU;AAAA,IACpE;AAEA,UAAM,gBACJ,UAAU,SAAS,SAAS,MAAM,KAAK,kBAAkB,SAAS,IAAI,MAAM,KAAK,mBAAmB,SAAS;AAE/G,QAAI,CAAC,eAAe;AAClB,YAAM,kBAAkB,KAAK,KAAK,cAC9B,2BAA2B,KAAK,KAAK,wBAAwB,KAAK,KAAK,iBACvE,2BAA2B,KAAK,KAAK;AACzC,YAAM,IAAI,OAAO,iBAAiB,eAAe;AAAA,IACnD;AAEA,UAAM,cAAc,cAAc;AAClC,UAAM,kBAAkB,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,KAAK,WAAW;AACvF,UAAM,iBAAiB,MAAM,OAAO,GAAG,UAAU,WAAW;AAC5D,UAAM,cAAc,MAAM,KAAK,KAAK,iBAAiB,OAAO,gBAAgB,cAAc;AAE1F,UA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AQ,KAAK,QAAQ;AAAA,MACrE,GAAG,KAAK;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,OAAO;AAAA,MACf;AAAA,IACF,CAAC;AAED,WAAO,IAAI,4BAA4B,EAAE,MAAM,CAAC,WAAW;AACzD,UAAI,kBAAkB,OAAO,gCAAgC;AAC3D,eAAO;AAAA,MACT;AACA,YAAM;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,CAAC,YAAwC;AAC7D,QAAI,CAAC,KAAK,KAAK,aAAa;AAC1B,aAAO;AAAA,IACT;AACA,WAAO,KAAK,KAAK,gBAAgB;AAAA,EACnC;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -28,25 +28,32 @@ __export(bundle_command_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(bundle_command_exports);
|
|
30
30
|
var import_chalk = __toESM(require("chalk"));
|
|
31
|
+
var errors = __toESM(require("../errors"));
|
|
31
32
|
var utils = __toESM(require("../utils"));
|
|
32
33
|
var import_project_command = require("./project-command");
|
|
33
34
|
class BundleCommand extends import_project_command.ProjectCommand {
|
|
34
35
|
async run() {
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
this.logger.success("Interface projects have
|
|
36
|
+
const projectDef = await this.readProjectDefinitionFromFS();
|
|
37
|
+
if (projectDef.type === "interface") {
|
|
38
|
+
this.logger.success("Interface projects have no implementation to bundle.");
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
|
-
const abs = this.projectPaths.abs;
|
|
41
|
-
const rel = this.projectPaths.rel("workDir");
|
|
42
41
|
const line = this.logger.line();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const { name } = integrationDef;
|
|
42
|
+
if (projectDef.type === "integration") {
|
|
43
|
+
const { name } = projectDef.definition;
|
|
46
44
|
line.started(`Bundling integration ${import_chalk.default.bold(name)}...`);
|
|
47
|
-
|
|
45
|
+
return await this._bundle(line);
|
|
46
|
+
}
|
|
47
|
+
if (projectDef.type === "bot") {
|
|
48
48
|
line.started("Bundling bot...");
|
|
49
|
+
return await this._bundle(line);
|
|
49
50
|
}
|
|
51
|
+
throw new errors.UnsupportedProjectType();
|
|
52
|
+
}
|
|
53
|
+
async _bundle(line) {
|
|
54
|
+
const logLevel = this.argv.verbose ? "info" : "silent";
|
|
55
|
+
const abs = this.projectPaths.abs;
|
|
56
|
+
const rel = this.projectPaths.rel("workDir");
|
|
50
57
|
const unixPath = utils.path.toUnix(rel.entryPoint);
|
|
51
58
|
const importFrom = utils.path.rmExtension(unixPath);
|
|
52
59
|
const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;
|
|
4
|
+
"sourcesContent": ["import chalk from 'chalk'\nimport { SingleLineLogger } from 'src/logger'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\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 projectDef = await this.readProjectDefinitionFromFS()\n\n if (projectDef.type === 'interface') {\n this.logger.success('Interface projects have no implementation to bundle.')\n return\n }\n\n const line = this.logger.line()\n\n if (projectDef.type === 'integration') {\n const { name } = projectDef.definition\n line.started(`Bundling integration ${chalk.bold(name)}...`)\n return await this._bundle(line)\n }\n\n if (projectDef.type === 'bot') {\n line.started('Bundling bot...')\n return await this._bundle(line)\n }\n\n throw new errors.UnsupportedProjectType()\n }\n\n private async _bundle(line: SingleLineLogger) {\n const logLevel = this.argv.verbose ? 'info' : 'silent'\n const abs = this.projectPaths.abs\n const rel = this.projectPaths.rel('workDir')\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 minify: this.argv.minify,\n })\n\n line.success(`Bundle available at ${chalk.grey(rel.outDir)}`)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGlB,aAAwB;AACxB,YAAuB;AACvB,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAE1D,QAAI,WAAW,SAAS,aAAa;AACnC,WAAK,OAAO,QAAQ,sDAAsD;AAC1E;AAAA,IACF;AAEA,UAAM,OAAO,KAAK,OAAO,KAAK;AAE9B,QAAI,WAAW,SAAS,eAAe;AACrC,YAAM,EAAE,KAAK,IAAI,WAAW;AAC5B,WAAK,QAAQ,wBAAwB,aAAAA,QAAM,KAAK,IAAI,MAAM;AAC1D,aAAO,MAAM,KAAK,QAAQ,IAAI;AAAA,IAChC;AAEA,QAAI,WAAW,SAAS,OAAO;AAC7B,WAAK,QAAQ,iBAAiB;AAC9B,aAAO,MAAM,KAAK,QAAQ,IAAI;AAAA,IAChC;AAEA,UAAM,IAAI,OAAO,uBAAuB;AAAA,EAC1C;AAAA,EAEA,MAAc,QAAQ,MAAwB;AAC5C,UAAM,WAAW,KAAK,KAAK,UAAU,SAAS;AAC9C,UAAM,MAAM,KAAK,aAAa;AAC9B,UAAM,MAAM,KAAK,aAAa,IAAI,SAAS;AAE3C,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,MACrB,QAAQ,KAAK,KAAK;AAAA,IACpB,CAAC;AAED,SAAK,QAAQ,uBAAuB,aAAAA,QAAM,KAAK,IAAI,MAAM,GAAG;AAAA,EAC9D;AACF;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
|
@@ -27,6 +27,7 @@ __export(deploy_command_exports, {
|
|
|
27
27
|
DeployCommand: () => DeployCommand
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(deploy_command_exports);
|
|
30
|
+
var sdk = __toESM(require("@botpress/sdk"));
|
|
30
31
|
var import_chalk = __toESM(require("chalk"));
|
|
31
32
|
var fs = __toESM(require("fs"));
|
|
32
33
|
var import_semver = __toESM(require("semver"));
|
|
@@ -34,6 +35,7 @@ var import_bot_body = require("../api/bot-body");
|
|
|
34
35
|
var import_integration_body = require("../api/integration-body");
|
|
35
36
|
var import_interface_body = require("../api/interface-body");
|
|
36
37
|
var errors = __toESM(require("../errors"));
|
|
38
|
+
var import_sdk = require("../sdk");
|
|
37
39
|
var utils = __toESM(require("../utils"));
|
|
38
40
|
var import_build_command = require("./build-command");
|
|
39
41
|
var import_project_command = require("./project-command");
|
|
@@ -50,7 +52,10 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
50
52
|
if (projectDef.type === "interface") {
|
|
51
53
|
return this._deployInterface(api, projectDef.definition);
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
if (projectDef.type === "bot") {
|
|
56
|
+
return this._deployBot(api, projectDef.definition, this.argv.botId, this.argv.createNewBot);
|
|
57
|
+
}
|
|
58
|
+
throw new errors.UnsupportedProjectType();
|
|
54
59
|
}
|
|
55
60
|
async _runBuild() {
|
|
56
61
|
return new import_build_command.BuildCommand(this.api, this.prompt, this.logger, this.argv).run();
|
|
@@ -239,10 +244,9 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
239
244
|
throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file "${absoluteFilePath}"`);
|
|
240
245
|
});
|
|
241
246
|
};
|
|
242
|
-
async _deployBot(api, argvBotId, argvCreateNew) {
|
|
247
|
+
async _deployBot(api, botDefinition, argvBotId, argvCreateNew) {
|
|
243
248
|
const outfile = this.projectPaths.abs.outFile;
|
|
244
249
|
const code = await fs.promises.readFile(outfile, "utf-8");
|
|
245
|
-
const { default: botImpl } = utils.require.requireJsFile(outfile);
|
|
246
250
|
let bot;
|
|
247
251
|
if (argvBotId && argvCreateNew) {
|
|
248
252
|
throw new errors.BotpressCLIError("Cannot specify both --botId and --createNew");
|
|
@@ -263,10 +267,11 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
263
267
|
}
|
|
264
268
|
const line = this.logger.line();
|
|
265
269
|
line.started(`Deploying bot ${import_chalk.default.bold(bot.name)}...`);
|
|
266
|
-
const integrationInstances = await this.fetchBotIntegrationInstances(
|
|
270
|
+
const integrationInstances = await this.fetchBotIntegrationInstances(botDefinition, api);
|
|
271
|
+
const createBotBody = await (0, import_bot_body.prepareCreateBotBody)(botDefinition);
|
|
267
272
|
const updateBotBody = (0, import_bot_body.prepareUpdateBotBody)(
|
|
268
273
|
{
|
|
269
|
-
...
|
|
274
|
+
...createBotBody,
|
|
270
275
|
id: bot.id,
|
|
271
276
|
code,
|
|
272
277
|
integrations: integrationInstances
|
|
@@ -337,7 +342,7 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
337
342
|
throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg);
|
|
338
343
|
}
|
|
339
344
|
const newName2 = `${remoteHandle}/${localName}`;
|
|
340
|
-
return
|
|
345
|
+
return new sdk.IntegrationDefinition({ ...integration, name: newName2 });
|
|
341
346
|
}
|
|
342
347
|
if (localHandle && !remoteHandle) {
|
|
343
348
|
const { available } = await api.client.checkHandleAvailability({ handle: localHandle }).catch((thrown) => {
|
|
@@ -377,7 +382,7 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
377
382
|
} while (!claimedHandle);
|
|
378
383
|
this.logger.success(`Handle "${claimedHandle}" is yours!`);
|
|
379
384
|
const newName = `${claimedHandle}/${localName}`;
|
|
380
|
-
return
|
|
385
|
+
return new sdk.IntegrationDefinition({ ...integration, name: newName });
|
|
381
386
|
}
|
|
382
387
|
_parseIntegrationName = (integrationName) => {
|
|
383
388
|
const parts = integrationName.split("/");
|
|
@@ -394,22 +399,25 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
394
399
|
return { name };
|
|
395
400
|
};
|
|
396
401
|
_formatInterfacesImplStatements = async (api, integration) => {
|
|
397
|
-
const
|
|
398
|
-
if (!interfacesEntries.length) {
|
|
399
|
-
return void 0;
|
|
400
|
-
}
|
|
402
|
+
const interfacesStatements = (0, import_sdk.getImplementationStatements)(integration);
|
|
401
403
|
const interfaces = {};
|
|
402
|
-
for (const [key, i] of
|
|
403
|
-
const { name, version, entities, actions, events } = i;
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
throw new errors.BotpressCLIError(`Could not find interface "${name}@${version}"`);
|
|
407
|
-
}
|
|
408
|
-
const { id } = intrface;
|
|
409
|
-
interfaces[key] = { id, entities, actions, events };
|
|
404
|
+
for (const [key, i] of Object.entries(interfacesStatements)) {
|
|
405
|
+
const { name, version, entities, actions, events, channels } = i;
|
|
406
|
+
const id = await this._getInterfaceId(api, { id: i.id, name, version });
|
|
407
|
+
interfaces[key] = { id, entities, actions, events, channels };
|
|
410
408
|
}
|
|
411
409
|
return interfaces;
|
|
412
410
|
};
|
|
411
|
+
_getInterfaceId = async (api, ref) => {
|
|
412
|
+
if (ref.id) {
|
|
413
|
+
return ref.id;
|
|
414
|
+
}
|
|
415
|
+
const intrface = await api.findPublicInterface({ type: "name", name: ref.name, version: ref.version });
|
|
416
|
+
if (!intrface) {
|
|
417
|
+
throw new errors.BotpressCLIError(`Could not find interface "${ref.name}@${ref.version}"`);
|
|
418
|
+
}
|
|
419
|
+
return intrface.id;
|
|
420
|
+
};
|
|
413
421
|
}
|
|
414
422
|
// Annotate the CommonJS export names for ESM import in node:
|
|
415
423
|
0 && (module.exports = {
|