@botpress/cli 0.0.8 → 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 +28 -31
- package/dist/app/index.js +18 -11
- package/dist/app/project.js +4 -4
- 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 -8
- package/dist/consts.js +24 -9
- package/dist/errors.js +156 -0
- package/dist/index.js +33 -20
- package/dist/integration-ref.js +61 -0
- package/dist/path-utils.js +7 -4
- 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 +7 -5
- 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
|
@@ -0,0 +1,124 @@
|
|
|
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 add_command_exports = {};
|
|
26
|
+
__export(add_command_exports, {
|
|
27
|
+
AddCommand: () => AddCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(add_command_exports);
|
|
30
|
+
var import_bluebird = __toESM(require("bluebird"));
|
|
31
|
+
var import_chalk = __toESM(require("chalk"));
|
|
32
|
+
var fs = __toESM(require("fs"));
|
|
33
|
+
var pathlib = __toESM(require("path"));
|
|
34
|
+
var codegen = __toESM(require("../code-generation"));
|
|
35
|
+
var errors = __toESM(require("../errors"));
|
|
36
|
+
var import_integration_ref = require("../integration-ref");
|
|
37
|
+
var import_project_command = require("./project-command");
|
|
38
|
+
class AddCommand extends import_project_command.ProjectCommand {
|
|
39
|
+
async run() {
|
|
40
|
+
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
41
|
+
if (integrationDef) {
|
|
42
|
+
throw new errors.ExclusiveBotFeatureError();
|
|
43
|
+
}
|
|
44
|
+
const integrationRef = this.argv.integrationRef;
|
|
45
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
46
|
+
const parsedRef = (0, import_integration_ref.parseIntegrationRef)(integrationRef);
|
|
47
|
+
if (!parsedRef) {
|
|
48
|
+
throw new errors.InvalidIntegrationReferenceError(integrationRef);
|
|
49
|
+
}
|
|
50
|
+
const integration = await api.findIntegration(parsedRef);
|
|
51
|
+
if (!integration) {
|
|
52
|
+
throw new errors.BotpressCLIError(`Integration "${integrationRef}" not found`);
|
|
53
|
+
}
|
|
54
|
+
const allInstances = await this._listIntegrationInstances();
|
|
55
|
+
const existingInstance = allInstances.find((i) => i.name === integration.name);
|
|
56
|
+
if (existingInstance) {
|
|
57
|
+
this.logger.warn(`Integration with name "${integration.name}" already installed.`);
|
|
58
|
+
const res = await this.prompt.confirm("Do you want to overwrite the existing instance?");
|
|
59
|
+
if (!res) {
|
|
60
|
+
this.logger.log("Aborted");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
await this._uninstallIntegration(existingInstance);
|
|
64
|
+
}
|
|
65
|
+
await this._generateIntegrationInstance(integration);
|
|
66
|
+
}
|
|
67
|
+
async _listIntegrationInstances() {
|
|
68
|
+
const installPath = this.projectPaths.abs.installDir;
|
|
69
|
+
if (!fs.existsSync(installPath)) {
|
|
70
|
+
this.logger.debug("Install path does not exist. Skipping listing of integration instances");
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const allFiles = await fs.promises.readdir(installPath);
|
|
74
|
+
const allPaths = allFiles.map((name) => pathlib.join(installPath, name));
|
|
75
|
+
const directories = await import_bluebird.default.filter(allPaths, async (path) => {
|
|
76
|
+
const stat = await fs.promises.stat(path);
|
|
77
|
+
return stat.isDirectory();
|
|
78
|
+
});
|
|
79
|
+
let jsons = directories.map((root) => ({ root, json: pathlib.join(root, codegen.INTEGRATION_JSON) }));
|
|
80
|
+
jsons = jsons.filter(({ json: x }) => fs.existsSync(x));
|
|
81
|
+
return import_bluebird.default.map(jsons, async ({ root, json }) => {
|
|
82
|
+
const content = await fs.promises.readFile(json, "utf-8");
|
|
83
|
+
const { name, version, id } = JSON.parse(content);
|
|
84
|
+
const dirname = pathlib.basename(root);
|
|
85
|
+
return {
|
|
86
|
+
dirname,
|
|
87
|
+
id,
|
|
88
|
+
name,
|
|
89
|
+
version
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async _uninstallIntegration(instance) {
|
|
94
|
+
const installDir = this.projectPaths.abs.installDir;
|
|
95
|
+
const instancePath = pathlib.join(installDir, instance.dirname);
|
|
96
|
+
await fs.promises.rm(instancePath, { recursive: true });
|
|
97
|
+
await this._generateBotIndex();
|
|
98
|
+
}
|
|
99
|
+
async _generateIntegrationInstance(integration) {
|
|
100
|
+
const line = this.logger.line();
|
|
101
|
+
const { name, version } = integration;
|
|
102
|
+
line.started(`Installing ${import_chalk.default.bold(name)} v${version}...`);
|
|
103
|
+
const instanceFiles = await codegen.generateIntegrationInstance(
|
|
104
|
+
integration,
|
|
105
|
+
this.projectPaths.rel("outDir").installDir
|
|
106
|
+
);
|
|
107
|
+
await this.writeGeneratedFilesToOutFolder(instanceFiles);
|
|
108
|
+
await this._generateBotIndex();
|
|
109
|
+
const rel = this.projectPaths.rel("workDir");
|
|
110
|
+
line.success(`Installed integration available at ${import_chalk.default.grey(rel.outDir)}`);
|
|
111
|
+
}
|
|
112
|
+
async _generateBotIndex() {
|
|
113
|
+
const allInstances = await this._listIntegrationInstances();
|
|
114
|
+
const indexFile = await codegen.generateBotIndex(
|
|
115
|
+
this.projectPaths.rel("outDir").installDir,
|
|
116
|
+
allInstances.map((i) => i.dirname)
|
|
117
|
+
);
|
|
118
|
+
await this.writeGeneratedFilesToOutFolder([indexFile]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
AddCommand
|
|
124
|
+
});
|
|
@@ -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
|
+
});
|