@botpress/cli 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.js +107 -0
- package/dist/app/api-utils.js +9 -3
- package/dist/app/base.js +1 -3
- package/dist/app/errors.js +8 -0
- package/dist/app/file-paths.js +4 -2
- package/dist/app/index.js +17 -12
- package/dist/app/user.js +73 -23
- package/dist/code-generation/action.js +70 -0
- package/dist/code-generation/channel.js +51 -0
- package/dist/code-generation/configuration.js +40 -0
- package/dist/code-generation/const.js +31 -0
- package/dist/code-generation/event.js +41 -0
- package/dist/code-generation/index.js +80 -0
- package/dist/code-generation/integration-impl.js +147 -0
- package/dist/code-generation/integration-instance.js +79 -0
- package/dist/code-generation/message.js +41 -0
- package/dist/code-generation/module.js +115 -0
- package/dist/code-generation/typings.js +16 -0
- package/dist/command-definitions.js +61 -0
- package/dist/command-implementations/add-command.js +124 -0
- package/dist/command-implementations/base-command.js +53 -0
- package/dist/command-implementations/bot-commands.js +89 -0
- package/dist/command-implementations/build-command.js +48 -0
- package/dist/command-implementations/bundle-command.js +58 -0
- package/dist/command-implementations/deploy-command.js +162 -0
- package/dist/command-implementations/dev-command.js +168 -0
- package/dist/command-implementations/gen-command.js +58 -0
- package/dist/command-implementations/global-command.js +111 -0
- package/dist/command-implementations/index.js +78 -0
- package/dist/command-implementations/init-command.js +85 -0
- package/dist/command-implementations/integration-commands.js +107 -0
- package/dist/command-implementations/login-command.js +75 -0
- package/dist/command-implementations/logout-command.js +34 -0
- package/dist/command-implementations/project-command.js +115 -0
- package/dist/command-implementations/serve-command.js +53 -0
- package/dist/command-tree.js +59 -0
- package/dist/config.js +18 -2
- package/dist/consts.js +13 -0
- package/dist/errors.js +156 -0
- package/dist/index.js +33 -20
- package/dist/integration-ref.js +61 -0
- package/dist/path-utils.js +6 -0
- package/dist/register-yargs.js +85 -0
- package/dist/typings.js +16 -0
- package/dist/utils/cache-utils.js +99 -0
- package/dist/utils/esbuild-utils.js +89 -0
- package/dist/utils/event-emitter.js +62 -0
- package/dist/utils/file-watcher.js +68 -0
- package/dist/utils/index.js +55 -0
- package/dist/utils/path-utils.js +83 -0
- package/dist/utils/prompt-utils.js +75 -0
- package/dist/utils/require-utils.js +49 -0
- package/dist/utils/string-utils.js +38 -0
- package/package.json +6 -4
- package/templates/echo-bot/.botpress/project.cache.json +1 -0
- package/templates/echo-bot/package.json +22 -0
- package/templates/echo-bot/readme.md +5 -0
- package/templates/echo-bot/src/index.ts +44 -0
- package/templates/echo-bot/tsconfig.json +15 -0
- package/templates/empty-integration/.botpress/implementation/actions/index.ts +7 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/audio.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/card.ts +17 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/carousel.ts +19 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/choice.ts +14 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/dropdown.ts +14 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/file.ts +11 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/image.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/index.ts +40 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/location.ts +11 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/markdown.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/text.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/video.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/index.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/configuration.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/events/index.ts +7 -0
- package/templates/empty-integration/.botpress/implementation/index.ts +17 -0
- package/templates/empty-integration/.botpress/index.ts +1 -0
- package/templates/empty-integration/.botpress/project.cache.json +1 -0
- package/templates/empty-integration/integration.definition.ts +13 -0
- package/templates/empty-integration/package.json +22 -0
- package/templates/empty-integration/readme.md +5 -0
- package/templates/empty-integration/src/index.ts +58 -0
- package/templates/empty-integration/tsconfig.json +15 -0
- package/.ignore.me.github/index.ts +0 -38
- package/dist/github-download.js +0 -159
- package/dist/github-fetch.js +0 -173
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Client } from '@botpress/client'
|
|
2
|
+
import { Bot, messages } from '@botpress/sdk'
|
|
3
|
+
import type { z } from 'zod'
|
|
4
|
+
// import * as botpress from '.botpress' /** uncomment to get generated code */
|
|
5
|
+
|
|
6
|
+
type DefaultMessages = typeof messages.defaults
|
|
7
|
+
type DefaultMessageType = keyof DefaultMessages
|
|
8
|
+
type DefaultMessagePayload<T extends DefaultMessageType> = z.infer<DefaultMessages[T]['schema']>
|
|
9
|
+
|
|
10
|
+
type CreateMessageProps = Parameters<Client['createMessage']>[0]
|
|
11
|
+
type CreateMessageBody<T extends DefaultMessageType> = Omit<CreateMessageProps, 'type' | 'payload'> & {
|
|
12
|
+
type: T
|
|
13
|
+
payload: DefaultMessagePayload<T>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const logger = console
|
|
17
|
+
|
|
18
|
+
const bot = new Bot({
|
|
19
|
+
integrations: [],
|
|
20
|
+
configuration: {
|
|
21
|
+
schema: {},
|
|
22
|
+
},
|
|
23
|
+
states: {},
|
|
24
|
+
events: {},
|
|
25
|
+
recurringEvents: {},
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
bot.message('', async ({ message, client, ctx }) => {
|
|
29
|
+
logger.info('Received message', message)
|
|
30
|
+
|
|
31
|
+
await client.createMessage({
|
|
32
|
+
conversationId: message.conversationId,
|
|
33
|
+
userId: ctx.botId,
|
|
34
|
+
tags: {},
|
|
35
|
+
type: 'text',
|
|
36
|
+
payload: {
|
|
37
|
+
text: `You said: ${message.payload.text}`,
|
|
38
|
+
},
|
|
39
|
+
} satisfies CreateMessageBody<'text'>)
|
|
40
|
+
|
|
41
|
+
logger.info('text message sent')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export default bot
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/node18-strictest/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es2017",
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"checkJs": false,
|
|
8
|
+
"incremental": true,
|
|
9
|
+
"exactOptionalPropertyTypes": false,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": false,
|
|
12
|
+
"noUnusedLocals": false
|
|
13
|
+
},
|
|
14
|
+
"include": [".botpress/**/*", "src/**/*", "./*.ts", "./*.json"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Audio {
|
|
9
|
+
audioUrl: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Card {
|
|
9
|
+
title: string;
|
|
10
|
+
subtitle?: string;
|
|
11
|
+
imageUrl?: string;
|
|
12
|
+
actions: {
|
|
13
|
+
action: "postback" | "url" | "say";
|
|
14
|
+
label: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Carousel {
|
|
9
|
+
items: {
|
|
10
|
+
title: string;
|
|
11
|
+
subtitle?: string;
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
actions: {
|
|
14
|
+
action: "postback" | "url" | "say";
|
|
15
|
+
label: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}[];
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Choice {
|
|
9
|
+
text: string;
|
|
10
|
+
options: {
|
|
11
|
+
label: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Dropdown {
|
|
9
|
+
text: string;
|
|
10
|
+
options: {
|
|
11
|
+
label: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface File {
|
|
9
|
+
fileUrl: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Image {
|
|
9
|
+
imageUrl: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
// This file is generated
|
|
3
|
+
// Do not edit this file
|
|
4
|
+
|
|
5
|
+
import type * as text from "./text";
|
|
6
|
+
export * as text from "./text";
|
|
7
|
+
import type * as markdown from "./markdown";
|
|
8
|
+
export * as markdown from "./markdown";
|
|
9
|
+
import type * as image from "./image";
|
|
10
|
+
export * as image from "./image";
|
|
11
|
+
import type * as audio from "./audio";
|
|
12
|
+
export * as audio from "./audio";
|
|
13
|
+
import type * as video from "./video";
|
|
14
|
+
export * as video from "./video";
|
|
15
|
+
import type * as file from "./file";
|
|
16
|
+
export * as file from "./file";
|
|
17
|
+
import type * as location from "./location";
|
|
18
|
+
export * as location from "./location";
|
|
19
|
+
import type * as carousel from "./carousel";
|
|
20
|
+
export * as carousel from "./carousel";
|
|
21
|
+
import type * as card from "./card";
|
|
22
|
+
export * as card from "./card";
|
|
23
|
+
import type * as dropdown from "./dropdown";
|
|
24
|
+
export * as dropdown from "./dropdown";
|
|
25
|
+
import type * as choice from "./choice";
|
|
26
|
+
export * as choice from "./choice";
|
|
27
|
+
|
|
28
|
+
export type ChannelChannel = {
|
|
29
|
+
text: text.Text;
|
|
30
|
+
markdown: markdown.Markdown;
|
|
31
|
+
image: image.Image;
|
|
32
|
+
audio: audio.Audio;
|
|
33
|
+
video: video.Video;
|
|
34
|
+
file: file.File;
|
|
35
|
+
location: location.Location;
|
|
36
|
+
carousel: carousel.Carousel;
|
|
37
|
+
card: card.Card;
|
|
38
|
+
dropdown: dropdown.Dropdown;
|
|
39
|
+
choice: choice.Choice;
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Location {
|
|
9
|
+
latitude: number;
|
|
10
|
+
longitude: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Markdown {
|
|
9
|
+
markdown: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Text {
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Video {
|
|
9
|
+
videoUrl: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Configuration {
|
|
9
|
+
[k: string]: unknown;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
// This file is generated
|
|
3
|
+
// Do not edit this file
|
|
4
|
+
|
|
5
|
+
import { Integration } from "@botpress/sdk";
|
|
6
|
+
|
|
7
|
+
import type * as configuration from "./configuration";
|
|
8
|
+
import type * as actions from "./actions/index";
|
|
9
|
+
import type * as channels from "./channels/index";
|
|
10
|
+
import type * as events from "./events/index";
|
|
11
|
+
export * as configuration from "./configuration";
|
|
12
|
+
export * as actions from "./actions/index";
|
|
13
|
+
export * as channels from "./channels/index";
|
|
14
|
+
export * as events from "./events/index";
|
|
15
|
+
|
|
16
|
+
export class IntegrationEmpty
|
|
17
|
+
extends Integration<configuration.Configuration, actions.Actions, channels.Channels, events.Events> {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './implementation'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IntegrationDefinition, messages } from '@botpress/sdk'
|
|
2
|
+
import { version } from './package.json'
|
|
3
|
+
|
|
4
|
+
export default new IntegrationDefinition({
|
|
5
|
+
name: 'empty',
|
|
6
|
+
version,
|
|
7
|
+
public: true,
|
|
8
|
+
channels: {
|
|
9
|
+
channel: {
|
|
10
|
+
messages: { ...messages.defaults },
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@botpresshub/empty-integration",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Integration with no content",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"type-check": "tsc --noEmit"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"private": true,
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@botpress/client": "0.0.10",
|
|
14
|
+
"@botpress/sdk": "0.0.8",
|
|
15
|
+
"zod": "^3.20.6"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^18.11.17",
|
|
19
|
+
"ts-node": "^10.9.1",
|
|
20
|
+
"typescript": "^4.9.4"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as botpress from '.botpress'
|
|
2
|
+
|
|
3
|
+
const logger = console
|
|
4
|
+
logger.info('starting integration')
|
|
5
|
+
|
|
6
|
+
class NotImplementedError extends Error {
|
|
7
|
+
constructor() {
|
|
8
|
+
super('Not implemented')
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default new botpress.IntegrationEmpty({
|
|
13
|
+
register: async () => {},
|
|
14
|
+
unregister: async () => {},
|
|
15
|
+
actions: {},
|
|
16
|
+
channels: {
|
|
17
|
+
channel: {
|
|
18
|
+
messages: {
|
|
19
|
+
text: async () => {
|
|
20
|
+
throw new NotImplementedError()
|
|
21
|
+
},
|
|
22
|
+
image: async () => {
|
|
23
|
+
throw new NotImplementedError()
|
|
24
|
+
},
|
|
25
|
+
markdown: async () => {
|
|
26
|
+
throw new NotImplementedError()
|
|
27
|
+
},
|
|
28
|
+
audio: async () => {
|
|
29
|
+
throw new NotImplementedError()
|
|
30
|
+
},
|
|
31
|
+
video: async () => {
|
|
32
|
+
throw new NotImplementedError()
|
|
33
|
+
},
|
|
34
|
+
file: async () => {
|
|
35
|
+
throw new NotImplementedError()
|
|
36
|
+
},
|
|
37
|
+
location: async () => {
|
|
38
|
+
throw new NotImplementedError()
|
|
39
|
+
},
|
|
40
|
+
carousel: async () => {
|
|
41
|
+
throw new NotImplementedError()
|
|
42
|
+
},
|
|
43
|
+
card: async () => {
|
|
44
|
+
throw new NotImplementedError()
|
|
45
|
+
},
|
|
46
|
+
choice: async () => {
|
|
47
|
+
throw new NotImplementedError()
|
|
48
|
+
},
|
|
49
|
+
dropdown: async () => {
|
|
50
|
+
throw new NotImplementedError()
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
handler: async () => {
|
|
56
|
+
throw new NotImplementedError()
|
|
57
|
+
},
|
|
58
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/node18-strictest/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es2017",
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"checkJs": false,
|
|
8
|
+
"incremental": true,
|
|
9
|
+
"exactOptionalPropertyTypes": false,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": false,
|
|
12
|
+
"noUnusedLocals": false
|
|
13
|
+
},
|
|
14
|
+
"include": [".botpress/**/*", "src/**/*", "./*.ts", "./*.json"]
|
|
15
|
+
}
|
|
@@ -1,38 +0,0 @@
|
|
|
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/github-download.js
DELETED
|
@@ -1,159 +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 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
|
-
});
|