Skip to content

Commit e1103f0

Browse files
Merge pull request #393 from RedisInsight/fix/RI-2494_default_content
#RI-2494-add script to download default content
2 parents f088418 + ae67c8d commit e1103f0

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

redisinsight/api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"scripts": {
1212
"build:defaults:commands": "ts-node ./scripts/default-commands.ts",
1313
"build:defaults:enablement-area": "ts-node ./scripts/default-enablement-area.ts",
14-
"build:defaults": "yarn build:defaults:enablement-area && yarn build:defaults:commands",
14+
"build:defaults:content": "ts-node ./scripts/default-content.ts",
15+
"build:defaults": "yarn build:defaults:enablement-area && yarn build:defaults:commands yarn build:defaults:content",
1516
"prebuild": "rimraf dist",
1617
"build": "nest build",
1718
"build:prod": "rimraf dist && nest build -p ./tsconfig.build.prod.json && cross-env NODE_ENV=production",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import axios from 'axios';
2+
import * as fs from 'fs-extra';
3+
import * as path from 'path';
4+
import { join } from 'path';
5+
import { get } from '../src/utils/config';
6+
import * as AdmZip from 'adm-zip';
7+
8+
const PATH_CONFIG = get('dir_path');
9+
const CONTENT_CONFIG = get('content');
10+
11+
async function init() {
12+
try {
13+
await fs.remove(PATH_CONFIG.defaultContent);
14+
15+
await fs.ensureDir(PATH_CONFIG.defaultContent);
16+
17+
const { data } = await axios.get(
18+
new URL(path.join(
19+
CONTENT_CONFIG.updateUrl,
20+
CONTENT_CONFIG.zip,
21+
)).toString(),
22+
{
23+
responseType: 'arraybuffer',
24+
},
25+
);
26+
27+
// extract archive to default folder
28+
const zip = new AdmZip(data);
29+
zip.extractAllTo(PATH_CONFIG.defaultContent, true);
30+
31+
const { data: buildInfo } = await axios.get(
32+
new URL(path.join(
33+
CONTENT_CONFIG.updateUrl,
34+
CONTENT_CONFIG.buildInfo,
35+
)).toString(),
36+
{
37+
responseType: 'arraybuffer',
38+
},
39+
);
40+
41+
// save build info to default folder
42+
await fs.writeFile(
43+
join(PATH_CONFIG.defaultContent, CONTENT_CONFIG.buildInfo),
44+
buildInfo,
45+
);
46+
47+
process.exit(0);
48+
} catch (e) {
49+
console.error('Something went wrong trying to get default commands jsons', e);
50+
process.exit(1);
51+
}
52+
}
53+
54+
init();

0 commit comments

Comments
 (0)