diff --git a/redisinsight/api/package.json b/redisinsight/api/package.json index e4124f4387..a0a62327c4 100644 --- a/redisinsight/api/package.json +++ b/redisinsight/api/package.json @@ -11,7 +11,8 @@ "scripts": { "build:defaults:commands": "ts-node ./scripts/default-commands.ts", "build:defaults:enablement-area": "ts-node ./scripts/default-enablement-area.ts", - "build:defaults": "yarn build:defaults:enablement-area && yarn build:defaults:commands", + "build:defaults:content": "ts-node ./scripts/default-content.ts", + "build:defaults": "yarn build:defaults:enablement-area && yarn build:defaults:commands yarn build:defaults:content", "prebuild": "rimraf dist", "build": "nest build", "build:prod": "rimraf dist && nest build -p ./tsconfig.build.prod.json && cross-env NODE_ENV=production", diff --git a/redisinsight/api/scripts/default-content.ts b/redisinsight/api/scripts/default-content.ts new file mode 100644 index 0000000000..5eecb1b2dd --- /dev/null +++ b/redisinsight/api/scripts/default-content.ts @@ -0,0 +1,54 @@ +import axios from 'axios'; +import * as fs from 'fs-extra'; +import * as path from 'path'; +import { join } from 'path'; +import { get } from '../src/utils/config'; +import * as AdmZip from 'adm-zip'; + +const PATH_CONFIG = get('dir_path'); +const CONTENT_CONFIG = get('content'); + +async function init() { + try { + await fs.remove(PATH_CONFIG.defaultContent); + + await fs.ensureDir(PATH_CONFIG.defaultContent); + + const { data } = await axios.get( + new URL(path.join( + CONTENT_CONFIG.updateUrl, + CONTENT_CONFIG.zip, + )).toString(), + { + responseType: 'arraybuffer', + }, + ); + + // extract archive to default folder + const zip = new AdmZip(data); + zip.extractAllTo(PATH_CONFIG.defaultContent, true); + + const { data: buildInfo } = await axios.get( + new URL(path.join( + CONTENT_CONFIG.updateUrl, + CONTENT_CONFIG.buildInfo, + )).toString(), + { + responseType: 'arraybuffer', + }, + ); + + // save build info to default folder + await fs.writeFile( + join(PATH_CONFIG.defaultContent, CONTENT_CONFIG.buildInfo), + buildInfo, + ); + + process.exit(0); + } catch (e) { + console.error('Something went wrong trying to get default commands jsons', e); + process.exit(1); + } +} + +init();