@botpress/cli 0.0.7 → 0.0.9

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.
@@ -0,0 +1,38 @@
1
+ import fs from 'fs'
2
+ import pathlib from 'path'
3
+ import { Octokit } from 'octokit'
4
+ import { Logger } from '../src/logger'
5
+ import { GithubFetcher } from '../src/github-fetch'
6
+
7
+ const maybeExit = (exit: boolean) => {
8
+ if (exit) {
9
+ process.exit(0)
10
+ }
11
+ }
12
+
13
+ const SSH_URI = 'ssh://github.com/botpress/openbook-cli.git'
14
+ const GIT_SSH_URI = 'git@github.com:botpress/openbook-cli.git'
15
+ const HTTPS_URI = 'https://github.com/botpress/openbook-cli.git'
16
+ const HTTPS_GITHUB_URI = 'https://github.com/botpress/skynet/tree/master'
17
+
18
+ const githubAuth = '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'
19
+
20
+ const main = async () => {
21
+ const logger = new Logger({ verbose: true })
22
+ const parsedUri = new GithubFetcher(logger)._parseUri(HTTPS_GITHUB_URI)
23
+
24
+ const octokit = new Octokit({ auth: githubAuth })
25
+
26
+ const { data: content } = await octokit.rest.repos.getContent({ ...parsedUri })
27
+
28
+ logger.json(content)
29
+ // const {
30
+ // data: { content: blob },
31
+ // } = await octokit.rest.git.getBlob({
32
+ // ...parsedUri,
33
+ // file_sha: content,
34
+ // })
35
+
36
+ maybeExit(true)
37
+ }
38
+ void main()
@@ -33,47 +33,42 @@ var consts = __toESM(require("../consts"));
33
33
  var pathutils = __toESM(require("../path-utils"));
