@botpress/cli 0.0.14 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.js +1 -0
- package/dist/api-client.js.map +7 -0
- package/dist/code-generation/action.js +1 -0
- package/dist/code-generation/action.js.map +7 -0
- package/dist/code-generation/channel.js +1 -0
- package/dist/code-generation/channel.js.map +7 -0
- package/dist/code-generation/configuration.js +1 -0
- package/dist/code-generation/configuration.js.map +7 -0
- package/dist/code-generation/const.js +1 -0
- package/dist/code-generation/const.js.map +7 -0
- package/dist/code-generation/event.js +1 -0
- package/dist/code-generation/event.js.map +7 -0
- package/dist/code-generation/index.js +1 -0
- package/dist/code-generation/index.js.map +7 -0
- package/dist/code-generation/integration-impl.js +1 -0
- package/dist/code-generation/integration-impl.js.map +7 -0
- package/dist/code-generation/integration-instance.js +1 -0
- package/dist/code-generation/integration-instance.js.map +7 -0
- package/dist/code-generation/integration-secret.js +1 -0
- package/dist/code-generation/integration-secret.js.map +7 -0
- package/dist/code-generation/message.js +1 -0
- package/dist/code-generation/message.js.map +7 -0
- package/dist/code-generation/module.js +1 -0
- package/dist/code-generation/module.js.map +7 -0
- package/dist/code-generation/typings.js +1 -0
- package/dist/code-generation/typings.js.map +7 -0
- package/dist/command-definitions.js +1 -0
- package/dist/command-definitions.js.map +7 -0
- package/dist/command-implementations/add-command.js +1 -0
- package/dist/command-implementations/add-command.js.map +7 -0
- package/dist/command-implementations/base-command.js +8 -1
- package/dist/command-implementations/base-command.js.map +7 -0
- package/dist/command-implementations/bot-commands.js +1 -0
- package/dist/command-implementations/bot-commands.js.map +7 -0
- package/dist/command-implementations/build-command.js +1 -0
- package/dist/command-implementations/build-command.js.map +7 -0
- package/dist/command-implementations/bundle-command.js +1 -0
- package/dist/command-implementations/bundle-command.js.map +7 -0
- package/dist/command-implementations/deploy-command.js +21 -3
- package/dist/command-implementations/deploy-command.js.map +7 -0
- package/dist/command-implementations/dev-command.js +1 -0
- package/dist/command-implementations/dev-command.js.map +7 -0
- package/dist/command-implementations/gen-command.js +1 -0
- package/dist/command-implementations/gen-command.js.map +7 -0
- package/dist/command-implementations/global-command.js +1 -0
- package/dist/command-implementations/global-command.js.map +7 -0
- package/dist/command-implementations/index.js +1 -0
- package/dist/command-implementations/index.js.map +7 -0
- package/dist/command-implementations/init-command.js +1 -0
- package/dist/command-implementations/init-command.js.map +7 -0
- package/dist/command-implementations/integration-commands.js +1 -0
- package/dist/command-implementations/integration-commands.js.map +7 -0
- package/dist/command-implementations/login-command.js +1 -0
- package/dist/command-implementations/login-command.js.map +7 -0
- package/dist/command-implementations/logout-command.js +1 -0
- package/dist/command-implementations/logout-command.js.map +7 -0
- package/dist/command-implementations/project-command.js +1 -0
- package/dist/command-implementations/project-command.js.map +7 -0
- package/dist/command-implementations/serve-command.js +1 -0
- package/dist/command-implementations/serve-command.js.map +7 -0
- package/dist/command-tree.js +1 -0
- package/dist/command-tree.js.map +7 -0
- package/dist/config.js +1 -0
- package/dist/config.js.map +7 -0
- package/dist/consts.js +1 -0
- package/dist/consts.js.map +7 -0
- package/dist/errors.js +27 -1
- package/dist/errors.js.map +7 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +7 -0
- package/dist/init.js +1 -0
- package/dist/init.js.map +7 -0
- package/dist/integration-ref.js +1 -0
- package/dist/integration-ref.js.map +7 -0
- package/dist/logger/base-logger.js +1 -0
- package/dist/logger/base-logger.js.map +7 -0
- package/dist/logger/index.js +1 -0
- package/dist/logger/index.js.map +7 -0
- package/dist/register-yargs.js +1 -0
- package/dist/register-yargs.js.map +7 -0
- package/dist/typings.js +1 -0
- package/dist/typings.js.map +7 -0
- package/dist/utils/cache-utils.js +1 -0
- package/dist/utils/cache-utils.js.map +7 -0
- package/dist/utils/case-utils.js +1 -0
- package/dist/utils/case-utils.js.map +7 -0
- package/dist/utils/esbuild-utils.js +1 -0
- package/dist/utils/esbuild-utils.js.map +7 -0
- package/dist/utils/event-emitter.js +1 -0
- package/dist/utils/event-emitter.js.map +7 -0
- package/dist/utils/file-watcher.js +1 -0
- package/dist/utils/file-watcher.js.map +7 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/path-utils.js +1 -0
- package/dist/utils/path-utils.js.map +7 -0
- package/dist/utils/prompt-utils.js +1 -0
- package/dist/utils/prompt-utils.js.map +7 -0
- package/dist/utils/require-utils.js +1 -0
- package/dist/utils/require-utils.js.map +7 -0
- package/dist/worker/child-entrypoint.js +1 -0
- package/dist/worker/child-entrypoint.js.map +7 -0
- package/dist/worker/child-wrapper.js +1 -0
- package/dist/worker/child-wrapper.js.map +7 -0
- package/dist/worker/config.js +1 -0
- package/dist/worker/config.js.map +7 -0
- package/dist/worker/index.js +1 -0
- package/dist/worker/index.js.map +7 -0
- package/dist/worker/is-child.js +1 -0
- package/dist/worker/is-child.js.map +7 -0
- package/dist/worker/worker-state.js +1 -0
- package/dist/worker/worker-state.js.map +7 -0
- package/dist/worker/worker.js +1 -0
- package/dist/worker/worker.js.map +7 -0
- package/package.json +13 -13
- package/templates/echo-bot/package.json +1 -2
- package/templates/empty-integration/integration.definition.ts +2 -2
- package/templates/empty-integration/package.json +1 -2
- package/build.ts +0 -12
- package/dist/app/api-utils.js +0 -112
- package/dist/app/base.js +0 -71
- package/dist/app/cache.js +0 -95
- package/dist/app/errors.js +0 -156
- package/dist/app/file-paths.js +0 -79
- package/dist/app/generator/action.js +0 -76
- package/dist/app/generator/channel.js +0 -51
- package/dist/app/generator/configuration.js +0 -40
- package/dist/app/generator/const.js +0 -31
- package/dist/app/generator/event.js +0 -47
- package/dist/app/generator/index.js +0 -83
- package/dist/app/generator/integration-impl.js +0 -147
- package/dist/app/generator/integration-instance.js +0 -85
- package/dist/app/generator/message.js +0 -47
- package/dist/app/generator/module.js +0 -115
- package/dist/app/generator/strings.js +0 -38
- package/dist/app/generator/typings.js +0 -16
- package/dist/app/index.js +0 -82
- package/dist/app/integration-ref.js +0 -61
- package/dist/app/project.js +0 -486
- package/dist/app/typings.js +0 -16
- package/dist/app/user.js +0 -237
- package/dist/esbuild-utils.js +0 -89
- package/dist/event-emitter.js +0 -62
- package/dist/path-utils.js +0 -72
- package/dist/require-utils.js +0 -49
- package/dist/update-notif.js +0 -47
- package/dist/utils/string-utils.js +0 -68
- package/dist/watcher.js +0 -68
- package/templates/echo-bot/.botpress/project.cache.json +0 -1
package/dist/app/project.js
DELETED
|
@@ -1,486 +0,0 @@
|
|
|
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 project_exports = {};
|
|
26
|
-
__export(project_exports, {
|
|
27
|
-
ProjectCommands: () => ProjectCommands
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(project_exports);
|
|
30
|
-
var import_bluebird = __toESM(require("bluebird"));
|
|
31
|
-
var import_chalk = __toESM(require("chalk"));
|
|
32
|
-
var import_fs = __toESM(require("fs"));
|
|
33
|
-
var import_lodash = __toESM(require("lodash"));
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_prompts = __toESM(require("prompts"));
|
|
36
|
-
var consts = __toESM(require("../consts"));
|
|
37
|
-
var esbuildutils = __toESM(require("../esbuild-utils"));
|
|
38
|
-
var pathutils = __toESM(require("../path-utils"));
|
|
39
|
-
var requireutils = __toESM(require("../require-utils"));
|
|
40
|
-
var import_watcher = require("../watcher");
|
|
41
|
-
var import_worker = require("../worker");
|
|
42
|
-
var import_base = require("./base");
|
|
43
|
-
var errors = __toESM(require("./errors"));
|
|
44
|
-
var generator = __toESM(require("./generator"));
|
|
45
|
-
var import_integration_ref = require("./integration-ref");
|
|
46
|
-
class ProjectCommands extends import_base.BaseCommands {
|
|
47
|
-
constructor(props, _paths, _projectCache, userCache, logger) {
|
|
48
|
-
super(props, userCache, logger);
|
|
49
|
-
this._paths = _paths;
|
|
50
|
-
this._projectCache = _projectCache;
|
|
51
|
-
}
|
|
52
|
-
async installIntegration(integrationRef, argv) {
|
|
53
|
-
const integrationDef = await this._readIntegrationDefinitionFromFS();
|
|
54
|
-
if (integrationDef) {
|
|
55
|
-
throw new errors.ExclusiveBotFeatureError();
|
|
56
|
-
}
|
|
57
|
-
const api = await this._ensureLoginAndCreateClient(argv);
|
|
58
|
-
const parsedRef = (0, import_integration_ref.parseIntegrationRef)(integrationRef);
|
|
59
|
-
if (!parsedRef) {
|
|
60
|
-
throw new errors.InvalidIntegrationReferenceError(integrationRef);
|
|
61
|
-
}
|
|
62
|
-
const integration = await api.findIntegration(parsedRef);
|
|
63
|
-
if (!integration) {
|
|
64
|
-
throw new errors.BotpressCLIError(`Integration "${integrationRef}" not found`);
|
|
65
|
-
}
|
|
66
|
-
const allInstances = await this._listIntegrationInstances();
|
|
67
|
-
const existingInstance = allInstances.find((i) => i.name === integration.name);
|
|
68
|
-
if (existingInstance) {
|
|
69
|
-
this._logger.warn(`Integration with name "${integration.name}" already installed.`);
|
|
70
|
-
const res = await this._confirm("Do you want to overwrite the existing instance?");
|
|
71
|
-
if (!res) {
|
|
72
|
-
this._logger.log("Aborted");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
await this._uninstallIntegration(existingInstance);
|
|
76
|
-
}
|
|
77
|
-
await this._generateIntegrationInstance(integration);
|
|
78
|
-
}
|
|
79
|
-
async buildProject(argv) {
|
|
80
|
-
const t0 = Date.now();
|
|
81
|
-
const integrationDef = await this._readIntegrationDefinitionFromFS();
|
|
82
|
-
if (integrationDef) {
|
|
83
|
-
await this.generateTypings(argv);
|
|
84
|
-
}
|
|
85
|
-
await this.bundleProject(argv);
|
|
86
|
-
const dt = Date.now() - t0;
|
|
87
|
-
this._logger.log(`Build completed in ${dt}ms`);
|
|
88
|
-
}
|
|
89
|
-
async serveProject(argv) {
|
|
90
|
-
const outfile = this._paths.abs.outFile;
|
|
91
|
-
if (!import_fs.default.existsSync(outfile)) {
|
|
92
|
-
throw new errors.NoBundleFoundError();
|
|
93
|
-
}
|
|
94
|
-
const isIntegration = !!await this._readIntegrationDefinitionFromFS();
|
|
95
|
-
this._logger.log(`Serving ${isIntegration ? "integration" : "bot"}...`);
|
|
96
|
-
const { default: serveable } = requireutils.requireJsFile(outfile);
|
|
97
|
-
return serveable.start(argv.port);
|
|
98
|
-
}
|
|
99
|
-
async bundleProject(_argv) {
|
|
100
|
-
const integrationDef = await this._readIntegrationDefinitionFromFS();
|
|
101
|
-
const { rel, abs } = this._paths;
|
|
102
|
-
const line = this._logger.line();
|
|
103
|
-
const logLevel = this._props.verbose ? "info" : "silent";
|
|
104
|
-
if (integrationDef) {
|
|
105
|
-
const { name } = integrationDef;
|
|
106
|
-
line.started(`Bundling integration ${import_chalk.default.bold(name)}...`);
|
|
107
|
-
} else {
|
|
108
|
-
line.started("Bundling bot...");
|
|
109
|
-
}
|
|
110
|
-
const unixPath = pathutils.toUnix(rel.entryPoint);
|
|
111
|
-
const importFrom = pathutils.rmExtension(unixPath);
|
|
112
|
-
const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`;
|
|
113
|
-
const outfile = abs.outFile;
|
|
114
|
-
line.debug(`Writing bundle to ${outfile}`);
|
|
115
|
-
await esbuildutils.buildCode({ code, cwd: abs.workDir, outfile, logLevel, write: true });
|
|
116
|
-
line.success(`Bundle available at ${import_chalk.default.grey(rel.outDir)}`);
|
|
117
|
-
}
|
|
118
|
-
async generateTypings(_argv) {
|
|
119
|
-
const integrationDef = await this._readIntegrationDefinitionFromFS();
|
|
120
|
-
if (!integrationDef) {
|
|
121
|
-
this._logger.warn("No typings to generate for bot");
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const line = this._logger.line();
|
|
125
|
-
const { name } = integrationDef;
|
|
126
|
-
line.started(`Generating typings for integration ${import_chalk.default.bold(name)}...`);
|
|
127
|
-
const typingFiles = await generator.generateIntegrationImplementationTypings(
|
|
128
|
-
integrationDef,
|
|
129
|
-
this._paths.relFrom("outDir").implementationDir
|
|
130
|
-
);
|
|
131
|
-
const indexFile = await generator.generateIntegrationIndex(this._paths.relFrom("outDir").implementationDir);
|
|
132
|
-
const generatedFiles = [...typingFiles, indexFile];
|
|
133
|
-
await this._writeFilesToOutFolder(generatedFiles);
|
|
134
|
-
line.success(`Typings available at ${import_chalk.default.grey(this._paths.rel.outDir)}`);
|
|
135
|
-
}
|
|
136
|
-
async deployProject(argv) {
|
|
137
|
-
const api = await this._ensureLoginAndCreateClient(argv);
|
|
138
|
-
if (api.host !== consts.defaultBotpressApi) {
|
|
139
|
-
this._logger.log(`Using custom host ${api.host}`);
|
|
140
|
-
}
|
|
141
|
-
if (!argv.noBuild) {
|
|
142
|
-
await this.buildProject(argv);
|
|
143
|
-
}
|
|
144
|
-
const integrationDef = await this._readIntegrationDefinitionFromFS();
|
|
145
|
-
if (integrationDef) {
|
|
146
|
-
return this._deployIntegration(api, integrationDef);
|
|
147
|
-
}
|
|
148
|
-
return this._deployBot(api, argv.botId, argv.createNewBot);
|
|
149
|
-
}
|
|
150
|
-
async devProject(argv) {
|
|
151
|
-
this._logger.warn("This command is experimental and subject to breaking changes without notice.");
|
|
152
|
-
if (!argv.noBuild) {
|
|
153
|
-
await this.buildProject(argv);
|
|
154
|
-
}
|
|
155
|
-
const api = await this._ensureLoginAndCreateClient(argv);
|
|
156
|
-
const integrationDef = await this._readIntegrationDefinitionFromFS();
|
|
157
|
-
if (integrationDef) {
|
|
158
|
-
await this._deployDevIntegration(api, argv.url, integrationDef);
|
|
159
|
-
} else {
|
|
160
|
-
await this._deployDevBot(api, argv.url);
|
|
161
|
-
}
|
|
162
|
-
const outfile = this._paths.abs.outFile;
|
|
163
|
-
const importPath = pathutils.toUnix(outfile);
|
|
164
|
-
const requireFrom = pathutils.rmExtension(importPath);
|
|
165
|
-
const code = `require('${requireFrom}').default.start(${argv.port})`;
|
|
166
|
-
const worker = await import_worker.Worker.spawn(
|
|
167
|
-
{
|
|
168
|
-
type: "code",
|
|
169
|
-
code,
|
|
170
|
-
env: {
|
|
171
|
-
BP_API_URL: api.host,
|
|
172
|
-
BP_TOKEN: api.token
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
this._logger
|
|
176
|
-
).catch((thrown) => {
|
|
177
|
-
throw errors.BotpressCLIError.wrap(thrown, "Could not start dev worker");
|
|
178
|
-
});
|
|
179
|
-
try {
|
|
180
|
-
const watcher = await import_watcher.FileWatcher.watch(
|
|
181
|
-
argv.workDir,
|
|
182
|
-
async (events) => {
|
|
183
|
-
const typescriptEvents = events.filter((e) => import_path.default.extname(e.path) === ".ts");
|
|
184
|
-
if (typescriptEvents.length === 0) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
this._logger.log("Changes detected, reloading...");
|
|
188
|
-
await this.buildProject(argv);
|
|
189
|
-
await worker.reload();
|
|
190
|
-
},
|
|
191
|
-
{ ignore: [this._paths.abs.outDir] }
|
|
192
|
-
);
|
|
193
|
-
await Promise.race([worker.wait(), watcher.wait()]);
|
|
194
|
-
await watcher.close();
|
|
195
|
-
} catch (thrown) {
|
|
196
|
-
throw errors.BotpressCLIError.wrap(thrown, "An error occurred while running the dev worker");
|
|
197
|
-
} finally {
|
|
198
|
-
if (worker.running) {
|
|
199
|
-
await worker.kill();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
async _deployDevIntegration(api, externalUrl, integrationDef) {
|
|
204
|
-
const devId = await this._projectCache.get("devId");
|
|
205
|
-
let integration = void 0;
|
|
206
|
-
if (devId) {
|
|
207
|
-
const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {
|
|
208
|
-
const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id "${devId}"`);
|
|
209
|
-
this._logger.warn(err.message);
|
|
210
|
-
return { integration: void 0 };
|
|
211
|
-
});
|
|
212
|
-
if (resp.integration?.dev) {
|
|
213
|
-
integration = resp.integration;
|
|
214
|
-
} else {
|
|
215
|
-
await this._projectCache.rm("devId");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const line = this._logger.line();
|
|
219
|
-
line.started(`Deploying dev integration ${import_chalk.default.bold(integrationDef.name)}...`);
|
|
220
|
-
if (integration) {
|
|
221
|
-
const resp = await api.client.updateIntegration({ ...integrationDef, id: integration.id, url: externalUrl }).catch((thrown) => {
|
|
222
|
-
throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration "${integrationDef.name}"`);
|
|
223
|
-
});
|
|
224
|
-
integration = resp.integration;
|
|
225
|
-
} else {
|
|
226
|
-
const resp = await api.client.createIntegration({ ...integrationDef, dev: true, url: externalUrl }).catch((thrown) => {
|
|
227
|
-
throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration "${integrationDef.name}"`);
|
|
228
|
-
});
|
|
229
|
-
integration = resp.integration;
|
|
230
|
-
}
|
|
231
|
-
line.success(`Dev Integration deployed with id "${integration.id}"`);
|
|
232
|
-
await this._projectCache.set("devId", integration.id);
|
|
233
|
-
}
|
|
234
|
-
async _deployDevBot(api, externalUrl) {
|
|
235
|
-
const devId = await this._projectCache.get("devId");
|
|
236
|
-
let bot = void 0;
|
|
237
|
-
if (devId) {
|
|
238
|
-
const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {
|
|
239
|
-
const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id "${devId}"`);
|
|
240
|
-
this._logger.warn(err.message);
|
|
241
|
-
return { bot: void 0 };
|
|
242
|
-
});
|
|
243
|
-
if (resp.bot?.dev) {
|
|
244
|
-
bot = resp.bot;
|
|
245
|
-
} else {
|
|
246
|
-
await this._projectCache.rm("devId");
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (!bot) {
|
|
250
|
-
const createLine = this._logger.line();
|
|
251
|
-
createLine.started("Creating dev bot...");
|
|
252
|
-
const resp = await api.client.createBot({
|
|
253
|
-
dev: true,
|
|
254
|
-
url: externalUrl
|
|
255
|
-
}).catch((thrown) => {
|
|
256
|
-
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
257
|
-
});
|
|
258
|
-
bot = resp.bot;
|
|
259
|
-
createLine.success(`Dev Bot created with id "${bot.id}"`);
|
|
260
|
-
await this._projectCache.set("devId", bot.id);
|
|
261
|
-
}
|
|
262
|
-
const outfile = this._paths.abs.outFile;
|
|
263
|
-
const { default: botImpl } = requireutils.requireJsFile(outfile);
|
|
264
|
-
const integrations = this._prepareIntegrations(botImpl, bot);
|
|
265
|
-
const updateLine = this._logger.line();
|
|
266
|
-
updateLine.started("Updating bot integrations...");
|
|
267
|
-
const { bot: updatedBot } = await api.client.updateBot({ id: bot.id, integrations, url: externalUrl }).catch((thrown) => {
|
|
268
|
-
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
269
|
-
});
|
|
270
|
-
updateLine.success("Integrations installed successfully");
|
|
271
|
-
this._displayWebhookUrls(updatedBot);
|
|
272
|
-
}
|
|
273
|
-
async _deployIntegration(api, integrationDef) {
|
|
274
|
-
const outfile = this._paths.abs.outFile;
|
|
275
|
-
const code = await import_fs.default.promises.readFile(outfile, "utf-8");
|
|
276
|
-
const { name, version } = integrationDef;
|
|
277
|
-
const integration = await api.findIntegration({ type: "name", name, version });
|
|
278
|
-
let message;
|
|
279
|
-
if (integration) {
|
|
280
|
-
this._logger.warn("Integration already exists. If you decide to deploy, it will overwrite the existing one.");
|
|
281
|
-
message = `Are you sure you want to override integration ${integrationDef.name} v${integrationDef.version}?`;
|
|
282
|
-
} else {
|
|
283
|
-
message = `Are you sure you want to deploy integration ${integrationDef.name} v${integrationDef.version}?`;
|
|
284
|
-
}
|
|
285
|
-
const confirm = await this._confirm(message);
|
|
286
|
-
if (!confirm) {
|
|
287
|
-
this._logger.log("Aborted");
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
const line = this._logger.line();
|
|
291
|
-
line.started(`Deploying integration ${import_chalk.default.bold(integrationDef.name)} v${integrationDef.version}...`);
|
|
292
|
-
if (integration) {
|
|
293
|
-
await api.client.updateIntegration({ id: integration.id, ...integrationDef, code }).catch((thrown) => {
|
|
294
|
-
throw errors.BotpressCLIError.wrap(thrown, `Could not update integration "${integrationDef.name}"`);
|
|
295
|
-
});
|
|
296
|
-
} else {
|
|
297
|
-
await api.client.createIntegration({ ...integrationDef, code }).catch((thrown) => {
|
|
298
|
-
throw errors.BotpressCLIError.wrap(thrown, `Could not create integration "${integrationDef.name}"`);
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
line.success("Integration deployed");
|
|
302
|
-
}
|
|
303
|
-
async _deployBot(api, argvBotId, argvCreateNew) {
|
|
304
|
-
const outfile = this._paths.abs.outFile;
|
|
305
|
-
const code = await import_fs.default.promises.readFile(outfile, "utf-8");
|
|
306
|
-
const { default: botImpl } = requireutils.requireJsFile(outfile);
|
|
307
|
-
const { tags, states, events, recurringEvents, configuration: botConfiguration } = botImpl;
|
|
308
|
-
let bot;
|
|
309
|
-
if (argvBotId && argvCreateNew) {
|
|
310
|
-
throw new errors.BotpressCLIError("Cannot specify both --botId and --createNew");
|
|
311
|
-
} else if (argvCreateNew) {
|
|
312
|
-
const confirm = await this._confirm("Are you sure you want to create a new bot ?");
|
|
313
|
-
if (!confirm) {
|
|
314
|
-
this._logger.log("Aborted");
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
bot = await this._createNewBot(api);
|
|
318
|
-
} else {
|
|
319
|
-
bot = await this._getExistingBot(api, argvBotId);
|
|
320
|
-
const confirm = await this._confirm(`Are you sure you want to deploy the bot "${bot.name}"?`);
|
|
321
|
-
if (!confirm) {
|
|
322
|
-
this._logger.log("Aborted");
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
const integrations = this._prepareIntegrations(botImpl, bot);
|
|
327
|
-
const line = this._logger.line();
|
|
328
|
-
line.started(`Deploying bot ${import_chalk.default.bold(bot.name)}...`);
|
|
329
|
-
const { bot: updatedBot } = await api.client.updateBot({
|
|
330
|
-
id: bot.id,
|
|
331
|
-
code,
|
|
332
|
-
states,
|
|
333
|
-
recurringEvents,
|
|
334
|
-
configuration: botConfiguration,
|
|
335
|
-
events,
|
|
336
|
-
tags,
|
|
337
|
-
integrations
|
|
338
|
-
}).catch((thrown) => {
|
|
339
|
-
throw errors.BotpressCLIError.wrap(thrown, `Could not update bot "${bot.name}"`);
|
|
340
|
-
});
|
|
341
|
-
line.success("Bot deployed");
|
|
342
|
-
this._displayWebhookUrls(updatedBot);
|
|
343
|
-
}
|
|
344
|
-
async _getExistingBot(api, botId) {
|
|
345
|
-
const promptedBotId = await this._projectCache.sync("botId", botId, async (defaultId) => {
|
|
346
|
-
const userBots = await api.listAllPages(api.client.listBots, (r) => r.bots).catch((thrown) => {
|
|
347
|
-
throw errors.BotpressCLIError.wrap(thrown, "Could not fetch existing bots");
|
|
348
|
-
});
|
|
349
|
-
if (!userBots.length) {
|
|
350
|
-
throw new errors.NoBotsFoundError();
|
|
351
|
-
}
|
|
352
|
-
const initial = userBots.find((bot) => bot.id === defaultId);
|
|
353
|
-
const { prompted } = await (0, import_prompts.default)({
|
|
354
|
-
type: "autocomplete",
|
|
355
|
-
name: "prompted",
|
|
356
|
-
message: "Which bot do you want to deploy?",
|
|
357
|
-
initial: initial?.name,
|
|
358
|
-
choices: userBots.map((bot) => ({ title: bot.name, value: bot.id }))
|
|
359
|
-
});
|
|
360
|
-
if (!prompted) {
|
|
361
|
-
throw new errors.ParamRequiredError("Bot Id");
|
|
362
|
-
}
|
|
363
|
-
return prompted;
|
|
364
|
-
});
|
|
365
|
-
const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {
|
|
366
|
-
throw errors.BotpressCLIError.wrap(thrown, "Could not get bot info");
|
|
367
|
-
});
|
|
368
|
-
return fetchedBot;
|
|
369
|
-
}
|
|
370
|
-
async _createNewBot(api) {
|
|
371
|
-
const line = this._logger.line();
|
|
372
|
-
const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {
|
|
373
|
-
throw errors.BotpressCLIError.wrap(thrown, "Could not create bot");
|
|
374
|
-
});
|
|
375
|
-
line.success(`Bot created with ID "${createdBot.id}" and name "${createdBot.name}"`);
|
|
376
|
-
await this._projectCache.set("botId", createdBot.id);
|
|
377
|
-
return createdBot;
|
|
378
|
-
}
|
|
379
|
-
_prepareIntegrations(botImpl, botInfo) {
|
|
380
|
-
const { integrations: integrationList } = botImpl;
|
|
381
|
-
const integrationsToUninstall = (0, import_lodash.default)(botInfo.integrations).keys().filter((key) => !integrationList?.map((i) => i.id).includes(key)).zipObject().mapValues(() => null).value();
|
|
382
|
-
const integrationsToInstall = (0, import_lodash.default)(integrationList ?? []).keyBy((i) => i.id).mapValues(({ enabled, configuration }) => ({ enabled, configuration })).value();
|
|
383
|
-
return { ...integrationsToUninstall, ...integrationsToInstall };
|
|
384
|
-
}
|
|
385
|
-
_displayWebhookUrls(bot) {
|
|
386
|
-
if (!import_lodash.default.keys(bot.integrations).length) {
|
|
387
|
-
this._logger.log("No integrations in bot");
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
this._logger.log("Integrations:");
|
|
391
|
-
for (const integration of Object.values(bot.integrations)) {
|
|
392
|
-
if (!integration.enabled) {
|
|
393
|
-
this._logger.log(`${import_chalk.default.grey(integration.name)} ${import_chalk.default.italic("(disabled)")}: ${integration.webhookUrl}`, {
|
|
394
|
-
prefix: { symbol: "\u25CB", indent: 2 }
|
|
395
|
-
});
|
|
396
|
-
} else {
|
|
397
|
-
this._logger.log(`${import_chalk.default.bold(integration.name)} : ${integration.webhookUrl}`, {
|
|
398
|
-
prefix: { symbol: "\u25CF", indent: 2 }
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
async _listIntegrationInstances() {
|
|
404
|
-
const installPath = this._paths.abs.installDir;
|
|
405
|
-
if (!import_fs.default.existsSync(installPath)) {
|
|
406
|
-
this._logger.debug("Install path does not exist. Skipping listing of integration instances");
|
|
407
|
-
return [];
|
|
408
|
-
}
|
|
409
|
-
const allFiles = await import_fs.default.promises.readdir(installPath);
|
|
410
|
-
const allPaths = allFiles.map((name) => import_path.default.join(installPath, name));
|
|
411
|
-
const directories = await import_bluebird.default.filter(allPaths, async (path) => {
|
|
412
|
-
const stat = await import_fs.default.promises.stat(path);
|
|
413
|
-
return stat.isDirectory();
|
|
414
|
-
});
|
|
415
|
-
let jsons = directories.map((root) => ({ root, json: import_path.default.join(root, generator.INTEGRATION_JSON) }));
|
|
416
|
-
jsons = jsons.filter(({ json: x }) => import_fs.default.existsSync(x));
|
|
417
|
-
return import_bluebird.default.map(jsons, async ({ root, json }) => {
|
|
418
|
-
const content = await import_fs.default.promises.readFile(json, "utf-8");
|
|
419
|
-
const { name, version, id } = JSON.parse(content);
|
|
420
|
-
const dirname = import_path.default.basename(root);
|
|
421
|
-
return {
|
|
422
|
-
dirname,
|
|
423
|
-
id,
|
|
424
|
-
name,
|
|
425
|
-
version
|
|
426
|
-
};
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
async _uninstallIntegration(instance) {
|
|
430
|
-
const installDir = this._paths.abs.installDir;
|
|
431
|
-
const instancePath = import_path.default.join(installDir, instance.dirname);
|
|
432
|
-
await import_fs.default.promises.rm(instancePath, { recursive: true });
|
|
433
|
-
await this._generateBotIndex();
|
|
434
|
-
}
|
|
435
|
-
async _generateIntegrationInstance(integration) {
|
|
436
|
-
const line = this._logger.line();
|
|
437
|
-
const { name, version } = integration;
|
|
438
|
-
line.started(`Installing ${import_chalk.default.bold(name)} v${version}...`);
|
|
439
|
-
const instanceFiles = await generator.generateIntegrationInstance(
|
|
440
|
-
integration,
|
|
441
|
-
this._paths.relFrom("outDir").installDir
|
|
442
|
-
);
|
|
443
|
-
await this._writeFilesToOutFolder(instanceFiles);
|
|
444
|
-
await this._generateBotIndex();
|
|
445
|
-
line.success(`Installed integration available at ${import_chalk.default.grey(this._paths.rel.outDir)}`);
|
|
446
|
-
}
|
|
447
|
-
async _generateBotIndex() {
|
|
448
|
-
const allInstances = await this._listIntegrationInstances();
|
|
449
|
-
const indexFile = await generator.generateBotIndex(
|
|
450
|
-
this._paths.relFrom("outDir").installDir,
|
|
451
|
-
allInstances.map((i) => i.dirname)
|
|
452
|
-
);
|
|
453
|
-
await this._writeFilesToOutFolder([indexFile]);
|
|
454
|
-
}
|
|
455
|
-
async _writeFilesToOutFolder(files) {
|
|
456
|
-
for (const file of files) {
|
|
457
|
-
const filePath = pathutils.absoluteFrom(this._paths.abs.outDir, file.path);
|
|
458
|
-
const dirPath = import_path.default.dirname(filePath);
|
|
459
|
-
await import_fs.default.promises.mkdir(dirPath, { recursive: true });
|
|
460
|
-
await import_fs.default.promises.writeFile(filePath, file.content);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
async _readIntegrationDefinitionFromFS() {
|
|
464
|
-
const { abs, rel } = this._paths;
|
|
465
|
-
if (!import_fs.default.existsSync(abs.definition)) {
|
|
466
|
-
this._logger.debug(`Integration definition not found at ${rel.definition}`);
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
const { outputFiles } = await esbuildutils.buildEntrypoint({
|
|
470
|
-
cwd: abs.workDir,
|
|
471
|
-
outfile: "",
|
|
472
|
-
entrypoint: rel.definition,
|
|
473
|
-
write: false
|
|
474
|
-
});
|
|
475
|
-
const artifact = outputFiles[0];
|
|
476
|
-
if (!artifact) {
|
|
477
|
-
throw new errors.BotpressCLIError("Could not read integration definition");
|
|
478
|
-
}
|
|
479
|
-
const { default: definition } = requireutils.requireJsCode(artifact.text);
|
|
480
|
-
return definition;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
484
|
-
0 && (module.exports = {
|
|
485
|
-
ProjectCommands
|
|
486
|
-
});
|
package/dist/app/typings.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var typings_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(typings_exports);
|