@botpress/cli 0.0.4 → 0.0.7
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/app/api-utils.js +5 -4
- package/dist/app/base.js +39 -1
- package/dist/app/errors.js +22 -19
- package/dist/app/file-paths.js +82 -0
- package/dist/app/generator/module.js +1 -1
- package/dist/app/index.js +17 -10
- package/dist/app/project.js +198 -240
- package/dist/app/user.js +5 -16
- package/dist/config.js +8 -3
- package/dist/consts.js +65 -0
- package/dist/esbuild-utils.js +89 -0
- package/dist/event-emitter.js +62 -0
- package/dist/index.js +19 -18
- package/dist/logger/base-logger.js +14 -0
- package/dist/logger/index.js +5 -5
- package/dist/path-utils.js +69 -0
- package/dist/require-utils.js +49 -0
- package/dist/update-notif.js +47 -0
- package/dist/watcher.js +68 -0
- package/dist/worker/child-entrypoint.js +4 -2
- package/dist/worker/child-wrapper.js +109 -0
- package/dist/worker/keyboard.js +48 -0
- package/dist/worker/messaging.js +39 -0
- package/dist/worker/worker-state.js +70 -0
- package/dist/worker/worker.js +87 -0
- package/package.json +4 -2
- package/readme.md +0 -1
- package/dist/index.js.map +0 -7
- package/dist/init.js.map +0 -7
|
@@ -0,0 +1,109 @@
|
|
|
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 child_wrapper_exports = {};
|
|
26
|
+
__export(child_wrapper_exports, {
|
|
27
|
+
ChildProcessWrapper: () => ChildProcessWrapper
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(child_wrapper_exports);
|
|
30
|
+
var childProcess = __toESM(require("child_process"));
|
|
31
|
+
var import_child_entrypoint = require("./child-entrypoint");
|
|
32
|
+
var import_config = require("./config");
|
|
33
|
+
var import_is_child = require("./is-child");
|
|
34
|
+
const listenForChildSpawn = (child, logger) => new Promise((resolve, reject) => {
|
|
35
|
+
child.on("spawn", () => {
|
|
36
|
+
logger.debug(`Child process spawned with pid ${child.pid}`);
|
|
37
|
+
resolve();
|
|
38
|
+
});
|
|
39
|
+
child.on("error", (err) => {
|
|
40
|
+
logger.debug(`Child process error: ${err.message}`);
|
|
41
|
+
reject(err);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const listenForChildExit = (child, logger) => new Promise((resolve, reject) => {
|
|
45
|
+
child.on("disconnect", () => {
|
|
46
|
+
logger.debug("Child process disconnected");
|
|
47
|
+
});
|
|
48
|
+
child.on("close", (exitCode, signal) => {
|
|
49
|
+
logger.debug(`Child process closed with code ${exitCode} and signal ${signal}`);
|
|
50
|
+
});
|
|
51
|
+
child.on("exit", (exitCode, signal) => {
|
|
52
|
+
logger.debug(`Child process exited with code ${exitCode} and signal ${signal}`);
|
|
53
|
+
resolve({ exitCode, signal });
|
|
54
|
+
});
|
|
55
|
+
child.on("error", (err) => {
|
|
56
|
+
logger.debug(`Child process error: ${err.message}`);
|
|
57
|
+
reject(err);
|
|
58
|
+
});
|
|
59
|
+
child.on("message", (message) => {
|
|
60
|
+
logger.debug(`Child process message: ${message}`);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
class ChildProcessWrapper {
|
|
64
|
+
constructor(_child, _exitPromise) {
|
|
65
|
+
this._child = _child;
|
|
66
|
+
this._exitPromise = _exitPromise;
|
|
67
|
+
}
|
|
68
|
+
static async spawn(config, logger) {
|
|
69
|
+
if (import_is_child.isChildProcess) {
|
|
70
|
+
throw new Error("Cannot spawn child process from child process");
|
|
71
|
+
}
|
|
72
|
+
const child = childProcess.fork(import_child_entrypoint.ENTRY_POINT, [], {
|
|
73
|
+
stdio: "inherit",
|
|
74
|
+
env: {
|
|
75
|
+
[import_is_child.CHILD_ENV_KEY]: import_is_child.CHILD_ENV_VALUE,
|
|
76
|
+
[import_config.CONFIG_ENV_KEY]: JSON.stringify(config),
|
|
77
|
+
...config.env
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const childSpawnPromise = listenForChildSpawn(child, logger);
|
|
81
|
+
const childExitPromise = listenForChildExit(child, logger);
|
|
82
|
+
const instance = new ChildProcessWrapper(child, childExitPromise);
|
|
83
|
+
childExitPromise.finally(() => {
|
|
84
|
+
instance._exited = true;
|
|
85
|
+
});
|
|
86
|
+
await childSpawnPromise;
|
|
87
|
+
return instance;
|
|
88
|
+
}
|
|
89
|
+
_exited = false;
|
|
90
|
+
async kill() {
|
|
91
|
+
if (this._exited) {
|
|
92
|
+
throw new Error("Child process already exited and cannot be killed");
|
|
93
|
+
}
|
|
94
|
+
this._child.kill();
|
|
95
|
+
const res = await this._exitPromise;
|
|
96
|
+
return res;
|
|
97
|
+
}
|
|
98
|
+
async listen() {
|
|
99
|
+
if (this._exited) {
|
|
100
|
+
throw new Error("Child process already exited and cannot be listened on");
|
|
101
|
+
}
|
|
102
|
+
const res = await this._exitPromise;
|
|
103
|
+
return res;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
ChildProcessWrapper
|
|
109
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
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 keyboard_exports = {};
|
|
26
|
+
__export(keyboard_exports, {
|
|
27
|
+
listenForKeypress: () => listenForKeypress
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(keyboard_exports);
|
|
30
|
+
var import_readline = __toESM(require("readline"));
|
|
31
|
+
const listenForKeypress = (handler) => {
|
|
32
|
+
import_readline.default.emitKeypressEvents(process.stdin);
|
|
33
|
+
const wrapper = (_str, key) => {
|
|
34
|
+
handler(key);
|
|
35
|
+
};
|
|
36
|
+
process.stdin.on("keypress", wrapper);
|
|
37
|
+
if (process.stdin.isTTY) {
|
|
38
|
+
process.stdin.setRawMode(true);
|
|
39
|
+
}
|
|
40
|
+
process.stdin.resume();
|
|
41
|
+
return () => {
|
|
42
|
+
process.stdin.off("keypress", wrapper);
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
listenForKeypress
|
|
48
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
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 messaging_exports = {};
|
|
20
|
+
__export(messaging_exports, {
|
|
21
|
+
exitCodes: () => exitCodes,
|
|
22
|
+
messages: () => messages
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(messaging_exports);
|
|
25
|
+
const exitCodes = {
|
|
26
|
+
success: 0,
|
|
27
|
+
restart: 69,
|
|
28
|
+
keyboard: 42,
|
|
29
|
+
terminate: 66
|
|
30
|
+
};
|
|
31
|
+
const messages = {
|
|
32
|
+
restart: "__restart__",
|
|
33
|
+
terminate: "__terminate__"
|
|
34
|
+
};
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
exitCodes,
|
|
38
|
+
messages
|
|
39
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
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 worker_state_exports = {};
|
|
20
|
+
__export(worker_state_exports, {
|
|
21
|
+
WorkerStateObserver: () => WorkerStateObserver
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(worker_state_exports);
|
|
24
|
+
class WorkerStateObserver {
|
|
25
|
+
_state;
|
|
26
|
+
_handlers = {
|
|
27
|
+
dead: [],
|
|
28
|
+
reloading: [],
|
|
29
|
+
live: [],
|
|
30
|
+
killing: [],
|
|
31
|
+
errored: []
|
|
32
|
+
};
|
|
33
|
+
constructor(initialState) {
|
|
34
|
+
this._state = initialState;
|
|
35
|
+
}
|
|
36
|
+
waitFor(status) {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
const cb = () => {
|
|
39
|
+
this.off(status, cb);
|
|
40
|
+
resolve();
|
|
41
|
+
};
|
|
42
|
+
this.on(status, cb);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
on(status, handler) {
|
|
46
|
+
this._handlers[status].push(handler);
|
|
47
|
+
if (this._state.status === status) {
|
|
48
|
+
handler(this._state);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
off(status, handler) {
|
|
52
|
+
const index = this._handlers[status].indexOf(handler);
|
|
53
|
+
this._handlers[status].splice(index, 1);
|
|
54
|
+
}
|
|
55
|
+
get() {
|
|
56
|
+
return this._state;
|
|
57
|
+
}
|
|
58
|
+
set(newState) {
|
|
59
|
+
this._state = newState;
|
|
60
|
+
const { status } = newState;
|
|
61
|
+
for (const handler of this._handlers[status]) {
|
|
62
|
+
const fn = handler;
|
|
63
|
+
fn(newState);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
WorkerStateObserver
|
|
70
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
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 worker_exports = {};
|
|
20
|
+
__export(worker_exports, {
|
|
21
|
+
Worker: () => Worker
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(worker_exports);
|
|
24
|
+
var import_child_wrapper = require("./child-wrapper");
|
|
25
|
+
var import_worker_state = require("./worker-state");
|
|
26
|
+
class Worker {
|
|
27
|
+
constructor(_config, _logger, _props = {}) {
|
|
28
|
+
this._config = _config;
|
|
29
|
+
this._logger = _logger;
|
|
30
|
+
this._props = _props;
|
|
31
|
+
}
|
|
32
|
+
static async spawn(config, logger, props) {
|
|
33
|
+
const instance = new Worker(config, logger, props);
|
|
34
|
+
await instance.reload();
|
|
35
|
+
return instance;
|
|
36
|
+
}
|
|
37
|
+
_state = new import_worker_state.WorkerStateObserver({ status: "dead", murdered: false });
|
|
38
|
+
get running() {
|
|
39
|
+
return this._state.get().status === "live";
|
|
40
|
+
}
|
|
41
|
+
kill = () => {
|
|
42
|
+
const state = this._state.get();
|
|
43
|
+
if (state.status !== "live") {
|
|
44
|
+
throw new Error("Cannot kill a child process that is not alive");
|
|
45
|
+
}
|
|
46
|
+
this._state.set({ status: "killing" });
|
|
47
|
+
return state.child.kill();
|
|
48
|
+
};
|
|
49
|
+
reload = async () => {
|
|
50
|
+
if (this._state.get().status === "reloading") {
|
|
51
|
+
this._logger.debug("Already reloading");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const previousState = this._state.get();
|
|
55
|
+
this._state.set({ status: "reloading" });
|
|
56
|
+
if (previousState.status === "live") {
|
|
57
|
+
await previousState.child.kill();
|
|
58
|
+
}
|
|
59
|
+
const child = await import_child_wrapper.ChildProcessWrapper.spawn(this._config, this._logger);
|
|
60
|
+
this._state.set({ status: "live", child });
|
|
61
|
+
void child.listen().catch((thrown) => {
|
|
62
|
+
this._state.set({ status: "errored", thrown });
|
|
63
|
+
}).then(() => {
|
|
64
|
+
const { status } = this._state.get();
|
|
65
|
+
if (status === "reloading") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this._state.set({ status: "dead", murdered: status === "killing" });
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
wait = () => new Promise((resolve, reject) => {
|
|
72
|
+
this._state.on("dead", (state) => {
|
|
73
|
+
if (state.murdered || !this._props.hangOnExit) {
|
|
74
|
+
resolve();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this._logger.debug("Child process died of natural causes...");
|
|
78
|
+
});
|
|
79
|
+
this._state.on("errored", (state) => {
|
|
80
|
+
reject(state.thrown);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
Worker
|
|
87
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Botpress CLI",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "pnpm run type-check && pnpm run bundle",
|
|
@@ -24,10 +24,12 @@
|
|
|
24
24
|
"@types/verror": "^1.10.6",
|
|
25
25
|
"axios": "^1.2.5",
|
|
26
26
|
"bluebird": "^3.7.2",
|
|
27
|
+
"boxen": "5.1.2",
|
|
27
28
|
"chalk": "^4.1.2",
|
|
28
29
|
"chokidar": "^3.5.3",
|
|
29
30
|
"esbuild": "^0.15.18",
|
|
30
31
|
"json-schema-to-typescript": "^11.0.2",
|
|
32
|
+
"latest-version": "5.1.0",
|
|
31
33
|
"lodash": "^4.17.21",
|
|
32
34
|
"prompts": "^2.4.2",
|
|
33
35
|
"radash": "^9.5.0",
|
|
@@ -40,7 +42,7 @@
|
|
|
40
42
|
"zod-to-json-schema": "^3.20.1"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@botpress/sdk": "0.0.
|
|
45
|
+
"@botpress/sdk": "0.0.7",
|
|
44
46
|
"@types/bluebird": "^3.5.38",
|
|
45
47
|
"@types/prompts": "^2.0.14",
|
|
46
48
|
"@types/semver": "^7.3.11",
|