34
34
  class ProjectPaths {
35
35
  abs;
36
- rel;
37
- constructor({ workDir, definition, entryPoint: entrypoint, outDir }) {
38
- const absWorkdir = pathutils.absoluteFrom(pathutils.cwd(), workDir);
39
- const absDefinition = pathutils.absoluteFrom(absWorkdir, definition);
40
- const absEntrypoint = pathutils.absoluteFrom(absWorkdir, entrypoint);
41
- const absOutdir = pathutils.absoluteFrom(absWorkdir, outDir);
36
+ constructor({ workDir, entryPoint, outDir }) {
37
+ const absWorkDir = pathutils.absoluteFrom(pathutils.cwd(), workDir);
38
+ const absEntrypoint = pathutils.absoluteFrom(absWorkDir, entryPoint);
39
+ const absOutDir = pathutils.absoluteFrom(absWorkDir, outDir);
42
40
  this.abs = {
43
- workDir: absWorkdir,
44
- definition: absDefinition,
41
+ workDir: absWorkDir,
45
42
  entryPoint: absEntrypoint,
46
- outDir: absOutdir,
47
- ...import_lodash.default.mapValues(consts.relativeToOutFolder, (p) => pathutils.absoluteFrom(absOutdir, p))
48
- };
49
- const relDefinition = pathutils.relativeFrom(this.abs.workDir, this.abs.definition);
50
- const relEntrypoint = pathutils.relativeFrom(this.abs.workDir, this.abs.entryPoint);
51
- const relOutdir = pathutils.relativeFrom(this.abs.workDir, this.abs.outDir);
52
- const relWorkdir = ".";
53
- this.rel = {
54
- workDir: relWorkdir,
55
- definition: relDefinition,
56
- entryPoint: relEntrypoint,
57
- outDir: relOutdir,
58
- ...import_lodash.default.mapValues(consts.relativeToOutFolder, (p) => pathutils.relativeFrom(this.abs.outDir, p))
43
+ outDir: absOutDir,
44
+ ...import_lodash.default.mapValues(consts.fromOutDir, (p) => pathutils.absoluteFrom(absOutDir, p)),
45
+ ...import_lodash.default.mapValues(consts.fromWorkDir, (p) => pathutils.absoluteFrom(absWorkDir, p))
59
46
  };
60
47
  }
48
+ get rel() {
49
+ return this.relFrom("workDir");
50
+ }
51
+ relFrom(dir) {
52
+ const from = this.abs[dir];
53
+ return import_lodash.default.mapValues(this.abs, (to) => pathutils.relativeFrom(from, to));
54
+ }
61
55
  }
62
56
  class UserPaths {
63
57
  abs;
64
- rel;
65
- constructor({ botpressHome }) {
66
- const absBotpressHome = pathutils.absoluteFrom(pathutils.cwd(), botpressHome);
58
+ constructor({ botpressHomeDir }) {
59
+ const absBotpressHome = pathutils.absoluteFrom(pathutils.cwd(), botpressHomeDir);
67
60
  this.abs = {
68
- botpressHome: absBotpressHome,
69
- ...import_lodash.default.mapValues(consts.relativeToHomeFolder, (p) => pathutils.absoluteFrom(absBotpressHome, p))
70
- };
71
- const relBotpressHome = ".";
72
- this.rel = {
73
- botpressHome: relBotpressHome,
74
- ...import_lodash.default.mapValues(consts.relativeToHomeFolder, (p) => pathutils.relativeFrom(this.abs.botpressHome, p))
61
+ botpressHomeDir: absBotpressHome,
62
+ ...import_lodash.default.mapValues(consts.fromHomeDir, (p) => pathutils.absoluteFrom(absBotpressHome, p))
75
63
  };
76
64
  }
65
+ get rel() {
66
+ return this.relFrom("botpressHomeDir");
67
+ }
68
+ relFrom(dir) {
69
+ const from = this.abs[dir];
70
+ return import_lodash.default.mapValues(this.abs, (to) => pathutils.relativeFrom(from, to));
71
+ }
77
72
  }
78
73
  // Annotate the CommonJS export names for ESM import in node:
79
74
  0 && (module.exports = {
package/dist/app/index.js CHANGED
@@ -50,10 +50,11 @@ const logBootInfo = async (logger, props) => {
50
50
  const forProject = async (props) => {
51
51
  const logger = new import_logger.Logger(props);
52
52
  await logBootInfo(logger, props);
53
- const projectPaths = new import_file_paths.ProjectPaths(props);
53
+ const { workDir, entryPoint, outDir, botpressHome } = props;
54
+ const projectPaths = new import_file_paths.ProjectPaths({ workDir, entryPoint, outDir });
54
55
  const projectCachePath = projectPaths.abs.projectCacheFile;
55
56
  const projectCache = await import_cache.FSConfigCache.loadFrom(projectCachePath);
56
- const userPaths = new import_file_paths.UserPaths(props);
57
+ const userPaths = new import_file_paths.UserPaths({ botpressHomeDir: botpressHome });
57
58
  const userCacheFile = userPaths.abs.userCacheFile;
58
59
  const userCache = await import_cache.FSConfigCache.loadFrom(userCacheFile);
59
60
  await import_fs.default.promises.mkdir(projectPaths.abs.distDir, { recursive: true });
@@ -62,7 +63,8 @@ const forProject = async (props) => {
62
63
  const forUser = async (props) => {
63
64
  const logger = new import_logger.Logger(props);
64
65
  await logBootInfo(logger, props);
65
- const userPaths = new import_file_paths.UserPaths(props);
66
+ const { botpressHome } = props;
67
+ const userPaths = new import_file_paths.UserPaths({ botpressHomeDir: botpressHome });
66
68
  const userCacheFile = userPaths.abs.userCacheFile;
67
69
  const userCache = await import_cache.FSConfigCache.loadFrom(userCacheFile);
68
70
  return new import_user.UserCommands(props, userCache, logger);
@@ -37,6 +37,7 @@ var consts = __toESM(require("../consts"));
37
37
  var esbuildutils = __toESM(require("../esbuild-utils"));
38
38
  var pathutils = __toESM(require("../path-utils"));
39
39
  var requireutils = __toESM(require("../require-utils"));
40
+ var import_watcher = require("../watcher");
40
41
  var import_worker = require("../worker");
41
42
  var import_base = require("./base");
42
43
  var errors = __toESM(require("./errors"));
@@ -125,9 +126,9 @@ class ProjectCommands extends import_base.BaseCommands {
125
126
  line.started(`Generating typings for integration ${import_chalk.default.bold(name)}...`);
126
127
  const typingFiles = await generator.generateIntegrationImplementationTypings(
127
128
  integrationDef,
128
- consts.relativeToOutFolder.implementationDir
129
+ this._paths.relFrom("outDir").implementationDir
129
130
  );
130
- const indexFile = await generator.generateIntegrationIndex(consts.relativeToOutFolder.implementationDir);
131
+ const indexFile = await generator.generateIntegrationIndex(this._paths.relFrom("outDir").implementationDir);
131
132
  const generatedFiles = [...typingFiles, indexFile];
132
133
  await this._writeFilesToOutFolder(generatedFiles);
133
134
  line.success(`Typings available at ${import_chalk.default.grey(this._paths.rel.outDir)}`);
@@ -162,7 +163,7 @@ class ProjectCommands extends import_base.BaseCommands {
162
163
  const importPath = pathutils.toUnix(outfile);
163
164
  const requireFrom = pathutils.rmExtension(importPath);
164
165
  const code = `require('${requireFrom}').default.start(${argv.port})`;
165
- await (0, import_worker.spawnChildProcess)(
166
+ const worker = await import_worker.Worker.spawn(
166
167
  {
167
168
  type: "code",
168
169
  code,
@@ -172,7 +173,32 @@ class ProjectCommands extends import_base.BaseCommands {
172
173
  }
173
174
  },
174
175
  this._logger
175
- );
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
+ }
176
202
  }
177
203
  async _deployDevIntegration(api, externalUrl, integrationDef) {
178
204
  const devId = await this._projectCache.get("devId");
@@ -412,7 +438,7 @@ class ProjectCommands extends import_base.BaseCommands {
412
438
  line.started(`Installing ${import_chalk.default.bold(name)} v${version}...`);
413
439
  const instanceFiles = await generator.generateIntegrationInstance(
414
440
  integration,
415
- consts.relativeToOutFolder.installDir
441
+ this._paths.relFrom("outDir").installDir
416
442
  );
417
443
  await this._writeFilesToOutFolder(instanceFiles);
418
444
  await this._generateBotIndex();
@@ -421,7 +447,7 @@ class ProjectCommands extends import_base.BaseCommands {
421
447
  async _generateBotIndex() {
422
448
  const allInstances = await this._listIntegrationInstances();
423
449
  const indexFile = await generator.generateBotIndex(
424
- consts.relativeToOutFolder.installDir,
450
+ this._paths.relFrom("outDir").installDir,
425
451
  allInstances.map((i) => i.dirname)
426
452
  );
427
453
  await this._writeFilesToOutFolder([indexFile]);
package/dist/config.js CHANGED
@@ -80,11 +80,6 @@ const entryPoint = {
80
80
  description: "The entry point of the project",
81
81
  default: consts.defaultEntrypoint
82
82
  };
83
- const definition = {
84
- type: "string",
85
- description: "The integration definition file to use. If file not found, the project is treated as a bot",
86
- default: consts.defaultIntegrationConfigScript
87
- };
88
83
  const outDir = {
89
84
  type: "string",
90
85
  description: "The output directory",
@@ -144,7 +139,6 @@ const globalSchema = {
144
139
  const projectSchema = {
145
140
  ...globalSchema,
146
141
  entryPoint,
147
- definition,
148
142
  outDir,
149
143
  workDir
150
144
  };
package/dist/consts.js CHANGED
@@ -28,10 +28,10 @@ __export(consts_exports, {
28
28
  defaultBotpressApp: () => defaultBotpressApp,
29
29
  defaultBotpressHome: () => defaultBotpressHome,
30
30
  defaultEntrypoint: () => defaultEntrypoint,
31
- defaultIntegrationConfigScript: () => defaultIntegrationConfigScript,
32
31
  defaultOutputFolder: () => defaultOutputFolder,
33
- relativeToHomeFolder: () => relativeToHomeFolder,
34
- relativeToOutFolder: () => relativeToOutFolder
32
+ fromHomeDir: () => fromHomeDir,
33
+ fromOutDir: () => fromOutDir,
34
+ fromWorkDir: () => fromWorkDir
35
35
  });
36
36
  module.exports = __toCommonJS(consts_exports);
37
37
  var import_os = __toESM(require("os"));
@@ -39,13 +39,15 @@ var import_path = __toESM(require("path"));
39
39
  const defaultBotpressHome = import_path.default.join(import_os.default.homedir(), ".botpress");
40
40
  const defaultOutputFolder = ".botpress";
41
41
  const defaultEntrypoint = import_path.default.join("src", "index.ts");
42
- const defaultIntegrationConfigScript = "integration.definition.ts";
43
42
  const defaultBotpressApi = "https://api.botpress.cloud";
44
43
  const defaultBotpressApp = "https://app.botpress.cloud";
45
- const relativeToHomeFolder = {
44
+ const fromHomeDir = {
46
45
  userCacheFile: "user.cache.json"
47
46
  };
48
- const relativeToOutFolder = {
47
+ const fromWorkDir = {
48
+ definition: "integration.definition.ts"
49
+ };
50
+ const fromOutDir = {
49
51
  distDir: "dist",
50
52
  outFile: import_path.default.join("dist", "index.js"),
51
53
  installDir: "installations",
@@ -58,8 +60,8 @@ const relativeToOutFolder = {
58
60
  defaultBotpressApp,
59
61
  defaultBotpressHome,
60
62
  defaultEntrypoint,
61
- defaultIntegrationConfigScript,
62
63
  defaultOutputFolder,
63
- relativeToHomeFolder,
64
- relativeToOutFolder
64
+ fromHomeDir,
65
+ fromOutDir,
66
+ fromWorkDir
65
67
  });
@@ -0,0 +1,159 @@
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 github_download_exports = {};
26
+ __export(github_download_exports, {
27
+ GithubDownloader: () => GithubDownloader
28
+ });
29
+ module.exports = __toCommonJS(github_download_exports);
30
+ var import_fs = __toESM(require("fs"));
31
+ var import_git_url_parse = __toESM(require("git-url-parse"));
32
+ var import_octokit = require("octokit");
33
+ var import_path = __toESM(require("path"));
34
+ const GITHUB_HOST = "github.com";
35
+ const DEFAULT_REF = "HEAD";
36
+ const GIT_URI = /^(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/;
37
+ const GITHUB_TREE_URI = /^^https:\/\/(.*?)(\.com)\/.*$/;
38
+ class GithubDownloader {
39
+ constructor(_logger) {
40
+ this._logger = _logger;
41
+ }
42
+ async listFiles(props) {
43
+ const parsedUri = this._parseUri(props.srcUri);
44
+ const { path: _, ...repoUri } = parsedUri;
45
+ const octo = new import_octokit.Octokit({ auth: props.githubAuth });
46
+ const files = await this._listFiles({
47
+ octo,
48
+ srcUri: parsedUri,
49
+ recursive: props.recursive
50
+ });
51
+ return files.map((f) => ({
52
+ uri: this._formatUri({ ...repoUri, path: f.path }),
53
+ name: f.name,
54
+ type: f.type
55
+ }));
56
+ }
57
+ async downloadFiles(props) {
58
+ const { destDir, srcUri } = props;
59
+ const dirExists = import_fs.default.existsSync(destDir);
60
+ if (dirExists) {
61
+ throw new Error(`Directory ${destDir} already exists`);
62
+ }
63
+ const parsedUri = this._parseUri(srcUri);
64
+ const octo = new import_octokit.Octokit({ auth: props.githubAuth });
65
+ await this._downloadFiles({
66
+ octo,
67
+ srcUri: parsedUri,
68
+ destDir,
69
+ allowedExtensions: props.allowedExtensions
70
+ });
71
+ }
72
+ async _downloadFiles(props) {
73
+ const { octo, srcUri, destDir, allowedExtensions } = props;
74
+ const files = await this._listFiles(props);
75
+ this._logger.debug(`Downloading ${files.length} files from ${srcUri.path} to ${destDir}`);
76
+ await import_fs.default.promises.mkdir(destDir);
77
+ for (const file of files) {
78
+ if (file.type === "dir") {
79
+ const subDir = import_path.default.join(destDir, file.name);
80
+ await this._downloadFiles({
81
+ octo,
82
+ srcUri: { ...srcUri, path: [srcUri.path, file.name].join("/") },
83
+ destDir: subDir
84
+ });
85
+ continue;
86
+ }
87
+ const fileExt = import_path.default.extname(file.name);
88
+ if (allowedExtensions && !allowedExtensions.includes(fileExt)) {
89
+ this._logger.debug(`Skipping file ${file.name} because it is not an allowed file type`);
90
+ continue;
91
+ }
92
+ const { data: blob } = await octo.rest.git.getBlob({
93
+ ...srcUri,
94
+ file_sha: file.sha
95
+ });
96
+ const filePath = import_path.default.join(destDir, file.name);
97
+ const content = Buffer.from(blob.content, "base64");
98
+ await import_fs.default.promises.writeFile(filePath, content);
99
+ }
100
+ }
101
+ async _listFiles(props) {
102
+ const { octo, srcUri, recursive } = props;
103
+ const { data } = await octo.rest.repos.getContent({
104
+ ...srcUri
105
+ });
106
+ let allFiles;
107
+ if (!Array.isArray(data)) {
108
+ allFiles = [data];
109
+ } else {
110
+ allFiles = data;
111
+ }
112
+ let supportedFiles = allFiles.filter((f) => f.type === "dir" || f.type === "file");
113
+ if (!recursive) {
114
+ return supportedFiles;
115
+ }
116
+ for (const dir of allFiles.filter((f) => f.type === "dir")) {
117
+ const subFiles = await this._listFiles({
118
+ ...props,
119
+ srcUri: {
120
+ ...srcUri,
121
+ path: [srcUri.path, dir.name].join("/")
122
+ }
123
+ });
124
+ supportedFiles = [...supportedFiles, ...subFiles];
125
+ }
126
+ return supportedFiles;
127
+ }
128
+ _formatUri(uri) {
129
+ if (uri.protocol === "ssh") {
130
+ return `git@${GITHUB_HOST}:${uri.owner}/${uri.repo}.git`;
131
+ }
132
+ return `https://${GITHUB_HOST}/${uri.owner}/${uri.repo}/tree/${uri.ref}/${uri.path}`;
133
+ }
134
+ _parseUri(uri) {
135
+ const isGit = this._isGitUri(uri);
136
+ if (!isGit) {
137
+ throw new Error("URI is not a valid git repository URI");
138
+ }
139
+ const parsed = (0, import_git_url_parse.default)(uri);
140
+ if (parsed.resource !== GITHUB_HOST) {
141
+ throw new Error(`Unsupported git host: ${parsed.resource}`);
142
+ }
143
+ if (parsed.protocol !== "ssh" && parsed.protocol !== "https") {
144
+ throw new Error(`Unsupported git protocol: ${parsed.protocol}}`);
145
+ }
146
+ return {
147
+ protocol: parsed.protocol,
148
+ owner: parsed.owner,
149
+ repo: parsed.name,
150
+ ref: parsed.ref ? parsed.ref : DEFAULT_REF,
151
+ path: parsed.filepath
152
+ };
153
+ }
154
+ _isGitUri = (uri) => GITHUB_TREE_URI.test(uri) || GIT_URI.test(uri);
155
+ }
156
+ // Annotate the CommonJS export names for ESM import in node:
157
+ 0 && (module.exports = {
158
+ GithubDownloader
159
+ });
@@ -0,0 +1,173 @@
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 github_fetch_exports = {};
26
+ __export(github_fetch_exports, {
27
+ GithubFetchError: () => GithubFetchError,
28
+ GithubFetcher: () => GithubFetcher
29
+ });
30
+ module.exports = __toCommonJS(github_fetch_exports);
31
+ var import_git_url_parse = __toESM(require("git-url-parse"));
32
+ var import_octokit = require("octokit");
33
+ var import_path = __toESM(require("path"));
34
+ class GithubFetchError extends Error {
35
+ }
36
+ const GITHUB_HOST = "github.com";
37
+ const DEFAULT_REF = "HEAD";
38
+ const GIT_URI = /^(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/;
39
+ const GITHUB_TREE_URI = /^https:\/\/(.*?)(\.com)\/.*$/;
40
+ class GithubFetcher {
41
+ constructor(_logger) {
42
+ this._logger = _logger;
43
+ }
44
+ async listFiles(props) {
45
+ const { uri, auth, recursive, pattern } = props;
46
+ if (pattern?.global) {
47
+ throw new GithubFetchError("Pattern must not be global");
48
+ }
49
+ const parsedUri = this._parseUri(uri);
50
+ const octo = new import_octokit.Octokit({ auth });
51
+ const dir = await this._browseTree({
52
+ octo,
53
+ uri: parsedUri,
54
+ recursive: recursive ?? false,
55
+ pattern,
56
+ leafMap: async (entry) => {
57
+ const entryUri = { ...parsedUri, path: entry.path };
58
+ return {
59
+ type: "file",
60
+ uri: this._formatUri(entryUri),
61
+ name: import_path.default.basename(entry.path),
62
+ content: null
63
+ };
64
+ }
65
+ });
66
+ return dir;
67
+ }
68
+ async fetchFiles(props) {
69
+ const { uri, auth, recursive, pattern } = props;
70
+ if (pattern?.global) {
71
+ throw new GithubFetchError("Pattern must not be global");
72
+ }
73
+ const parsedUri = this._parseUri(uri);
74
+ const octo = new import_octokit.Octokit({ auth });
75
+ const dir = await this._browseTree({
76
+ octo,
77
+ uri: parsedUri,
78
+ recursive: recursive ?? false,
79
+ pattern,
80
+ leafMap: async (entry) => {
81
+ const entryUri = { ...parsedUri, path: entry.path };
82
+ const {
83
+ data: { content: blob }
84
+ } = await octo.rest.git.getBlob({ ...entryUri, file_sha: entry.sha });
85
+ return {
86
+ type: "file",
87
+ uri: this._formatUri({ ...parsedUri, path: entry.path }),
88
+ name: import_path.default.basename(entry.path),
89
+ content: Buffer.from(blob, "base64").toString("utf8")
90
+ };
91
+ }
92
+ });
93
+ return dir;
94
+ }
95
+ async _browseTree(props) {
96
+ const { octo, uri, recursive, leafMap, pattern } = props;
97
+ const { data } = await octo.rest.repos.getContent({
98
+ ...uri
99
+ });
100
+ if (!Array.isArray(data)) {
101
+ const formattedUri = this._formatUri(uri);
102
+ throw new GithubFetchError(`URI ${formattedUri} is not a directory. Cannot list or fetch a single file.`);
103
+ }
104
+ const allTopLevelEntries = data;
105
+ const supportedEntries = allTopLevelEntries.filter(this._isSupported);
106
+ const dir = {
107
+ type: "dir",
108
+ uri: this._formatUri(uri),
109
+ name: import_path.default.basename(uri.path)
110
+ };
111
+ const content = [];
112
+ for (const entry of supportedEntries) {
113
+ const entryUri = { ...uri, path: entry.path };
114
+ if (entry.type === "file") {
115
+ if (pattern && !pattern.test(entry.path)) {
116
+ this._logger.debug(`Skipping ${entry.path} because it does not match pattern ${pattern}`);
117
+ } else {
118
+ const leaf = await leafMap(entry);
119
+ content.push(leaf);
120
+ }
121
+ continue;
122
+ }
123
+ if (!recursive) {
124
+ content.push({
125
+ type: "dir",
126
+ uri: this._formatUri(entryUri),
127
+ name: entry.name,
128
+ content: []
129
+ });
130
+ continue;
131
+ }
132
+ const subDirEntry = await this._browseTree({ octo, uri: entryUri, recursive, leafMap });
133
+ content.push(subDirEntry);
134
+ }
135
+ return {
136
+ ...dir,
137
+ content
138
+ };
139
+ }
140
+ _formatUri(uri) {
141
+ if (uri.protocol === "ssh") {
142
+ return `git@${GITHUB_HOST}:${uri.owner}/${uri.repo}.git`;
143
+ }
144
+ return `https://${GITHUB_HOST}/${uri.owner}/${uri.repo}/tree/${uri.ref}/${uri.path}`;
145
+ }
146
+ _parseUri(uri) {
147
+ const isGit = this._isGitUri(uri);
148
+ if (!isGit) {
149
+ throw new Error("URI is not a valid git repository URI");
150
+ }
151
+ const parsed = (0, import_git_url_parse.default)(uri);
152
+ if (parsed.resource !== GITHUB_HOST) {
153
+ throw new Error(`Unsupported git host: ${parsed.resource}`);
154
+ }
155
+ if (parsed.protocol !== "ssh" && parsed.protocol !== "https") {
156
+ throw new Error(`Unsupported git protocol: ${parsed.protocol}}`);
157
+ }
158
+ return {
159
+ protocol: parsed.protocol,
160
+ owner: parsed.owner,
161
+ repo: parsed.name,
162
+ ref: parsed.ref ? parsed.ref : DEFAULT_REF,
163
+ path: parsed.filepath
164
+ };
165
+ }
166
+ _isGitUri = (uri) => GITHUB_TREE_URI.test(uri) || GIT_URI.test(uri);
167
+ _isSupported = (file) => file.type === "dir" || file.type === "file";
168
+ }
169
+ // Annotate the CommonJS export names for ESM import in node:
170
+ 0 && (module.exports = {
171
+ GithubFetchError,
172
+ GithubFetcher
173
+ });
@@ -52,10 +52,7 @@ const relativeFrom = (rootdir, target) => {
52
52
  } else {
53
53
  absPath = import_path.default.resolve(import_path.default.join(rootdir, target));
54
54
  }
55
- if (!absPath.startsWith(rootdir)) {
56
- return target;
57
- }
58
- return absPath.slice(rootdir.length + 1);
55
+ return import_path.default.relative(rootdir, absPath);
59
56
  };
60
57
  // Annotate the CommonJS export names for ESM import in node:
61
58
  0 && (module.exports = {
@@ -27,31 +27,21 @@ __export(child_entrypoint_exports, {
27
27
  ENTRY_POINT: () => ENTRY_POINT
28
28
  });
29
29
  module.exports = __toCommonJS(child_entrypoint_exports);
30
- var import_readline = __toESM(require("readline"));
31
30
  var requireutils = __toESM(require("../require-utils"));
32
31
  var import_config = require("./config");
33
32
  var import_is_child = require("./is-child");
34
33
  const ENTRY_POINT = __filename;
35
34
  const childProcessEntrypoint = async (_props) => {
36
- const config = (0, import_config.getConfigFromEnv)();
37
- import_readline.default.emitKeypressEvents(process.stdin);
38
- process.stdin.on("keypress", (_, key) => {
39
- if (key && key.ctrl && key.name === "c") {
40
- process.exit(0);
41
- }
42
- if (key && key.name === "escape") {
43
- process.exit(0);
44
- }
45
- });
46
- if (process.stdin.isTTY) {
47
- process.stdin.setRawMode(true);
35
+ const rawConfig = process.env[import_config.CONFIG_ENV_KEY];
36
+ if (!rawConfig) {
37
+ throw new Error(`Config variable ${import_config.CONFIG_ENV_KEY} was not set`);
48
38
  }
49
- process.stdin.resume();
39
+ const config = import_config.configSchema.parse(JSON.parse(rawConfig));
50
40
  if (config.type === "code") {
51
- await requireutils.requireJsCode(config.code);
41
+ requireutils.requireJsCode(config.code);
52
42
  }
53
43
  if (config.type === "file") {
54
- await requireutils.requireJsFile(config.file);
44
+ requireutils.requireJsFile(config.file);
55
45
  }
56
46
  };
57
47
  if (import_is_child.processProps.type === "child") {
@@ -25,8 +25,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
25
25
  var config_exports = {};
26
26
  __export(config_exports, {
27
27
  CONFIG_ENV_KEY: () => CONFIG_ENV_KEY,
28
- configSchema: () => configSchema,
29
- getConfigFromEnv: () => getConfigFromEnv
28
+ configSchema: () => configSchema
30
29
  });
31
30
  module.exports = __toCommonJS(config_exports);
32
31
  var import_zod = __toESM(require("zod"));
@@ -43,16 +42,8 @@ const configSchema = import_zod.default.union([
43
42
  env: import_zod.default.record(import_zod.default.string(), import_zod.default.string()).optional()
44
43
  })
45
44
  ]);
46
- const getConfigFromEnv = () => {
47
- const config = process.env[CONFIG_ENV_KEY];
48
- if (!config) {
49
- throw new Error(`Config variable ${CONFIG_ENV_KEY} was not set`);
50
- }
51
- return configSchema.parse(JSON.parse(config));
52
- };
53
45
  // Annotate the CommonJS export names for ESM import in node:
54
46
  0 && (module.exports = {
55
47
  CONFIG_ENV_KEY,
56
- configSchema,
57
- getConfigFromEnv
48
+ configSchema
58
49
  });
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,39 +15,17 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
19
  var worker_exports = {};
26
20
  __export(worker_exports, {
27
- Config: () => import_config2.Config,
28
- spawnChildProcess: () => spawnChildProcess
21
+ Config: () => import_config.Config,
22
+ Worker: () => import_worker.Worker
29
23
  });
30
24
  module.exports = __toCommonJS(worker_exports);
31
- var childProcess = __toESM(require("child_process"));
32
- var import_child_entrypoint = require("./child-entrypoint");
33
25
  var import_config = require("./config");
34
- var import_is_child = require("./is-child");
35
- var import_listen_child = require("./listen-child");
36
- var import_config2 = require("./config");
37
- const spawnChildProcess = async (config, logger) => {
38
- if (import_is_child.isChildProcess) {
39
- throw new Error("Cannot spawn child process from child process");
40
- }
41
- const child = childProcess.fork(import_child_entrypoint.ENTRY_POINT, [], {
42
- stdio: "inherit",
43
- env: {
44
- [import_is_child.CHILD_ENV_KEY]: import_is_child.CHILD_ENV_VALUE,
45
- [import_config.CONFIG_ENV_KEY]: JSON.stringify(config),
46
- ...config.env
47
- }
48
- });
49
- return (0, import_listen_child.listenChild)(child, logger);
50
- };
26
+ var import_worker = require("./worker");
51
27
  // Annotate the CommonJS export names for ESM import in node:
52
28
  0 && (module.exports = {
53
29
  Config,
54
- spawnChildProcess
30
+ Worker
55
31
  });
@@ -30,7 +30,8 @@ const getProcessProps = () => {
30
30
  const type = process.env[CHILD_ENV_KEY] === CHILD_ENV_VALUE ? "child" : "main";
31
31
  if (type === "main") {
32
32
  return {
33
- type
33
+ type,
34
+ pid: process.pid
34
35
  };
35
36
  }
36
37
  if (!process.send) {
@@ -38,7 +39,8 @@ const getProcessProps = () => {
38
39
  }
39
40
  return {
40
41
  type,
41
- sendMessage: process.send
42
+ sendMessage: process.send,
43
+ pid: process.pid
42
44
  };
43
45
  };
44
46
  const processProps = getProcessProps();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/cli",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Botpress CLI",
5
5
  "scripts": {
6
6
  "build": "pnpm run type-check && pnpm run bundle",
@@ -17,8 +17,9 @@
17
17
  },
18
18
  "main": "dist/index.js",
19
19
  "dependencies": {
20
- "@botpress/client": "0.0.6",
20
+ "@botpress/client": "0.0.7",
21
21
  "@bpinternal/yargs-extra": "^0.0.2",
22
+ "@parcel/watcher": "^2.1.0",
22
23
  "@types/lodash": "^4.14.191",
23
24
  "@types/node": "^18.11.17",
24
25
  "@types/verror": "^1.10.6",
@@ -42,7 +43,7 @@
42
43
  "zod-to-json-schema": "^3.20.1"
43
44
  },
44
45
  "devDependencies": {
45
- "@botpress/sdk": "0.0.7",
46
+ "@botpress/sdk": "0.0.8",
46
47
  "@types/bluebird": "^3.5.38",
47
48
  "@types/prompts": "^2.0.14",
48
49
  "@types/semver": "^7.3.11",
@@ -1,89 +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 __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 esbuild_exports = {};
20
- __export(esbuild_exports, {
21
- buildCode: () => buildCode,
22
- buildEntrypoint: () => buildEntrypoint
23
- });
24
- module.exports = __toCommonJS(esbuild_exports);
25
- var import_esbuild = require("esbuild");
26
- const keepNames = true;
27
- function buildCode({
28
- cwd,
29
- minify = true,
30
- bundle = true,
31
- sourcemap = false,
32
- logLevel = "silent",
33
- outfile,
34
- code,
35
- write
36
- }) {
37
- return (0, import_esbuild.build)({
38
- stdin: {
39
- contents: code,
40
- resolveDir: cwd,
41
- loader: "ts"
42
- },
43
- logOverride: {
44
- "equals-negative-zero": "silent"
45
- },
46
- platform: "node",
47
- target: "es2020",
48
- sourcemap,
49
- minify,
50
- bundle,
51
- outfile,
52
- absWorkingDir: cwd,
53
- logLevel,
54
- keepNames,
55
- write
56
- });
57
- }
58
- function buildEntrypoint({
59
- cwd,
60
- minify = true,
61
- bundle = true,
62
- sourcemap = false,
63
- logLevel = "silent",
64
- outfile,
65
- entrypoint,
66
- write
67
- }) {
68
- return (0, import_esbuild.build)({
69
- entryPoints: [entrypoint],
70
- logOverride: {
71
- "equals-negative-zero": "silent"
72
- },
73
- platform: "node",
74
- target: "es2020",
75
- sourcemap,
76
- minify,
77
- bundle,
78
- outfile,
79
- absWorkingDir: cwd,
80
- logLevel,
81
- keepNames,
82
- write
83
- });
84
- }
85
- // Annotate the CommonJS export names for ESM import in node:
86
- 0 && (module.exports = {
87
- buildCode,
88
- buildEntrypoint
89
- });
package/dist/const.js DELETED
@@ -1,87 +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 const_exports = {};
26
- __export(const_exports, {
27
- defDataOutfile: () => defDataOutfile,
28
- defaultBotpressApi: () => defaultBotpressApi,
29
- defaultBotpressApp: () => defaultBotpressApp,
30
- defaultBotpressHome: () => defaultBotpressHome,
31
- defaultEntrypoint: () => defaultEntrypoint,
32
- defaultIntegrationConfigScript: () => defaultIntegrationConfigScript,
33
- defaultOutputFolder: () => defaultOutputFolder,
34
- dist: () => dist,
35
- implementationTypings: () => implementationTypings,
36
- installDir: () => installDir,
37
- outfile: () => outfile,
38
- projectCache: () => projectCache,
39
- relativeToHomeFolder: () => relativeToHomeFolder,
40
- relativeToOutFolder: () => relativeToOutFolder,
41
- userCache: () => userCache
42
- });
43
- module.exports = __toCommonJS(const_exports);
44
- var import_os = __toESM(require("os"));
45
- var import_path = __toESM(require("path"));
46
- const defaultOutputFolder = ".botpress";
47
- const defaultEntrypoint = "src/index.ts";
48
- const defaultIntegrationConfigScript = "integration.definition.ts";
49
- const defaultBotpressApi = "https://api.botpress.cloud";
50
- const defaultBotpressApp = "https://app.botpress.cloud";
51
- const defaultBotpressHome = import_path.default.join(import_os.default.homedir(), ".botpress");
52
- const relativeToHomeFolder = {
53
- userCache: "user.cache.json"
54
- };
55
- const userCache = (botpressHome) => import_path.default.join(botpressHome, relativeToHomeFolder.userCache);
56
- const relativeToOutFolder = {
57
- dist: "dist",
58
- outfile: import_path.default.join("dist", "index.js"),
59
- defDataOutfile: import_path.default.join("dist", "integration.definition.json"),
60
- implementationTypings: "implementation",
61
- installDir: "installations",
62
- projectCache: "project.cache.json"
63
- };
64
- const dist = (outFolder) => import_path.default.join(outFolder, relativeToOutFolder.dist);
65
- const outfile = (outFolder) => import_path.default.join(outFolder, relativeToOutFolder.outfile);
66
- const defDataOutfile = (outFolder) => import_path.default.join(outFolder, relativeToOutFolder.defDataOutfile);
67
- const implementationTypings = (outFolder) => import_path.default.join(outFolder, relativeToOutFolder.implementationTypings);
68
- const installDir = (outFolder) => import_path.default.join(outFolder, relativeToOutFolder.installDir);
69
- const projectCache = (outFolder) => import_path.default.join(outFolder, relativeToOutFolder.projectCache);
70
- // Annotate the CommonJS export names for ESM import in node:
71
- 0 && (module.exports = {
72
- defDataOutfile,
73
- defaultBotpressApi,
74
- defaultBotpressApp,
75
- defaultBotpressHome,
76
- defaultEntrypoint,
77
- defaultIntegrationConfigScript,
78
- defaultOutputFolder,
79
- dist,
80
- implementationTypings,
81
- installDir,
82
- outfile,
83
- projectCache,
84
- relativeToHomeFolder,
85
- relativeToOutFolder,
86
- userCache
87
- });
package/dist/paths.js DELETED
@@ -1,69 +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 paths_exports = {};
26
- __export(paths_exports, {
27
- absoluteFrom: () => absoluteFrom,
28
- cwd: () => cwd,
29
- isAbsolute: () => isAbsolute,
30
- isPath: () => isPath,
31
- relativeFrom: () => relativeFrom,
32
- rmExtension: () => rmExtension,
33
- toUnix: () => toUnix
34
- });
35
- module.exports = __toCommonJS(paths_exports);
36
- var import_path = __toESM(require("path"));
37
- const cwd = () => process.cwd();
38
- const isAbsolute = (path) => import_path.default.isAbsolute(path);
39
- const isPath = (path) => isAbsolute(path) || path.startsWith(".");
40
- const rmExtension = (filename) => filename.replace(/\.[^/.]+$/, "");
41
- const toUnix = (path) => path.split(import_path.default.sep).join(import_path.default.posix.sep);
42
- const absoluteFrom = (rootdir, target) => {
43
- if (isAbsolute(target)) {
44
- return target;
45
- }
46
- return import_path.default.join(rootdir, target);
47
- };
48
- const relativeFrom = (rootdir, target) => {
49
- let absPath;
50
- if (isAbsolute(target)) {
51
- absPath = target;
52
- } else {
53
- absPath = import_path.default.resolve(import_path.default.join(rootdir, target));
54
- }
55
- if (!absPath.startsWith(rootdir)) {
56
- return target;
57
- }
58
- return absPath.slice(rootdir.length + 1);
59
- };
60
- // Annotate the CommonJS export names for ESM import in node:
61
- 0 && (module.exports = {
62
- absoluteFrom,
63
- cwd,
64
- isAbsolute,
65
- isPath,
66
- relativeFrom,
67
- rmExtension,
68
- toUnix
69
- });
package/dist/requires.js DELETED
@@ -1,49 +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 requires_exports = {};
26
- __export(requires_exports, {
27
- requireJsCode: () => requireJsCode,
28
- requireJsFile: () => requireJsFile
29
- });
30
- module.exports = __toCommonJS(requires_exports);
31
- var import_module = __toESM(require("module"));
32
- var import_path = __toESM(require("path"));
33
- const requireJsFile = (path) => {
34
- return require(path);
35
- };
36
- const requireJsCode = (code) => {
37
- const filedir = "tmp";
38
- const filename = `${Date.now()}.js`;
39
- const fileid = import_path.default.join(filedir, filename);
40
- const m = new import_module.default(fileid);
41
- m.filename = filename;
42
- m._compile(code, filename);
43
- return m.exports;
44
- };
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- requireJsCode,
48
- requireJsFile
49
- });
@@ -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 type_utils_exports = {};
16
- module.exports = __toCommonJS(type_utils_exports);
@@ -1,48 +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 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
- });
@@ -1,89 +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 __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 listen_child_exports = {};
20
- __export(listen_child_exports, {
21
- listenChild: () => listenChild
22
- });
23
- module.exports = __toCommonJS(listen_child_exports);
24
- const listenChild = async (child, logger) => {
25
- let isClosed = false;
26
- return new Promise((resolve, reject) => {
27
- child.on("close", (code) => {
28
- if (isClosed) {
29
- return;
30
- }
31
- isClosed = true;
32
- const msg = `Child process closed with code ${code}`;
33
- if (code) {
34
- logger.error(msg);
35
- reject(new Error(msg));
36
- return;
37
- }
38
- logger.log(msg);
39
- resolve();
40
- });
41
- child.on("disconnect", () => {
42
- if (isClosed) {
43
- return;
44
- }
45
- const msg = "Child process disconnected";
46
- logger.debug(msg);
47
- });
48
- child.on("exit", (code, signal) => {
49
- if (isClosed) {
50
- return;
51
- }
52
- isClosed = true;
53
- const msg = `Child process exited with code ${code} and signal ${signal}`;
54
- if (code || signal) {
55
- logger.error(msg);
56
- reject(new Error(msg));
57
- return;
58
- }
59
- logger.debug(msg);
60
- resolve();
61
- });
62
- child.on("error", (err) => {
63
- if (isClosed) {
64
- return;
65
- }
66
- const msg = `Child process error: ${err.message}`;
67
- logger.error(msg);
68
- reject(err);
69
- });
70
- child.on("message", (message) => {
71
- if (isClosed) {
72
- return;
73
- }
74
- const msg = `Child process message: ${message}`;
75
- logger.log(msg);
76
- });
77
- child.on("spawn", () => {
78
- if (isClosed) {
79
- return;
80
- }
81
- const msg = "Child process spawned";
82
- logger.debug(msg);
83
- });
84
- });
85
- };
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- listenChild
89
- });
@@ -1,39 +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 __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
- });