@botpress/cli 0.0.8 → 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.
- package/.ignore.me.github/index.ts +38 -0
- package/dist/app/file-paths.js +26 -31
- package/dist/app/index.js +5 -3
- package/dist/app/project.js +4 -4
- package/dist/config.js +0 -6
- package/dist/consts.js +11 -9
- package/dist/github-download.js +159 -0
- package/dist/github-fetch.js +173 -0
- package/dist/path-utils.js +1 -4
- package/package.json +3 -3
|
@@ -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()
|
package/dist/app/file-paths.js
CHANGED
|
@@ -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
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
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:
|
|
44
|
-
definition: absDefinition,
|
|
41
|
+
workDir: absWorkDir,
|
|
45
42
|
entryPoint: absEntrypoint,
|
|
46
|
-
outDir:
|
|
47
|
-
...import_lodash.default.mapValues(consts.
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
const absBotpressHome = pathutils.absoluteFrom(pathutils.cwd(), botpressHome);
|
|
58
|
+
constructor({ botpressHomeDir }) {
|
|
59
|
+
const absBotpressHome = pathutils.absoluteFrom(pathutils.cwd(), botpressHomeDir);
|
|
67
60
|
this.abs = {
|
|
68
|
-
|
|
69
|
-
...import_lodash.default.mapValues(consts.
|
|
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
|
|
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(
|
|
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
|
|
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);
|
package/dist/app/project.js
CHANGED
|
@@ -126,9 +126,9 @@ class ProjectCommands extends import_base.BaseCommands {
|
|
|
126
126
|
line.started(`Generating typings for integration ${import_chalk.default.bold(name)}...`);
|
|
127
127
|
const typingFiles = await generator.generateIntegrationImplementationTypings(
|
|
128
128
|
integrationDef,
|
|
129
|
-
|
|
129
|
+
this._paths.relFrom("outDir").implementationDir
|
|
130
130
|
);
|
|
131
|
-
const indexFile = await generator.generateIntegrationIndex(
|
|
131
|
+
const indexFile = await generator.generateIntegrationIndex(this._paths.relFrom("outDir").implementationDir);
|
|
132
132
|
const generatedFiles = [...typingFiles, indexFile];
|
|
133
133
|
await this._writeFilesToOutFolder(generatedFiles);
|
|
134
134
|
line.success(`Typings available at ${import_chalk.default.grey(this._paths.rel.outDir)}`);
|
|
@@ -438,7 +438,7 @@ class ProjectCommands extends import_base.BaseCommands {
|
|
|
438
438
|
line.started(`Installing ${import_chalk.default.bold(name)} v${version}...`);
|
|
439
439
|
const instanceFiles = await generator.generateIntegrationInstance(
|
|
440
440
|
integration,
|
|
441
|
-
|
|
441
|
+
this._paths.relFrom("outDir").installDir
|
|
442
442
|
);
|
|
443
443
|
await this._writeFilesToOutFolder(instanceFiles);
|
|
444
444
|
await this._generateBotIndex();
|
|
@@ -447,7 +447,7 @@ class ProjectCommands extends import_base.BaseCommands {
|
|
|
447
447
|
async _generateBotIndex() {
|
|
448
448
|
const allInstances = await this._listIntegrationInstances();
|
|
449
449
|
const indexFile = await generator.generateBotIndex(
|
|
450
|
-
|
|
450
|
+
this._paths.relFrom("outDir").installDir,
|
|
451
451
|
allInstances.map((i) => i.dirname)
|
|
452
452
|
);
|
|
453
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
|
-
|
|
34
|
-
|
|
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
|
|
44
|
+
const fromHomeDir = {
|
|
46
45
|
userCacheFile: "user.cache.json"
|
|
47
46
|
};
|
|
48
|
-
const
|
|
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
|
-
|
|
64
|
-
|
|
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
|
+
});
|
package/dist/path-utils.js
CHANGED
|
@@ -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
|
-
|
|
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 = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Botpress CLI",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "pnpm run type-check && pnpm run bundle",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@botpress/client": "0.0.
|
|
20
|
+
"@botpress/client": "0.0.7",
|
|
21
21
|
"@bpinternal/yargs-extra": "^0.0.2",
|
|
22
22
|
"@parcel/watcher": "^2.1.0",
|
|
23
23
|
"@types/lodash": "^4.14.191",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"zod-to-json-schema": "^3.20.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@botpress/sdk": "0.0.
|
|
46
|
+
"@botpress/sdk": "0.0.8",
|
|
47
47
|
"@types/bluebird": "^3.5.38",
|
|
48
48
|
"@types/prompts": "^2.0.14",
|
|
49
49
|
"@types/semver": "^7.3.11",
|