@hexabot-ai/cli 3.3.2 → 3.3.4-beta.0
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.
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as fs from 'fs';
|
|
7
7
|
import * as path from 'path';
|
|
8
|
+
import decompress from '@xhmikosr/decompress';
|
|
8
9
|
import axios from 'axios';
|
|
9
|
-
import decompress from 'decompress';
|
|
10
10
|
export const downloadAndExtractTemplate = async (templateUrl, destination) => {
|
|
11
11
|
try {
|
|
12
12
|
const response = await axios({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hexabot-ai/cli",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4-beta.0",
|
|
4
4
|
"description": "Official Hexabot CLI for creating and managing AI chatbot/agent projects built with Hexabot.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -18,17 +18,16 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@inquirer/prompts": "^7.10.1",
|
|
21
|
+
"@xhmikosr/decompress": "^11.1.3",
|
|
21
22
|
"axios": "^1.17.0",
|
|
22
23
|
"chalk": "^5.3.0",
|
|
23
24
|
"commander": "^12.1.0",
|
|
24
|
-
"decompress": "^4.2.1",
|
|
25
25
|
"degit": "^2.8.4",
|
|
26
26
|
"dotenv": "^16.4.5",
|
|
27
27
|
"figlet": "^1.7.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@jest/globals": "^30.4.1",
|
|
31
|
-
"@types/decompress": "^4.2.7",
|
|
32
31
|
"@types/degit": "^2.8.6",
|
|
33
32
|
"@types/figlet": "^1.5.8",
|
|
34
33
|
"@types/jest": "^30.0.0",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2025 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as os from 'os';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
|
|
11
|
+
import { jest } from '@jest/globals';
|
|
12
|
+
|
|
13
|
+
const decompress = jest.fn<() => Promise<unknown[]>>();
|
|
14
|
+
const axios = jest.fn<() => Promise<{ data: Buffer }>>();
|
|
15
|
+
|
|
16
|
+
jest.unstable_mockModule('@xhmikosr/decompress', () => ({
|
|
17
|
+
default: decompress,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
jest.unstable_mockModule('axios', () => ({
|
|
21
|
+
default: axios,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
let downloadAndExtractTemplate: (
|
|
25
|
+
templateUrl: string,
|
|
26
|
+
destination: string,
|
|
27
|
+
) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
beforeAll(async () => {
|
|
30
|
+
({ downloadAndExtractTemplate } = await import('../templates.js'));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('downloadAndExtractTemplate', () => {
|
|
34
|
+
let destination: string;
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
jest.resetAllMocks();
|
|
38
|
+
destination = fs.mkdtempSync(path.join(os.tmpdir(), 'hexabot-template-'));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
fs.rmSync(destination, { recursive: true, force: true });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('downloads the archive, extracts it and removes the zip file', async () => {
|
|
46
|
+
axios.mockResolvedValue({ data: Buffer.from('zip-content') });
|
|
47
|
+
decompress.mockResolvedValue([]);
|
|
48
|
+
|
|
49
|
+
await downloadAndExtractTemplate(
|
|
50
|
+
'https://example.com/template.zip',
|
|
51
|
+
destination,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(axios).toHaveBeenCalledWith({
|
|
55
|
+
url: 'https://example.com/template.zip',
|
|
56
|
+
method: 'GET',
|
|
57
|
+
responseType: 'arraybuffer',
|
|
58
|
+
});
|
|
59
|
+
expect(decompress).toHaveBeenCalledWith(
|
|
60
|
+
path.join(destination, 'template.zip'),
|
|
61
|
+
destination,
|
|
62
|
+
{ strip: 1 },
|
|
63
|
+
);
|
|
64
|
+
expect(fs.existsSync(path.join(destination, 'template.zip'))).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('throws a friendly error when the download fails', async () => {
|
|
68
|
+
axios.mockRejectedValue(new Error('network error'));
|
|
69
|
+
|
|
70
|
+
await expect(
|
|
71
|
+
downloadAndExtractTemplate(
|
|
72
|
+
'https://example.com/template.zip',
|
|
73
|
+
destination,
|
|
74
|
+
),
|
|
75
|
+
).rejects.toThrow('Failed to download template from GitHub');
|
|
76
|
+
expect(decompress).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2025 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
declare module '@xhmikosr/decompress' {
|
|
8
|
+
interface File {
|
|
9
|
+
data: Buffer;
|
|
10
|
+
mode: number;
|
|
11
|
+
mtime: string;
|
|
12
|
+
path: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface DecompressOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Filter out files before extracting
|
|
19
|
+
*/
|
|
20
|
+
filter?(file: File): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Map files before extracting
|
|
23
|
+
*/
|
|
24
|
+
map?(file: File): File;
|
|
25
|
+
/**
|
|
26
|
+
* Array of plugins to use (defaults to tar, tar.bz2, tar.gz and zip)
|
|
27
|
+
*/
|
|
28
|
+
plugins?: unknown[];
|
|
29
|
+
/**
|
|
30
|
+
* Remove leading directory components from extracted files
|
|
31
|
+
*/
|
|
32
|
+
strip?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function decompress(
|
|
36
|
+
input: string | Buffer,
|
|
37
|
+
output?: string | DecompressOptions,
|
|
38
|
+
opts?: DecompressOptions,
|
|
39
|
+
): Promise<File[]>;
|
|
40
|
+
|
|
41
|
+
export default decompress;
|
|
42
|
+
}
|