@botpress/cli 0.0.9 → 0.0.10
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 +107 -0
- package/dist/app/api-utils.js +9 -3
- package/dist/app/base.js +1 -3
- package/dist/app/errors.js +8 -0
- package/dist/app/file-paths.js +4 -2
- package/dist/app/index.js +17 -12
- package/dist/app/user.js +73 -23
- package/dist/code-generation/action.js +70 -0
- package/dist/code-generation/channel.js +51 -0
- package/dist/code-generation/configuration.js +40 -0
- package/dist/code-generation/const.js +31 -0
- package/dist/code-generation/event.js +41 -0
- package/dist/code-generation/index.js +80 -0
- package/dist/code-generation/integration-impl.js +147 -0
- package/dist/code-generation/integration-instance.js +79 -0
- package/dist/code-generation/message.js +41 -0
- package/dist/code-generation/module.js +115 -0
- package/dist/code-generation/typings.js +16 -0
- package/dist/command-definitions.js +61 -0
- package/dist/command-implementations/add-command.js +124 -0
- package/dist/command-implementations/base-command.js +53 -0
- package/dist/command-implementations/bot-commands.js +89 -0
- package/dist/command-implementations/build-command.js +48 -0
- package/dist/command-implementations/bundle-command.js +58 -0
- package/dist/command-implementations/deploy-command.js +162 -0
- package/dist/command-implementations/dev-command.js +168 -0
- package/dist/command-implementations/gen-command.js +58 -0
- package/dist/command-implementations/global-command.js +111 -0
- package/dist/command-implementations/index.js +78 -0
- package/dist/command-implementations/init-command.js +85 -0
- package/dist/command-implementations/integration-commands.js +107 -0
- package/dist/command-implementations/login-command.js +75 -0
- package/dist/command-implementations/logout-command.js +34 -0
- package/dist/command-implementations/project-command.js +115 -0
- package/dist/command-implementations/serve-command.js +53 -0
- package/dist/command-tree.js +59 -0
- package/dist/config.js +18 -2
- package/dist/consts.js +13 -0
- package/dist/errors.js +156 -0
- package/dist/index.js +33 -20
- package/dist/integration-ref.js +61 -0
- package/dist/path-utils.js +6 -0
- package/dist/register-yargs.js +85 -0
- package/dist/typings.js +16 -0
- package/dist/utils/cache-utils.js +99 -0
- package/dist/utils/esbuild-utils.js +89 -0
- package/dist/utils/event-emitter.js +62 -0
- package/dist/utils/file-watcher.js +68 -0
- package/dist/utils/index.js +55 -0
- package/dist/utils/path-utils.js +83 -0
- package/dist/utils/prompt-utils.js +75 -0
- package/dist/utils/require-utils.js +49 -0
- package/dist/utils/string-utils.js +38 -0
- package/package.json +6 -4
- package/templates/echo-bot/.botpress/project.cache.json +1 -0
- package/templates/echo-bot/package.json +22 -0
- package/templates/echo-bot/readme.md +5 -0
- package/templates/echo-bot/src/index.ts +44 -0
- package/templates/echo-bot/tsconfig.json +15 -0
- package/templates/empty-integration/.botpress/implementation/actions/index.ts +7 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/audio.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/card.ts +17 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/carousel.ts +19 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/choice.ts +14 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/dropdown.ts +14 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/file.ts +11 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/image.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/index.ts +40 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/location.ts +11 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/markdown.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/text.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/video.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/index.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/configuration.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/events/index.ts +7 -0
- package/templates/empty-integration/.botpress/implementation/index.ts +17 -0
- package/templates/empty-integration/.botpress/index.ts +1 -0
- package/templates/empty-integration/.botpress/project.cache.json +1 -0
- package/templates/empty-integration/integration.definition.ts +13 -0
- package/templates/empty-integration/package.json +22 -0
- package/templates/empty-integration/readme.md +5 -0
- package/templates/empty-integration/src/index.ts +58 -0
- package/templates/empty-integration/tsconfig.json +15 -0
- package/.ignore.me.github/index.ts +0 -38
- package/dist/github-download.js +0 -159
- package/dist/github-fetch.js +0 -173
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var base_command_exports = {};
|
|
26
|
+
__export(base_command_exports, {
|
|
27
|
+
BaseCommand: () => BaseCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(base_command_exports);
|
|
30
|
+
var errors = __toESM(require("../errors"));
|
|
31
|
+
class BaseCommand {
|
|
32
|
+
constructor(logger, argv) {
|
|
33
|
+
this.logger = logger;
|
|
34
|
+
this.argv = argv;
|
|
35
|
+
}
|
|
36
|
+
async handler() {
|
|
37
|
+
try {
|
|
38
|
+
if (this.bootstrap) {
|
|
39
|
+
await this.bootstrap();
|
|
40
|
+
}
|
|
41
|
+
await this.run();
|
|
42
|
+
} catch (thrown) {
|
|
43
|
+
const error = errors.BotpressCLIError.map(thrown);
|
|
44
|
+
this.logger.error(error.message);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
BaseCommand
|
|
53
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var bot_commands_exports = {};
|
|
26
|
+
__export(bot_commands_exports, {
|
|
27
|
+
CreateBotCommand: () => CreateBotCommand,
|
|
28
|
+
DeleteBotCommand: () => DeleteBotCommand,
|
|
29
|
+
GetBotCommand: () => GetBotCommand,
|
|
30
|
+
ListBotsCommand: () => ListBotsCommand
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(bot_commands_exports);
|
|
33
|
+
var import_chalk = __toESM(require("chalk"));
|
|
34
|
+
var errors = __toESM(require("../errors"));
|
|
35
|
+
var import_global_command = require("./global-command");
|
|
36
|
+
class GetBotCommand extends import_global_command.GlobalCommand {
|
|
37
|
+
async run() {
|
|
38
|
+
const { client } = await this.ensureLoginAndCreateClient(this.argv);
|
|
39
|
+
try {
|
|
40
|
+
const { bot } = await client.getBot({ id: this.argv.botRef });
|
|
41
|
+
this.logger.success(`Bot ${import_chalk.default.bold(this.argv.botRef)}:`);
|
|
42
|
+
this.logger.json(bot);
|
|
43
|
+
} catch (thrown) {
|
|
44
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not get bot ${this.argv.botRef}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class ListBotsCommand extends import_global_command.GlobalCommand {
|
|
49
|
+
async run() {
|
|
50
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
51
|
+
try {
|
|
52
|
+
const bots = await api.listAllPages(api.client.listBots, (r) => r.bots);
|
|
53
|
+
this.logger.success("Bots:");
|
|
54
|
+
this.logger.json(bots);
|
|
55
|
+
} catch (thrown) {
|
|
56
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not list bots");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class DeleteBotCommand extends import_global_command.GlobalCommand {
|
|
61
|
+
async run() {
|
|
62
|
+
const { client } = await this.ensureLoginAndCreateClient(this.argv);
|
|
63
|
+
try {
|
|
64
|
+
await client.deleteBot({ id: this.argv.botRef });
|
|
65
|
+
this.logger.success(`Bot ${import_chalk.default.bold(this.argv.botRef)} deleted`);
|
|
66
|
+
} catch (thrown) {
|
|
67
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not delete bot ${this.argv.botRef}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class CreateBotCommand extends import_global_command.GlobalCommand {
|
|
72
|
+
async run() {
|
|
73
|
+
const { client } = await this.ensureLoginAndCreateClient(this.argv);
|
|
74
|
+
try {
|
|
75
|
+
const { bot } = await client.createBot({ name: this.argv.name });
|
|
76
|
+
this.logger.success(`Bot ${import_chalk.default.bold(bot.id)}:`);
|
|
77
|
+
this.logger.json(bot);
|
|
78
|
+
} catch (thrown) {
|
|
79
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not create bot");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
CreateBotCommand,
|
|
86
|
+
DeleteBotCommand,
|
|
87
|
+
GetBotCommand,
|
|
88
|
+
ListBotsCommand
|
|
89
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var build_command_exports = {};
|
|
20
|
+
__export(build_command_exports, {
|
|
21
|
+
BuildCommand: () => BuildCommand
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(build_command_exports);
|
|
24
|
+
var import_bundle_command = require("./bundle-command");
|
|
25
|
+
var import_gen_command = require("./gen-command");
|
|
26
|
+
var import_project_command = require("./project-command");
|
|
27
|
+
class BuildCommand extends import_project_command.ProjectCommand {
|
|
28
|
+
async run() {
|
|
29
|
+
const t0 = Date.now();
|
|
30
|
+
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
31
|
+
if (integrationDef) {
|
|
32
|
+
await this._runGenerate();
|
|
33
|
+
}
|
|
34
|
+
await this._runBundle();
|
|
35
|
+
const dt = Date.now() - t0;
|
|
36
|
+
this.logger.log(`Build completed in ${dt}ms`);
|
|
37
|
+
}
|
|
38
|
+
_runGenerate() {
|
|
39
|
+
return new import_gen_command.GenerateCommand(this.api, this.prompt, this.logger, this.argv).run();
|
|
40
|
+
}
|
|
41
|
+
_runBundle() {
|
|
42
|
+
return new import_bundle_command.BundleCommand(this.api, this.prompt, this.logger, this.argv).run();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
BuildCommand
|
|
48
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var bundle_command_exports = {};
|
|
26
|
+
__export(bundle_command_exports, {
|
|
27
|
+
BundleCommand: () => BundleCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(bundle_command_exports);
|
|
30
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
|
+
var utils = __toESM(require("../utils"));
|
|
32
|
+
var import_project_command = require("./project-command");
|
|
33
|
+
class BundleCommand extends import_project_command.ProjectCommand {
|
|
34
|
+
async run() {
|
|
35
|
+
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
36
|
+
const abs = this.projectPaths.abs;
|
|
37
|
+
const rel = this.projectPaths.rel("workDir");
|
|
38
|
+
const line = this.logger.line();
|
|
39
|
+
const logLevel = this.argv.verbose ? "info" : "silent";
|
|
40
|
+
if (integrationDef) {
|
|
41
|
+
const { name } = integrationDef;
|
|
42
|
+
line.started(`Bundling integration ${import_chalk.default.bold(name)}...`);
|
|
43
|
+
} else {
|
|
44
|
+
line.started("Bundling bot...");
|
|
45
|
+
}
|
|
46
|
+
const unixPath = utils.path.toUnix(rel.entryPoint);
|
|
47
|
+
const importFrom = utils.path.rmExtension(unixPath);
|
|
48
|
+
const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`;
|
|
49
|
+
const outfile = abs.outFile;
|
|
50
|
+
line.debug(`Writing bundle to ${outfile}`);
|
|
51
|
+
await utils.esbuild.buildCode({ code, cwd: abs.workDir, outfile, logLevel, write: true });
|
|
52
|
+
line.success(`Bundle available at ${import_chalk.default.grey(rel.outDir)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
BundleCommand
|
|
58
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var deploy_command_exports = {};
|
|
26
|
+
__export(deploy_command_exports, {
|
|
27
|
+
DeployCommand: () => DeployCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(deploy_command_exports);
|
|
30
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
|
+
var fs = __toESM(require("fs"));
|
|
32
|
+
var consts = __toESM(require("../consts"));
|
|
33
|
+
var errors = __toESM(require("../errors"));
|
|
34
|
+
var utils = __toESM(require("../utils"));
|
|
35
|
+
var import_build_command = require("./build-command");
|
|
36
|
+
var import_project_command = require("./project-command");
|
|
37
|
+
class DeployCommand extends import_project_command.ProjectCommand {
|
|
38
|
+
async run() {
|
|
39
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
40
|
+
if (api.host !== consts.defaultBotpressApi) {
|
|
41
|
+
this.logger.log(`Using custom host ${api.host}`);
|
|
42
|
+
}
|
|
43
|
+
if (!this.argv.noBuild) {
|
|
44
|
+
await this._runBuild();
|
|
45
|
+
}
|
|
46
|
+
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
47
|
+
if (integrationDef) {
|
|
48
|
+
return this._deployIntegration(api, integrationDef);
|
|
49
|
+
}
|
|
50
|
+
return this._deployBot(api, this.argv.botId, this.argv.createNewBot);
|
|
51
|
+
}
|
|
52
|
+
async _runBuild() {
|
|
53
|
+
return new import_build_command.BuildCommand(this.api, this.prompt, this.logger, this.argv).run();
|
|
54
|
+
}
|
|
55
|
+
async _deployIntegration(api, integrationDef) {
|
|
56
|
+
const outfile = this.projectPaths.abs.outFile;
|
|
57
|
+
const code = await fs.promises.readFile(outfile, "utf-8");
|
|
58
|
+
const { name, version } = integrationDef;
|
|
59
|
+
const integration = await api.findIntegration({ type: "name", name, version });
|
|
60
|
+
let message;
|
|
61
|
+
if (integration) {
|
|
62
|
+
this.logger.warn("Integration already exists. If you decide to deploy, it will overwrite the existing one.");
|
|
63
|
+
message = `Are you sure you want to override integration ${integrationDef.name} v${integrationDef.version}?`;
|
|
64
|
+
} else {
|
|
65
|
+
message = `Are you sure you want to deploy integration ${integrationDef.name} v${integrationDef.version}?`;
|
|
66
|
+
}
|
|
67
|
+
const confirm = await this.prompt.confirm(message);
|
|
68
|
+
if (!confirm) {
|
|
69
|
+
this.logger.log("Aborted");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const line = this.logger.line();
|
|
73
|
+
line.started(`Deploying integration ${import_chalk.default.bold(integrationDef.name)} v${integrationDef.version}...`);
|
|
74
|
+
if (integration) {
|
|
75
|
+
await api.client.updateIntegration({ id: integration.id, ...integrationDef, code }).catch((thrown) => {
|
|
76
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not update integration "${integrationDef.name}"`);
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
await api.client.createIntegration({ ...integrationDef, code }).catch((thrown) => {
|
|
80
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not create integration "${integrationDef.name}"`);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
line.success("Integration deployed");
|
|
84
|
+
}
|
|
85
|
+
async _deployBot(api, argvBotId, argvCreateNew) {
|
|
86
|
+
const outfile = this.projectPaths.abs.outFile;
|
|
87
|
+
const code = await fs.promises.readFile(outfile, "utf-8");
|
|
88
|
+
const { default: botImpl } = utils.require.requireJsFile(outfile);
|
|
89
|
+
const { tags, states, events, recurringEvents, configuration: botConfiguration } = botImpl;
|
|
90
|
+
let bot;
|
|
91
|
+
if (argvBotId && argvCreateNew) {
|
|
92
|
+
throw new errors.BotpressCLIError("Cannot specify both --botId and --createNew");
|
|
93
|
+
} else if (argvCreateNew) {
|
|
94
|
+
const confirm = await this.prompt.confirm("Are you sure you want to create a new bot ?");
|
|
95
|
+
if (!confirm) {
|
|
96
|
+
this.logger.log("Aborted");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
bot = await this._createNewBot(api);
|
|
100
|
+
} else {
|
|
101
|
+
bot = await this._getExistingBot(api, argvBotId);
|
|
102
|
+
const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot "${bot.name}"?`);
|
|
103
|
+
if (!confirm) {
|
|
104
|
+
this.logger.log("Aborted");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const integrations = this.prepareIntegrations(botImpl, bot);
|
|
109
|
+
const line = this.logger.line();
|
|
110
|
+
line.started(`Deploying bot ${import_chalk.default.bold(bot.name)}...`);
|
|
111
|
+
const { bot: updatedBot } = await api.client.updateBot({
|
|
112
|
+
id: bot.id,
|
|
113
|
+
code,
|
|
114
|
+
states,
|
|
115
|
+
recurringEvents,
|
|
116
|
+
configuration: botConfiguration,
|
|
117
|
+
events,
|
|
118
|
+
tags,
|
|
119
|
+
integrations
|
|
120
|
+
}).catch((thrown) => {
|
|
121
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not update bot "${bot.name}"`);
|
|
122
|
+
});
|
|
123
|
+
line.success("Bot deployed");
|
|
124
|
+
this.displayWebhookUrls(updatedBot);
|
|
125
|
+
}
|
|
126
|
+
async _createNewBot(api) {
|
|
127
|
+
const line = this.logger.line();
|
|
128
|
+
const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {
|
|
129
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not create bot");
|
|
130
|
+
});
|
|
131
|
+
line.success(`Bot created with ID "${createdBot.id}" and name "${createdBot.name}"`);
|
|
132
|
+
await this.projectCache.set("botId", createdBot.id);
|
|
133
|
+
return createdBot;
|
|
134
|
+
}
|
|
135
|
+
async _getExistingBot(api, botId) {
|
|
136
|
+
const promptedBotId = await this.projectCache.sync("botId", botId, async (defaultId) => {
|
|
137
|
+
const userBots = await api.listAllPages(api.client.listBots, (r) => r.bots).catch((thrown) => {
|
|
138
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not fetch existing bots");
|
|
139
|
+
});
|
|
140
|
+
if (!userBots.length) {
|
|
141
|
+
throw new errors.NoBotsFoundError();
|
|
142
|
+
}
|
|
143
|
+
const initial = userBots.find((bot) => bot.id === defaultId);
|
|
144
|
+
const prompted = await this.prompt.select("Which bot do you want to deploy?", {
|
|
145
|
+
initial: initial && { title: initial.name, value: initial.id },
|
|
146
|
+
choices: userBots.map((bot) => ({ title: bot.name, value: bot.id }))
|
|
147
|
+
});
|
|
148
|
+
if (!prompted) {
|
|
149
|
+
throw new errors.ParamRequiredError("Bot Id");
|
|
150
|
+
}
|
|
151
|
+
return prompted;
|
|
152
|
+
});
|
|
153
|
+
const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {
|
|
154
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not get bot info");
|
|
155
|
+
});
|
|
156
|
+
return fetchedBot;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
DeployCommand
|
|
162
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var dev_command_exports = {};
|
|
26
|
+
__export(dev_command_exports, {
|
|
27
|
+
DevCommand: () => DevCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(dev_command_exports);
|
|
30
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
|
+
var pathlib = __toESM(require("path"));
|
|
32
|
+
var errors = __toESM(require("../errors"));
|
|
33
|
+
var utils = __toESM(require("../utils"));
|
|
34
|
+
var import_worker = require("../worker");
|
|
35
|
+
var import_build_command = require("./build-command");
|
|
36
|
+
var import_project_command = require("./project-command");
|
|
37
|
+
class DevCommand extends import_project_command.ProjectCommand {
|
|
38
|
+
async run() {
|
|
39
|
+
this.logger.warn("This command is experimental and subject to breaking changes without notice.");
|
|
40
|
+
if (!this.argv.noBuild) {
|
|
41
|
+
await this._runBuild();
|
|
42
|
+
}
|
|
43
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
44
|
+
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
45
|
+
if (integrationDef) {
|
|
46
|
+
await this._deployDevIntegration(api, this.argv.url, integrationDef);
|
|
47
|
+
} else {
|
|
48
|
+
await this._deployDevBot(api, this.argv.url);
|
|
49
|
+
}
|
|
50
|
+
const outfile = this.projectPaths.abs.outFile;
|
|
51
|
+
const importPath = utils.path.toUnix(outfile);
|
|
52
|
+
const requireFrom = utils.path.rmExtension(importPath);
|
|
53
|
+
const code = `require('${requireFrom}').default.start(${this.argv.port})`;
|
|
54
|
+
const worker = await import_worker.Worker.spawn(
|
|
55
|
+
{
|
|
56
|
+
type: "code",
|
|
57
|
+
code,
|
|
58
|
+
env: {
|
|
59
|
+
BP_API_URL: api.host,
|
|
60
|
+
BP_TOKEN: api.token
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
this.logger
|
|
64
|
+
).catch((thrown) => {
|
|
65
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not start dev worker");
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
const watcher = await utils.filewatcher.FileWatcher.watch(
|
|
69
|
+
this.argv.workDir,
|
|
70
|
+
async (events) => {
|
|
71
|
+
const typescriptEvents = events.filter((e) => pathlib.extname(e.path) === ".ts");
|
|
72
|
+
if (typescriptEvents.length === 0) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.logger.log("Changes detected, reloading...");
|
|
76
|
+
await this._runBuild();
|
|
77
|
+
await worker.reload();
|
|
78
|
+
},
|
|
79
|
+
{ ignore: [this.projectPaths.abs.outDir] }
|
|
80
|
+
);
|
|
81
|
+
await Promise.race([worker.wait(), watcher.wait()]);
|
|
82
|
+
await watcher.close();
|
|
83
|
+
} catch (thrown) {
|
|
84
|
+
throw errors.BotpressCLIError.wrap(thrown, "An error occurred while running the dev worker");
|
|
85
|
+
} finally {
|
|
86
|
+
if (worker.running) {
|
|
87
|
+
await worker.kill();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
_runBuild() {
|
|
92
|
+
return new import_build_command.BuildCommand(this.api, this.prompt, this.logger, this.argv).run();
|
|
93
|
+
}
|
|
94
|
+
async _deployDevIntegration(api, externalUrl, integrationDef) {
|
|
95
|
+
const devId = await this.projectCache.get("devId");
|
|
96
|
+
let integration = void 0;
|
|
97
|
+
if (devId) {
|
|
98
|
+
const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {
|
|
99
|
+
const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id "${devId}"`);
|
|
100
|
+
this.logger.warn(err.message);
|
|
101
|
+
return { integration: void 0 };
|
|
102
|
+
});
|
|
103
|
+
if (resp.integration?.dev) {
|
|
104
|
+
integration = resp.integration;
|
|
105
|
+
} else {
|
|
106
|
+
await this.projectCache.rm("devId");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const line = this.logger.line();
|
|
110
|
+
line.started(`Deploying dev integration ${import_chalk.default.bold(integrationDef.name)}...`);
|
|
111
|
+
if (integration) {
|
|
112
|
+
const resp = await api.client.updateIntegration({ ...integrationDef, id: integration.id, url: externalUrl }).catch((thrown) => {
|
|
113
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration "${integrationDef.name}"`);
|
|
114
|
+
});
|
|
115
|
+
integration = resp.integration;
|
|
116
|
+
} else {
|
|
117
|
+
const resp = await api.client.createIntegration({ ...integrationDef, dev: true, url: externalUrl }).catch((thrown) => {
|
|
118
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration "${integrationDef.name}"`);
|
|
119
|
+
});
|
|
120
|
+
integration = resp.integration;
|
|
121
|
+
}
|
|
122
|
+
line.success(`Dev Integration deployed with id "${integration.id}"`);
|
|
123
|
+
await this.projectCache.set("devId", integration.id);
|
|
124
|
+
}
|
|
125
|
+
async _deployDevBot(api, externalUrl) {
|
|
126
|
+
const devId = await this.projectCache.get("devId");
|
|
127
|
+
let bot = void 0;
|
|
128
|
+
if (devId) {
|
|
129
|
+
const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {
|
|
130
|
+
const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id "${devId}"`);
|
|
131
|
+
this.logger.warn(err.message);
|
|
132
|
+
return { bot: void 0 };
|
|
133
|
+
});
|
|
134
|
+
if (resp.bot?.dev) {
|
|
135
|
+
bot = resp.bot;
|
|
136
|
+
} else {
|
|
137
|
+
await this.projectCache.rm("devId");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!bot) {
|
|
141
|
+
const createLine = this.logger.line();
|
|
142
|
+
createLine.started("Creating dev bot...");
|
|
143
|
+
const resp = await api.client.createBot({
|
|
144
|
+
dev: true,
|
|
145
|
+
url: externalUrl
|
|
146
|
+
}).catch((thrown) => {
|
|
147
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
148
|
+
});
|
|
149
|
+
bot = resp.bot;
|
|
150
|
+
createLine.success(`Dev Bot created with id "${bot.id}"`);
|
|
151
|
+
await this.projectCache.set("devId", bot.id);
|
|
152
|
+
}
|
|
153
|
+
const outfile = this.projectPaths.abs.outFile;
|
|
154
|
+
const { default: botImpl } = utils.require.requireJsFile(outfile);
|
|
155
|
+
const integrations = this.prepareIntegrations(botImpl, bot);
|
|
156
|
+
const updateLine = this.logger.line();
|
|
157
|
+
updateLine.started("Updating bot integrations...");
|
|
158
|
+
const { bot: updatedBot } = await api.client.updateBot({ id: bot.id, integrations, url: externalUrl }).catch((thrown) => {
|
|
159
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
160
|
+
});
|
|
161
|
+
updateLine.success("Integrations installed successfully");
|
|
162
|
+
this.displayWebhookUrls(updatedBot);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
DevCommand
|
|
168
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var gen_command_exports = {};
|
|
26
|
+
__export(gen_command_exports, {
|
|
27
|
+
GenerateCommand: () => GenerateCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(gen_command_exports);
|
|
30
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
|
+
var codegen = __toESM(require("../code-generation"));
|
|
32
|
+
var import_project_command = require("./project-command");
|
|
33
|
+
class GenerateCommand extends import_project_command.ProjectCommand {
|
|
34
|
+
async run() {
|
|
35
|
+
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
36
|
+
if (!integrationDef) {
|
|
37
|
+
this.logger.warn("No typings to generate for bot");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const line = this.logger.line();
|
|
41
|
+
const { name } = integrationDef;
|
|
42
|
+
line.started(`Generating typings for integration ${import_chalk.default.bold(name)}...`);
|
|
43
|
+
const fromWorkDir = this.projectPaths.rel("workDir");
|
|
44
|
+
const fromOutDir = this.projectPaths.rel("outDir");
|
|
45
|
+
const typingFiles = await codegen.generateIntegrationImplementationTypings(
|
|
46
|
+
integrationDef,
|
|
47
|
+
fromOutDir.implementationDir
|
|
48
|
+
);
|
|
49
|
+
const indexFile = await codegen.generateIntegrationIndex(fromOutDir.implementationDir);
|
|
50
|
+
const generatedFiles = [...typingFiles, indexFile];
|
|
51
|
+
await this.writeGeneratedFilesToOutFolder(generatedFiles);
|
|
52
|
+
line.success(`Typings available at ${import_chalk.default.grey(fromWorkDir.outDir)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
GenerateCommand
|
|
58
|
+
});
|