@botpress/cli 0.0.11 → 0.0.13
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/code-generation/integration-impl.js +3 -6
- package/dist/command-implementations/init-command.js +26 -11
- package/dist/consts.js +8 -8
- package/dist/utils/prompt-utils.js +9 -0
- package/dist/utils/string-utils.js +26 -7
- package/package.json +1 -1
- package/templates/echo-bot/package.json +3 -3
- package/templates/empty-integration/.botpress/implementation/index.ts +3 -3
- package/templates/empty-integration/integration.definition.ts +3 -3
- package/templates/empty-integration/package.json +3 -3
- package/templates/empty-integration/src/index.ts +13 -3
- package/templates/echo-bot/readme.md +0 -5
- package/templates/empty-integration/readme.md +0 -5
|
@@ -28,7 +28,6 @@ __export(integration_impl_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(integration_impl_exports);
|
|
30
30
|
var import_bluebird = __toESM(require("bluebird"));
|
|
31
|
-
var import_utils = require("../utils");
|
|
32
31
|
var import_action = require("./action");
|
|
33
32
|
var import_channel = require("./channel");
|
|
34
33
|
var import_configuration = require("./configuration");
|
|
@@ -74,7 +73,7 @@ class IntegrationImplementationIndexModule extends import_module.Module {
|
|
|
74
73
|
get content() {
|
|
75
74
|
let content = import_const.GENERATED_HEADER;
|
|
76
75
|
const { configModule, actionsModule, channelsModule, eventsModule } = this;
|
|
77
|
-
content += 'import
|
|
76
|
+
content += 'import * as sdk from "@botpress/sdk";\n\n';
|
|
78
77
|
const configImport = configModule.import(this);
|
|
79
78
|
const actionsImport = actionsModule.import(this);
|
|
80
79
|
const channelsImport = channelsModule.import(this);
|
|
@@ -96,10 +95,8 @@ class IntegrationImplementationIndexModule extends import_module.Module {
|
|
|
96
95
|
content += `export * as ${eventsModule.name} from "./${eventsImport}";
|
|
97
96
|
`;
|
|
98
97
|
content += "\n";
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
content += `export class Integration${className}
|
|
102
|
-
extends Integration<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}> {}
|
|
98
|
+
content += `export class Integration
|
|
99
|
+
extends sdk.Integration<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}> {}
|
|
103
100
|
`;
|
|
104
101
|
return content;
|
|
105
102
|
}
|
|
@@ -46,26 +46,41 @@ class InitCommand extends import_global_command.GlobalCommand {
|
|
|
46
46
|
}
|
|
47
47
|
projectType = promptedType;
|
|
48
48
|
}
|
|
49
|
+
let name = this.argv.name;
|
|
50
|
+
if (!name) {
|
|
51
|
+
const defaultName = projectType === "bot" ? consts.echoBotDirName : consts.emptyIntegrationDirName;
|
|
52
|
+
const promptMessage = `What is the name of your ${projectType}?`;
|
|
53
|
+
const promptedName = await this.prompt.text(promptMessage, { initial: defaultName });
|
|
54
|
+
if (!promptedName) {
|
|
55
|
+
throw new errors.ParamRequiredError("Project Name");
|
|
56
|
+
}
|
|
57
|
+
name = promptedName;
|
|
58
|
+
}
|
|
49
59
|
const workDir = utils.path.absoluteFrom(utils.path.cwd(), this.argv.workDir);
|
|
50
60
|
if (projectType === "bot") {
|
|
51
|
-
|
|
52
|
-
const exist2 = await this._checkIfDestinationExists(destination2);
|
|
53
|
-
if (exist2) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
await fs.promises.cp(this.globalPaths.abs.echoBotTemplate, destination2, { recursive: true });
|
|
61
|
+
await this._copy({ srcDir: this.globalPaths.abs.echoBotTemplate, destDir: workDir, name });
|
|
57
62
|
this.logger.success(`Bot project initialized in ${import_chalk.default.bold(workDir)}`);
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
60
|
-
|
|
65
|
+
await this._copy({ srcDir: this.globalPaths.abs.emptyIntegrationTemplate, destDir: workDir, name });
|
|
66
|
+
this.logger.success(`Integration project initialized in ${import_chalk.default.bold(this.argv.workDir)}`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
_copy = async (props) => {
|
|
70
|
+
const { srcDir, destDir, name } = props;
|
|
71
|
+
const destination = pathlib.join(destDir, props.name);
|
|
61
72
|
const exist = await this._checkIfDestinationExists(destination);
|
|
62
73
|
if (exist) {
|
|
63
74
|
return;
|
|
64
75
|
}
|
|
65
|
-
await fs.promises.cp(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
await fs.promises.cp(srcDir, destination, { recursive: true });
|
|
77
|
+
const pkgJsonPath = pathlib.join(destination, "package.json");
|
|
78
|
+
const strContent = await fs.promises.readFile(pkgJsonPath, "utf-8");
|
|
79
|
+
const { name: _, ...json } = JSON.parse(strContent);
|
|
80
|
+
const pkgJsonName = utils.strings.snakeCase(name);
|
|
81
|
+
const updatedJson = { name: pkgJsonName, ...json };
|
|
82
|
+
await fs.promises.writeFile(pkgJsonPath, JSON.stringify(updatedJson, null, 2));
|
|
83
|
+
};
|
|
69
84
|
_checkIfDestinationExists = async (destination) => {
|
|
70
85
|
if (fs.existsSync(destination)) {
|
|
71
86
|
const override = await this.prompt.confirm(
|
package/dist/consts.js
CHANGED
|
@@ -29,8 +29,8 @@ __export(consts_exports, {
|
|
|
29
29
|
defaultBotpressHome: () => defaultBotpressHome,
|
|
30
30
|
defaultEntrypoint: () => defaultEntrypoint,
|
|
31
31
|
defaultOutputFolder: () => defaultOutputFolder,
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
echoBotDirName: () => echoBotDirName,
|
|
33
|
+
emptyIntegrationDirName: () => emptyIntegrationDirName,
|
|
34
34
|
fromCliRootDir: () => fromCliRootDir,
|
|
35
35
|
fromHomeDir: () => fromHomeDir,
|
|
36
36
|
fromOutDir: () => fromOutDir,
|
|
@@ -44,12 +44,12 @@ const defaultOutputFolder = ".botpress";
|
|
|
44
44
|
const defaultEntrypoint = import_path.default.join("src", "index.ts");
|
|
45
45
|
const defaultBotpressApi = "https://api.botpress.cloud";
|
|
46
46
|
const defaultBotpressApp = "https://app.botpress.cloud";
|
|
47
|
-
const
|
|
48
|
-
const
|
|
47
|
+
const echoBotDirName = "echo-bot";
|
|
48
|
+
const emptyIntegrationDirName = "empty-integration";
|
|
49
49
|
const fromCliRootDir = {
|
|
50
50
|
packageJson: "package.json",
|
|
51
|
-
echoBotTemplate: import_path.default.join("templates",
|
|
52
|
-
emptyIntegrationTemplate: import_path.default.join("templates",
|
|
51
|
+
echoBotTemplate: import_path.default.join("templates", echoBotDirName),
|
|
52
|
+
emptyIntegrationTemplate: import_path.default.join("templates", emptyIntegrationDirName)
|
|
53
53
|
};
|
|
54
54
|
const fromHomeDir = {
|
|
55
55
|
globalCacheFile: "global.cache.json"
|
|
@@ -71,8 +71,8 @@ const fromOutDir = {
|
|
|
71
71
|
defaultBotpressHome,
|
|
72
72
|
defaultEntrypoint,
|
|
73
73
|
defaultOutputFolder,
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
echoBotDirName,
|
|
75
|
+
emptyIntegrationDirName,
|
|
76
76
|
fromCliRootDir,
|
|
77
77
|
fromHomeDir,
|
|
78
78
|
fromOutDir,
|
|
@@ -68,6 +68,15 @@ class CLIPrompt {
|
|
|
68
68
|
});
|
|
69
69
|
return prompted ? prompted : void 0;
|
|
70
70
|
}
|
|
71
|
+
async text(message, opts) {
|
|
72
|
+
const { prompted } = await (0, import_prompts.default)({
|
|
73
|
+
type: "text",
|
|
74
|
+
name: "prompted",
|
|
75
|
+
message,
|
|
76
|
+
initial: opts?.initial
|
|
77
|
+
});
|
|
78
|
+
return prompted ? prompted : void 0;
|
|
79
|
+
}
|
|
71
80
|
}
|
|
72
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
73
82
|
0 && (module.exports = {
|
|
@@ -18,21 +18,40 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var string_utils_exports = {};
|
|
20
20
|
__export(string_utils_exports, {
|
|
21
|
+
camelCase: () => camelCase,
|
|
21
22
|
kebabCase: () => kebabCase,
|
|
22
|
-
pascalCase: () => pascalCase
|
|
23
|
+
pascalCase: () => pascalCase,
|
|
24
|
+
snakeCase: () => snakeCase
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(string_utils_exports);
|
|
25
|
-
const capitalizeFirstLetter = (
|
|
26
|
-
const
|
|
27
|
-
|
|
27
|
+
const capitalizeFirstLetter = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
28
|
+
const splitHyphens = (tokens) => tokens.flatMap((token) => token.split("-"));
|
|
29
|
+
const splitUnderscores = (tokens) => tokens.flatMap((token) => token.split("_"));
|
|
30
|
+
const splitCaseChange = (tokens) => tokens.flatMap((token) => token.split(/(?<=[a-z])(?=[A-Z])/));
|
|
31
|
+
const split = (tokens) => {
|
|
32
|
+
const steps = [splitHyphens, splitUnderscores, splitCaseChange];
|
|
33
|
+
return steps.reduce((acc, step) => step(acc), tokens);
|
|
34
|
+
};
|
|
35
|
+
const pascalCase = (text) => {
|
|
36
|
+
const words = split([text]);
|
|
28
37
|
return words.map(capitalizeFirstLetter).join("");
|
|
29
38
|
};
|
|
30
|
-
const kebabCase = (
|
|
31
|
-
const words =
|
|
39
|
+
const kebabCase = (text) => {
|
|
40
|
+
const words = split([text]);
|
|
32
41
|
return words.map((word) => word.toLowerCase()).join("-");
|
|
33
42
|
};
|
|
43
|
+
const snakeCase = (text) => {
|
|
44
|
+
const words = split([text]);
|
|
45
|
+
return words.map((word) => word.toLowerCase()).join("_");
|
|
46
|
+
};
|
|
47
|
+
const camelCase = (text) => {
|
|
48
|
+
const [first, ...words] = split([text]);
|
|
49
|
+
return [first.toLowerCase(), ...words.map(capitalizeFirstLetter)].join("");
|
|
50
|
+
};
|
|
34
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
52
|
0 && (module.exports = {
|
|
53
|
+
camelCase,
|
|
36
54
|
kebabCase,
|
|
37
|
-
pascalCase
|
|
55
|
+
pascalCase,
|
|
56
|
+
snakeCase
|
|
38
57
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "echo-bot",
|
|
3
3
|
"version": "0.1.0",
|
|
4
|
-
"description": "Bot that answers with the received message",
|
|
5
4
|
"scripts": {
|
|
6
5
|
"type-check": "tsc --noEmit"
|
|
7
6
|
},
|
|
@@ -17,6 +16,7 @@
|
|
|
17
16
|
"devDependencies": {
|
|
18
17
|
"@types/node": "^18.11.17",
|
|
19
18
|
"ts-node": "^10.9.1",
|
|
20
|
-
"typescript": "^4.9.4"
|
|
19
|
+
"typescript": "^4.9.4",
|
|
20
|
+
"@tsconfig/node18-strictest": "^1.0.0"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// This file is generated
|
|
3
3
|
// Do not edit this file
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as sdk from "@botpress/sdk";
|
|
6
6
|
|
|
7
7
|
import type * as configuration from "./configuration";
|
|
8
8
|
import type * as actions from "./actions/index";
|
|
@@ -13,5 +13,5 @@ export * as actions from "./actions/index";
|
|
|
13
13
|
export * as channels from "./channels/index";
|
|
14
14
|
export * as events from "./events/index";
|
|
15
15
|
|
|
16
|
-
export class
|
|
17
|
-
extends Integration<configuration.Configuration, actions.Actions, channels.Channels, events.Events> {}
|
|
16
|
+
export class Integration
|
|
17
|
+
extends sdk.Integration<configuration.Configuration, actions.Actions, channels.Channels, events.Events> {}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IntegrationDefinition, messages } from '@botpress/sdk'
|
|
2
|
-
import { version } from './package.json'
|
|
2
|
+
import { version, name } from './package.json'
|
|
3
3
|
|
|
4
4
|
export default new IntegrationDefinition({
|
|
5
|
-
name
|
|
5
|
+
name,
|
|
6
6
|
version,
|
|
7
|
-
public:
|
|
7
|
+
public: false,
|
|
8
8
|
channels: {
|
|
9
9
|
channel: {
|
|
10
10
|
messages: { ...messages.defaults },
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "empty-integration",
|
|
3
3
|
"version": "0.1.0",
|
|
4
|
-
"description": "Integration with no content",
|
|
5
4
|
"scripts": {
|
|
6
5
|
"type-check": "tsc --noEmit"
|
|
7
6
|
},
|
|
@@ -17,6 +16,7 @@
|
|
|
17
16
|
"devDependencies": {
|
|
18
17
|
"@types/node": "^18.11.17",
|
|
19
18
|
"ts-node": "^10.9.1",
|
|
20
|
-
"typescript": "^4.9.4"
|
|
19
|
+
"typescript": "^4.9.4",
|
|
20
|
+
"@tsconfig/node18-strictest": "^1.0.0"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -9,9 +9,19 @@ class NotImplementedError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default new botpress.
|
|
13
|
-
register: async () => {
|
|
14
|
-
|
|
12
|
+
export default new botpress.Integration({
|
|
13
|
+
register: async () => {
|
|
14
|
+
/**
|
|
15
|
+
* This is called when a bot installs the integration.
|
|
16
|
+
* You should use this handler to instanciate ressources in the external service and ensure that the configuration is valid.
|
|
17
|
+
*/
|
|
18
|
+
},
|
|
19
|
+
unregister: async () => {
|
|
20
|
+
/**
|
|
21
|
+
* This is called when a bot removes the integration.
|
|
22
|
+
* You should use this handler to instanciate ressources in the external service and ensure that the configuration is valid.
|
|
23
|
+
*/
|
|
24
|
+
},
|
|
15
25
|
actions: {},
|
|
16
26
|
channels: {
|
|
17
27
|
channel: {
|