@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,59 @@
|
|
|
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 command_tree_exports = {};
|
|
20
|
+
__export(command_tree_exports, {
|
|
21
|
+
guards: () => guards,
|
|
22
|
+
zipTree: () => zipTree
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(command_tree_exports);
|
|
25
|
+
const guards = {
|
|
26
|
+
definition: {
|
|
27
|
+
isDef: (x) => "schema" in x,
|
|
28
|
+
isSubTree: (x) => "subcommands" in x
|
|
29
|
+
},
|
|
30
|
+
implementation: {
|
|
31
|
+
isImpl: (x) => typeof x === "function",
|
|
32
|
+
isSubTree: (x) => typeof x === "object"
|
|
33
|
+
},
|
|
34
|
+
command: {
|
|
35
|
+
isLeaf: (x) => "handler" in x,
|
|
36
|
+
isSubTree: (x) => "subcommands" in x
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const zipTree = (defTree, implTree) => {
|
|
40
|
+
const tree = {};
|
|
41
|
+
for (const key in defTree) {
|
|
42
|
+
const def = defTree[key];
|
|
43
|
+
const impl = implTree[key];
|
|
44
|
+
if (guards.definition.isDef(def) && guards.implementation.isImpl(impl)) {
|
|
45
|
+
tree[key] = { ...def, handler: impl };
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (guards.definition.isSubTree(def) && guards.implementation.isSubTree(impl)) {
|
|
49
|
+
tree[key] = { ...def, subcommands: zipTree(def.subcommands, impl.subcommands) };
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return tree;
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
guards,
|
|
58
|
+
zipTree
|
|
59
|
+
});
|
package/dist/config.js
CHANGED
|
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -35,6 +35,7 @@ __export(config_exports, {
|
|
|
35
35
|
devSchema: () => devSchema,
|
|
36
36
|
generateSchema: () => generateSchema,
|
|
37
37
|
globalSchema: () => globalSchema,
|
|
38
|
+
initSchema: () => initSchema,
|
|
38
39
|
integrationRef: () => integrationRef,
|
|
39
40
|
listBotsSchema: () => listBotsSchema,
|
|
40
41
|
listIntegrationsSchema: () => listIntegrationsSchema,
|
|
@@ -120,6 +121,14 @@ const workspaceId = {
|
|
|
120
121
|
type: "string",
|
|
121
122
|
description: "The Workspace Id to deploy to"
|
|
122
123
|
};
|
|
124
|
+
const type = {
|
|
125
|
+
type: "string",
|
|
126
|
+
choices: ["bot", "integration"]
|
|
127
|
+
};
|
|
128
|
+
const name = {
|
|
129
|
+
type: "string",
|
|
130
|
+
description: "The name of the project"
|
|
131
|
+
};
|
|
123
132
|
const botRef = {
|
|
124
133
|
type: "string",
|
|
125
134
|
description: "The bot ID. Bot Name is not supported.",
|
|
@@ -218,6 +227,12 @@ const deleteIntegrationSchema = {
|
|
|
218
227
|
...globalSchema,
|
|
219
228
|
...loggedInSchema
|
|
220
229
|
};
|
|
230
|
+
const initSchema = {
|
|
231
|
+
...globalSchema,
|
|
232
|
+
workDir,
|
|
233
|
+
type,
|
|
234
|
+
name
|
|
235
|
+
};
|
|
221
236
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
237
|
0 && (module.exports = {
|
|
223
238
|
addSchema,
|
|
@@ -231,6 +246,7 @@ const deleteIntegrationSchema = {
|
|
|
231
246
|
devSchema,
|
|
232
247
|
generateSchema,
|
|
233
248
|
globalSchema,
|
|
249
|
+
initSchema,
|
|
234
250
|
integrationRef,
|
|
235
251
|
listBotsSchema,
|
|
236
252
|
listIntegrationsSchema,
|
package/dist/consts.js
CHANGED
|
@@ -29,6 +29,9 @@ __export(consts_exports, {
|
|
|
29
29
|
defaultBotpressHome: () => defaultBotpressHome,
|
|
30
30
|
defaultEntrypoint: () => defaultEntrypoint,
|
|
31
31
|
defaultOutputFolder: () => defaultOutputFolder,
|
|
32
|
+
echoBotName: () => echoBotName,
|
|
33
|
+
emptyIntegrationName: () => emptyIntegrationName,
|
|
34
|
+
fromCliRootDir: () => fromCliRootDir,
|
|
32
35
|
fromHomeDir: () => fromHomeDir,
|
|
33
36
|
fromOutDir: () => fromOutDir,
|
|
34
37
|
fromWorkDir: () => fromWorkDir
|
|
@@ -41,6 +44,13 @@ const defaultOutputFolder = ".botpress";
|
|
|
41
44
|
const defaultEntrypoint = import_path.default.join("src", "index.ts");
|
|
42
45
|
const defaultBotpressApi = "https://api.botpress.cloud";
|
|
43
46
|
const defaultBotpressApp = "https://app.botpress.cloud";
|
|
47
|
+
const echoBotName = "echo-bot";
|
|
48
|
+
const emptyIntegrationName = "empty-integration";
|
|
49
|
+
const fromCliRootDir = {
|
|
50
|
+
packageJson: "package.json",
|
|
51
|
+
echoBotTemplate: import_path.default.join("templates", echoBotName),
|
|
52
|
+
emptyIntegrationTemplate: import_path.default.join("templates", emptyIntegrationName)
|
|
53
|
+
};
|
|
44
54
|
const fromHomeDir = {
|
|
45
55
|
userCacheFile: "user.cache.json"
|
|
46
56
|
};
|
|
@@ -61,6 +71,9 @@ const fromOutDir = {
|
|
|
61
71
|
defaultBotpressHome,
|
|
62
72
|
defaultEntrypoint,
|
|
63
73
|
defaultOutputFolder,
|
|
74
|
+
echoBotName,
|
|
75
|
+
emptyIntegrationName,
|
|
76
|
+
fromCliRootDir,
|
|
64
77
|
fromHomeDir,
|
|
65
78
|
fromOutDir,
|
|
66
79
|
fromWorkDir
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
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 errors_exports = {};
|
|
26
|
+
__export(errors_exports, {
|
|
27
|
+
BotpressCLIError: () => BotpressCLIError,
|
|
28
|
+
ExclusiveBotFeatureError: () => ExclusiveBotFeatureError,
|
|
29
|
+
ExclusiveIntegrationFeatureError: () => ExclusiveIntegrationFeatureError,
|
|
30
|
+
HTTPError: () => HTTPError,
|
|
31
|
+
InvalidIntegrationReferenceError: () => InvalidIntegrationReferenceError,
|
|
32
|
+
NoBotsFoundError: () => NoBotsFoundError,
|
|
33
|
+
NoBundleFoundError: () => NoBundleFoundError,
|
|
34
|
+
NoWorkspacesFoundError: () => NoWorkspacesFoundError,
|
|
35
|
+
NotLoggedInError: () => NotLoggedInError,
|
|
36
|
+
ParamRequiredError: () => ParamRequiredError
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(errors_exports);
|
|
39
|
+
var import_client = require("@botpress/client");
|
|
40
|
+
var import_axios = __toESM(require("axios"));
|
|
41
|
+
var import_verror = require("verror");
|
|
42
|
+
var consts = __toESM(require("./consts"));
|
|
43
|
+
const isKnownApiError = (e) => (0, import_client.isApiError)(e) && !(e instanceof import_client.UnknownError);
|
|
44
|
+
class BotpressCLIError extends import_verror.VError {
|
|
45
|
+
static wrap(thrown, message) {
|
|
46
|
+
const err = BotpressCLIError.map(thrown);
|
|
47
|
+
return new BotpressCLIError(err, message ?? "");
|
|
48
|
+
}
|
|
49
|
+
static map(thrown) {
|
|
50
|
+
if (thrown instanceof import_client.UnknownError) {
|
|
51
|
+
return new HTTPError(500, "An unknown error has occurred.");
|
|
52
|
+
}
|
|
53
|
+
if (isKnownApiError(thrown)) {
|
|
54
|
+
return HTTPError.fromApi(thrown);
|
|
55
|
+
}
|
|
56
|
+
if (import_axios.default.isAxiosError(thrown)) {
|
|
57
|
+
return HTTPError.fromAxios(thrown);
|
|
58
|
+
}
|
|
59
|
+
if (thrown instanceof Error) {
|
|
60
|
+
const { message } = thrown;
|
|
61
|
+
return new BotpressCLIError(message);
|
|
62
|
+
}
|
|
63
|
+
return new BotpressCLIError(`${thrown}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class ExclusiveBotFeatureError extends BotpressCLIError {
|
|
67
|
+
constructor() {
|
|
68
|
+
const message = "This feature is only available for bots. This project is an integration";
|
|
69
|
+
super(message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class ExclusiveIntegrationFeatureError extends BotpressCLIError {
|
|
73
|
+
constructor() {
|
|
74
|
+
const message = "This feature is only available for integration. This project is a bot";
|
|
75
|
+
super(message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class HTTPError extends BotpressCLIError {
|
|
79
|
+
constructor(status, message) {
|
|
80
|
+
super(message);
|
|
81
|
+
this.status = status;
|
|
82
|
+
}
|
|
83
|
+
static fromAxios(e) {
|
|
84
|
+
const message = this._axiosMsg(e);
|
|
85
|
+
return new HTTPError(e.response?.status, message);
|
|
86
|
+
}
|
|
87
|
+
static fromApi(e) {
|
|
88
|
+
const { message, code } = e;
|
|
89
|
+
return new HTTPError(code, message);
|
|
90
|
+
}
|
|
91
|
+
static _axiosMsg(e) {
|
|
92
|
+
let message = e.message;
|
|
93
|
+
if (e.response?.statusText) {
|
|
94
|
+
message += `
|
|
95
|
+
${e.response?.statusText}`;
|
|
96
|
+
}
|
|
97
|
+
if (e.response?.status && e.request?.method && e.request?.path) {
|
|
98
|
+
message += `
|
|
99
|
+
(${e.response?.status}) ${e.request.method} ${e.request.path}`;
|
|
100
|
+
}
|
|
101
|
+
if (e.response?.data?.message) {
|
|
102
|
+
message += `
|
|
103
|
+
${e.response?.data?.message}`;
|
|
104
|
+
}
|
|
105
|
+
return message;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
class NoBundleFoundError extends BotpressCLIError {
|
|
109
|
+
constructor() {
|
|
110
|
+
const message = "No bundle found. Please run `bp bundle` first.";
|
|
111
|
+
super(message);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class NoBotsFoundError extends BotpressCLIError {
|
|
115
|
+
constructor() {
|
|
116
|
+
const message = `No Bot found in your Workspace. Please create one first at ${consts.defaultBotpressApp}.`;
|
|
117
|
+
super(message);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class NoWorkspacesFoundError extends BotpressCLIError {
|
|
121
|
+
constructor() {
|
|
122
|
+
const message = "No Workspace found. Please create one first.";
|
|
123
|
+
super(message);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class NotLoggedInError extends BotpressCLIError {
|
|
127
|
+
constructor() {
|
|
128
|
+
const message = "Not logged in. Please run `bp login` first.";
|
|
129
|
+
super(message);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class ParamRequiredError extends BotpressCLIError {
|
|
133
|
+
constructor(param) {
|
|
134
|
+
const message = `${param} is required.`;
|
|
135
|
+
super(message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
class InvalidIntegrationReferenceError extends BotpressCLIError {
|
|
139
|
+
constructor(ref) {
|
|
140
|
+
const message = `Invalid integration reference "${ref}".`;
|
|
141
|
+
super(message);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
BotpressCLIError,
|
|
147
|
+
ExclusiveBotFeatureError,
|
|
148
|
+
ExclusiveIntegrationFeatureError,
|
|
149
|
+
HTTPError,
|
|
150
|
+
InvalidIntegrationReferenceError,
|
|
151
|
+
NoBotsFoundError,
|
|
152
|
+
NoBundleFoundError,
|
|
153
|
+
NoWorkspacesFoundError,
|
|
154
|
+
NotLoggedInError,
|
|
155
|
+
ParamRequiredError
|
|
156
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -22,12 +22,11 @@ var import_process = require("process");
|
|
|
22
22
|
var app = __toESM(require("./app"));
|
|
23
23
|
var config = __toESM(require("./config"));
|
|
24
24
|
var import_logger = require("./logger");
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const errorLogger = new import_logger.Logger();
|
|
25
|
+
var pathutils = __toESM(require("./path-utils"));
|
|
26
|
+
const CLI_ROOT_DIR = pathutils.join(__dirname, "..");
|
|
28
27
|
const logError = (thrown) => {
|
|
29
28
|
const error = app.errors.BotpressCLIError.map(thrown);
|
|
30
|
-
|
|
29
|
+
new import_logger.Logger().error(error.message);
|
|
31
30
|
};
|
|
32
31
|
const onError = (thrown) => {
|
|
33
32
|
logError(thrown);
|
|
@@ -52,7 +51,7 @@ import_yargs_extra.default.command(
|
|
|
52
51
|
async (argv) => {
|
|
53
52
|
try {
|
|
54
53
|
const parsed = parseArguments(config.loginSchema, argv);
|
|
55
|
-
const commands = await app.forUser({ ...parsed,
|
|
54
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
56
55
|
await commands.login(parsed);
|
|
57
56
|
commands.teardown();
|
|
58
57
|
} catch (e) {
|
|
@@ -66,7 +65,7 @@ import_yargs_extra.default.command(
|
|
|
66
65
|
async (argv) => {
|
|
67
66
|
try {
|
|
68
67
|
const parsed = parseArguments(config.logoutSchema, argv);
|
|
69
|
-
const commands = await app.forUser({ ...parsed,
|
|
68
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
70
69
|
await commands.logout();
|
|
71
70
|
commands.teardown();
|
|
72
71
|
} catch (e) {
|
|
@@ -81,7 +80,7 @@ import_yargs_extra.default.command(
|
|
|
81
80
|
async (argv) => {
|
|
82
81
|
try {
|
|
83
82
|
const parsed = parseArguments(config.createBotSchema, argv);
|
|
84
|
-
const commands = await app.forUser({ ...parsed,
|
|
83
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
85
84
|
await commands.createBot(parsed);
|
|
86
85
|
commands.teardown();
|
|
87
86
|
} catch (e) {
|
|
@@ -95,7 +94,7 @@ import_yargs_extra.default.command(
|
|
|
95
94
|
async (argv) => {
|
|
96
95
|
try {
|
|
97
96
|
const parsed = parseArguments(config.listBotsSchema, argv);
|
|
98
|
-
const commands = await app.forUser({ ...parsed,
|
|
97
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
99
98
|
await commands.listBots(parsed);
|
|
100
99
|
commands.teardown();
|
|
101
100
|
} catch (e) {
|
|
@@ -109,7 +108,7 @@ import_yargs_extra.default.command(
|
|
|
109
108
|
async (argv) => {
|
|
110
109
|
try {
|
|
111
110
|
const parsed = parseArguments(config.readBotSchema, argv);
|
|
112
|
-
const commands = await app.forUser({ ...parsed,
|
|
111
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
113
112
|
await commands.getBot(argv.botRef, parsed);
|
|
114
113
|
commands.teardown();
|
|
115
114
|
} catch (e) {
|
|
@@ -123,7 +122,7 @@ import_yargs_extra.default.command(
|
|
|
123
122
|
async (argv) => {
|
|
124
123
|
try {
|
|
125
124
|
const parsed = parseArguments(config.deleteBotSchema, argv);
|
|
126
|
-
const commands = await app.forUser({ ...parsed,
|
|
125
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
127
126
|
await commands.deleteBot(argv.botRef, parsed);
|
|
128
127
|
commands.teardown();
|
|
129
128
|
} catch (e) {
|
|
@@ -139,7 +138,7 @@ import_yargs_extra.default.command(
|
|
|
139
138
|
async (argv) => {
|
|
140
139
|
try {
|
|
141
140
|
const parsed = parseArguments(config.listIntegrationsSchema, argv);
|
|
142
|
-
const commands = await app.forUser({ ...parsed,
|
|
141
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
143
142
|
await commands.listIntegrations(parsed);
|
|
144
143
|
commands.teardown();
|
|
145
144
|
} catch (e) {
|
|
@@ -153,7 +152,7 @@ import_yargs_extra.default.command(
|
|
|
153
152
|
async (argv) => {
|
|
154
153
|
try {
|
|
155
154
|
const parsed = parseArguments(config.readIntegrationSchema, argv);
|
|
156
|
-
const commands = await app.forUser({ ...parsed,
|
|
155
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
157
156
|
await commands.getIntegration(argv.integrationRef, parsed);
|
|
158
157
|
commands.teardown();
|
|
159
158
|
} catch (e) {
|
|
@@ -167,7 +166,7 @@ import_yargs_extra.default.command(
|
|
|
167
166
|
async (argv) => {
|
|
168
167
|
try {
|
|
169
168
|
const parsed = parseArguments(config.readIntegrationSchema, argv);
|
|
170
|
-
const commands = await app.forUser({ ...parsed,
|
|
169
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
171
170
|
await commands.deleteIntegration(argv.integrationRef, parsed);
|
|
172
171
|
commands.teardown();
|
|
173
172
|
} catch (e) {
|
|
@@ -176,13 +175,27 @@ import_yargs_extra.default.command(
|
|
|
176
175
|
}
|
|
177
176
|
);
|
|
178
177
|
}).command(
|
|
178
|
+
"init",
|
|
179
|
+
"Initialize a new project",
|
|
180
|
+
() => import_yargs_extra.default.options(config.initSchema),
|
|
181
|
+
async (argv) => {
|
|
182
|
+
try {
|
|
183
|
+
const parsed = parseArguments(config.initSchema, argv);
|
|
184
|
+
const commands = await app.forUser({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
185
|
+
await commands.initProject(parsed);
|
|
186
|
+
commands.teardown();
|
|
187
|
+
} catch (e) {
|
|
188
|
+
onError(e);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
).command(
|
|
179
192
|
"bundle",
|
|
180
193
|
"Bundle a botpress project",
|
|
181
194
|
() => import_yargs_extra.default.options(config.bundleSchema),
|
|
182
195
|
async (argv) => {
|
|
183
196
|
try {
|
|
184
197
|
const parsed = parseArguments(config.bundleSchema, argv);
|
|
185
|
-
const commands = await app.forProject({ ...parsed,
|
|
198
|
+
const commands = await app.forProject({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
186
199
|
await commands.bundleProject(parsed);
|
|
187
200
|
commands.teardown();
|
|
188
201
|
} catch (e) {
|
|
@@ -196,7 +209,7 @@ import_yargs_extra.default.command(
|
|
|
196
209
|
async (argv) => {
|
|
197
210
|
try {
|
|
198
211
|
const parsed = parseArguments(config.generateSchema, argv);
|
|
199
|
-
const commands = await app.forProject({ ...parsed,
|
|
212
|
+
const commands = await app.forProject({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
200
213
|
await commands.generateTypings(parsed);
|
|
201
214
|
commands.teardown();
|
|
202
215
|
} catch (e) {
|
|
@@ -210,7 +223,7 @@ import_yargs_extra.default.command(
|
|
|
210
223
|
async (argv) => {
|
|
211
224
|
try {
|
|
212
225
|
const parsed = parseArguments(config.buildSchema, argv);
|
|
213
|
-
const commands = await app.forProject({ ...parsed,
|
|
226
|
+
const commands = await app.forProject({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
214
227
|
await commands.buildProject(parsed);
|
|
215
228
|
commands.teardown();
|
|
216
229
|
} catch (e) {
|
|
@@ -224,7 +237,7 @@ import_yargs_extra.default.command(
|
|
|
224
237
|
async (argv) => {
|
|
225
238
|
try {
|
|
226
239
|
const parsed = parseArguments(config.serveSchema, argv);
|
|
227
|
-
const commands = await app.forProject({ ...parsed,
|
|
240
|
+
const commands = await app.forProject({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
228
241
|
await commands.serveProject(parsed);
|
|
229
242
|
commands.teardown();
|
|
230
243
|
} catch (e) {
|
|
@@ -238,7 +251,7 @@ import_yargs_extra.default.command(
|
|
|
238
251
|
async (argv) => {
|
|
239
252
|
try {
|
|
240
253
|
const parsed = parseArguments(config.deploySchema, argv);
|
|
241
|
-
const commands = await app.forProject({ ...parsed,
|
|
254
|
+
const commands = await app.forProject({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
242
255
|
await commands.deployProject(parsed);
|
|
243
256
|
commands.teardown();
|
|
244
257
|
} catch (e) {
|
|
@@ -252,7 +265,7 @@ import_yargs_extra.default.command(
|
|
|
252
265
|
async (argv) => {
|
|
253
266
|
try {
|
|
254
267
|
const parsed = parseArguments(config.devSchema, argv);
|
|
255
|
-
const commands = await app.forProject({ ...parsed,
|
|
268
|
+
const commands = await app.forProject({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
256
269
|
await commands.devProject(parsed);
|
|
257
270
|
commands.teardown();
|
|
258
271
|
} catch (e) {
|
|
@@ -266,7 +279,7 @@ import_yargs_extra.default.command(
|
|
|
266
279
|
async (argv) => {
|
|
267
280
|
try {
|
|
268
281
|
const parsed = parseArguments(config.addSchema, argv);
|
|
269
|
-
const commands = await app.forProject({ ...parsed,
|
|
282
|
+
const commands = await app.forProject({ ...parsed, cliRootPath: CLI_ROOT_DIR });
|
|
270
283
|
await commands.installIntegration(argv.integrationRef, parsed);
|
|
271
284
|
commands.teardown();
|
|
272
285
|
} catch (e) {
|
|
@@ -0,0 +1,61 @@
|
|
|
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 integration_ref_exports = {};
|
|
26
|
+
__export(integration_ref_exports, {
|
|
27
|
+
formatIntegrationRef: () => formatIntegrationRef,
|
|
28
|
+
parseIntegrationRef: () => parseIntegrationRef
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(integration_ref_exports);
|
|
31
|
+
var import_semver = __toESM(require("semver"));
|
|
32
|
+
var uuid = __toESM(require("uuid"));
|
|
33
|
+
const LATEST_TAG = "latest";
|
|
34
|
+
const formatIntegrationRef = (ref) => {
|
|
35
|
+
if (ref.type === "id") {
|
|
36
|
+
return ref.id;
|
|
37
|
+
}
|
|
38
|
+
return `${ref.name}@${ref.version}`;
|
|
39
|
+
};
|
|
40
|
+
const parseIntegrationRef = (ref) => {
|
|
41
|
+
if (uuid.validate(ref)) {
|
|
42
|
+
return { type: "id", id: ref };
|
|
43
|
+
}
|
|
44
|
+
if (!ref.includes("@")) {
|
|
45
|
+
return { type: "name", name: ref, version: LATEST_TAG };
|
|
46
|
+
}
|
|
47
|
+
const [name, version] = ref.split("@");
|
|
48
|
+
if (!name || !version) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const cleanedVersion = version === LATEST_TAG ? version : import_semver.default.clean(version);
|
|
52
|
+
if (!cleanedVersion) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
return { type: "name", name, version: cleanedVersion };
|
|
56
|
+
};
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
formatIntegrationRef,
|
|
60
|
+
parseIntegrationRef
|
|
61
|
+
});
|
package/dist/path-utils.js
CHANGED
|
@@ -28,6 +28,7 @@ __export(path_utils_exports, {
|
|
|
28
28
|
cwd: () => cwd,
|
|
29
29
|
isAbsolute: () => isAbsolute,
|
|
30
30
|
isPath: () => isPath,
|
|
31
|
+
join: () => join,
|
|
31
32
|
relativeFrom: () => relativeFrom,
|
|
32
33
|
rmExtension: () => rmExtension,
|
|
33
34
|
toUnix: () => toUnix
|
|
@@ -37,6 +38,10 @@ var import_path = __toESM(require("path"));
|
|
|
37
38
|
const cwd = () => process.cwd();
|
|
38
39
|
const isAbsolute = (path) => import_path.default.isAbsolute(path);
|
|
39
40
|
const isPath = (path) => isAbsolute(path) || path.startsWith(".");
|
|
41
|
+
const join = (abs, ...paths) => {
|
|
42
|
+
const joined = import_path.default.join(abs, ...paths);
|
|
43
|
+
return import_path.default.normalize(joined);
|
|
44
|
+
};
|
|
40
45
|
const rmExtension = (filename) => filename.replace(/\.[^/.]+$/, "");
|
|
41
46
|
const toUnix = (path) => path.split(import_path.default.sep).join(import_path.default.posix.sep);
|
|
42
47
|
const absoluteFrom = (rootdir, target) => {
|
|
@@ -60,6 +65,7 @@ const relativeFrom = (rootdir, target) => {
|
|
|
60
65
|
cwd,
|
|
61
66
|
isAbsolute,
|
|
62
67
|
isPath,
|
|
68
|
+
join,
|
|
63
69
|
relativeFrom,
|
|
64
70
|
rmExtension,
|
|
65
71
|
toUnix
|
|
@@ -0,0 +1,85 @@
|
|
|
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 register_yargs_exports = {};
|
|
26
|
+
__export(register_yargs_exports, {
|
|
27
|
+
registerYargs: () => registerYargs
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(register_yargs_exports);
|
|
30
|
+
var import_yargs_extra = require("@bpinternal/yargs-extra");
|
|
31
|
+
var import_lodash = __toESM(require("lodash"));
|
|
32
|
+
var tree = __toESM(require("./command-tree"));
|
|
33
|
+
const parseArguments = (schema, argv) => {
|
|
34
|
+
const yargsEnv = (0, import_yargs_extra.parseEnv)(schema, "BP");
|
|
35
|
+
return (0, import_yargs_extra.cleanupConfig)(schema, { ...argv, ...yargsEnv });
|
|
36
|
+
};
|
|
37
|
+
const registerYargs = (yargz, commands, props) => {
|
|
38
|
+
for (const cmdName in commands) {
|
|
39
|
+
const command = commands[cmdName];
|
|
40
|
+
if (tree.guards.command.isSubTree(command)) {
|
|
41
|
+
yargz.command(cmdName, command.description ?? cmdName, (y) => {
|
|
42
|
+
registerYargs(y, command.subcommands, props);
|
|
43
|
+
return y;
|
|
44
|
+
});
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const { schema, description, alias } = command;
|
|
48
|
+
const aliases = alias ? [cmdName, alias] : [cmdName];
|
|
49
|
+
const options = Object.entries(schema);
|
|
50
|
+
let positionals = options.filter(
|
|
51
|
+
(value) => !!value[1].positional
|
|
52
|
+
);
|
|
53
|
+
let usage = aliases;
|
|
54
|
+
if (positionals.length) {
|
|
55
|
+
positionals = import_lodash.default.sortBy(positionals, ([, option]) => option.idx);
|
|
56
|
+
const positionalArgs = positionals.map(
|
|
57
|
+
([optName, option]) => option.demandOption ? `<${optName}>` : `[${optName}]`
|
|
58
|
+
);
|
|
59
|
+
const positionalStr = positionalArgs.join(" ");
|
|
60
|
+
usage = aliases.map((optAlias) => `${optAlias} ${positionalStr}`);
|
|
61
|
+
}
|
|
62
|
+
yargz.command(
|
|
63
|
+
usage,
|
|
64
|
+
description ?? cmdName,
|
|
65
|
+
(y) => {
|
|
66
|
+
for (const [key, option] of Object.entries(schema)) {
|
|
67
|
+
if (option.positional) {
|
|
68
|
+
y = y.positional(key, option);
|
|
69
|
+
} else {
|
|
70
|
+
y = y.option(key, option);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return y;
|
|
74
|
+
},
|
|
75
|
+
async (argv) => {
|
|
76
|
+
const parsed = parseArguments(schema, argv);
|
|
77
|
+
await command.handler({ ...parsed, ...props });
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
registerYargs
|
|
85
|
+
});
|
package/dist/typings.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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);
|