Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions redisinsight/api/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { join } from 'path';

const homedir = join(__dirname, '..');

const buildInfoFileName = 'build.json';
const dataZipFileName = 'data.zip';


const staticDir = process.env.BUILD_TYPE === 'ELECTRON' && process['resourcesPath']
? join(process['resourcesPath'], 'static')
: join(__dirname, '..', 'static');
Expand All @@ -21,8 +25,10 @@ export default {
pluginsAssets: join(staticDir, 'resources', 'plugins'),
commands: join(homedir, 'commands'),
defaultCommandsDir: join(defaultsDir, 'commands'),
enablementArea: process.env.GUIDES_DEV_PATH || join(homedir, 'enablement-area'),
defaultEnablementArea: join(defaultsDir, 'enablement-area'),
guides: process.env.GUIDES_DEV_PATH || join(homedir, 'guides'),
defaultGuides: join(defaultsDir, 'guides'),
tutorials: process.env.TUTORIALS_DEV_PATH || join(homedir, 'tutorials'),
defaultTutorials: join(defaultsDir, 'tutorials'),
content: process.env.CONTENT_DEV_PATH || join(homedir, 'content'),
defaultContent: join(defaultsDir, 'content'),
caCertificates: join(homedir, 'ca_certificates'),
Expand All @@ -35,7 +41,8 @@ export default {
globalPrefix: 'api',
customPluginsUri: '/plugins',
staticUri: '/static',
enablementAreaUri: '/static/workbench',
guidesUri: '/static/guides',
tutorialsUri: '/static/tutorials',
contentUri: '/static/content',
defaultPluginsUri: '/static/plugins',
pluginsAssetsUri: '/static/resources/plugins',
Expand Down Expand Up @@ -92,18 +99,25 @@ export default {
plugins: {
stateMaxSize: parseInt(process.env.PLUGIN_STATE_MAX_SIZE, 10) || 1024 * 1024,
},
enablementArea: {
updateUrl: process.env.ENABLEMENT_AREA_UPDATE_URL
guides: {
updateUrl: process.env.GUIDES_UPDATE_URL
|| 'https://github.com/RedisInsight/Guides/releases/download/latest',
zip: process.env.ENABLEMENT_AREA_ZIP || 'data.zip',
buildInfo: process.env.ENABLEMENT_AREA_CHECKSUM || 'build.json',
zip: process.env.GUIDES_ZIP || dataZipFileName,
buildInfo: process.env.GUIDES_CHECKSUM || buildInfoFileName,
devMode: !!process.env.GUIDES_DEV_PATH,
},
tutorials: {
updateUrl: process.env.TUTORIALS_UPDATE_URL
|| 'https://github.com/RedisInsight/Tutorials/releases/download/latest',
zip: process.env.TUTORIALS_ZIP || dataZipFileName,
buildInfo: process.env.TUTORIALS_CHECKSUM || buildInfoFileName,
devMode: !!process.env.TUTORIALS_DEV_PATH,
},
content: {
updateUrl: process.env.CONTENT_UPDATE_URL
|| 'https://github.com/RedisInsight/Statics/releases/download/latest',
zip: process.env.CONTENT_ZIP || 'data.zip',
buildInfo: process.env.CONTENT_CHECKSUM || 'build.json',
zip: process.env.CONTENT_ZIP || dataZipFileName,
buildInfo: process.env.CONTENT_CHECKSUM || buildInfoFileName,
devMode: !!process.env.CONTENT_DEV_PATH,
},
workbench: {
Expand Down
3 changes: 2 additions & 1 deletion redisinsight/api/config/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default {
logs: join(homedir, 'logs'),
customPlugins: join(homedir, 'plugins'),
commands: join(homedir, 'commands'),
enablementArea: process.env.GUIDES_DEV_PATH || join(homedir, 'enablement-area'),
guides: process.env.GUIDES_DEV_PATH || join(homedir, 'guides'),
tutorials: process.env.TUTORIALS_DEV_PATH || join(homedir, 'tutorials'),
content: process.env.CONTENT_DEV_PATH || join(homedir, 'content'),
caCertificates: join(homedir, 'ca_certificates'),
clientCertificates: join(homedir, 'client_certificates'),
Expand Down
3 changes: 2 additions & 1 deletion redisinsight/api/config/staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default {
logs: join(homedir, 'logs'),
customPlugins: join(homedir, 'plugins'),
commands: join(homedir, 'commands'),
enablementArea: process.env.GUIDES_DEV_PATH || join(homedir, 'enablement-area'),
guides: process.env.GUIDES_DEV_PATH || join(homedir, 'guides'),
tutorials: process.env.TUTORIALS_DEV_PATH || join(homedir, 'tutorials'),
content: process.env.CONTENT_DEV_PATH || join(homedir, 'content'),
caCertificates: join(homedir, 'ca_certificates'),
clientCertificates: join(homedir, 'client_certificates'),
Expand Down
5 changes: 3 additions & 2 deletions redisinsight/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
},
"scripts": {
"build:defaults:commands": "ts-node ./scripts/default-commands.ts",
"build:defaults:enablement-area": "ts-node ./scripts/default-enablement-area.ts",
"build:defaults:guides": "ts-node ./scripts/default-guides.ts",
"build:defaults:tutorials": "ts-node ./scripts/default-tutorials.ts",
"build:defaults:content": "ts-node ./scripts/default-content.ts",
"build:defaults": "yarn build:defaults:enablement-area && yarn build:defaults:commands yarn build:defaults:content",
"build:defaults": "yarn build:defaults:guides && yarn build:defaults:commands && yarn build:defaults:content && build:defaults:tutorials",
"prebuild": "rimraf dist",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test it locally? I assume that default tutorials will not work because I don't see build:defaults:tutorials here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't include the tutorials because there are no files in the repository, so the script will fail with an error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, do not hurry up build:defaults:tutorialss

"build": "nest build",
"build:prod": "rimraf dist && nest build -p ./tsconfig.build.prod.json && cross-env NODE_ENV=production",
Expand Down
52 changes: 19 additions & 33 deletions redisinsight/api/scripts/default-content.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
import axios from 'axios';
import * as fs from 'fs-extra';
import * as path from 'path';
import { join } from 'path';
import { getFile, updateFolderFromArchive, updateFile } from '../src/utils/file-helper';
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);
const archiveUrl = new URL(path.join(
CONTENT_CONFIG.updateUrl,
CONTENT_CONFIG.zip,
)).toString();

await fs.ensureDir(PATH_CONFIG.defaultContent);
const buildInfoUrl = new URL(path.join(
CONTENT_CONFIG.updateUrl,
CONTENT_CONFIG.buildInfo,
)).toString();

const { data } = await axios.get(
new URL(path.join(
CONTENT_CONFIG.updateUrl,
CONTENT_CONFIG.zip,
)).toString(),
{
responseType: 'arraybuffer',
},
);
async function init() {
try {
// get archive
const data = await getFile(archiveUrl);

// 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',
},
);
await updateFolderFromArchive(PATH_CONFIG.defaultContent, data);

// get build info
const buildInfo = await getFile(buildInfoUrl);

// save build info to default folder
await fs.writeFile(
join(PATH_CONFIG.defaultContent, CONTENT_CONFIG.buildInfo),
buildInfo,
);
await updateFile(PATH_CONFIG.defaultContent, CONTENT_CONFIG.buildInfo, buildInfo);

process.exit(0);
} catch (e) {
Expand All @@ -52,3 +37,4 @@ async function init() {
}

init();

56 changes: 0 additions & 56 deletions redisinsight/api/scripts/default-enablement-area.ts

This file was deleted.

39 changes: 39 additions & 0 deletions redisinsight/api/scripts/default-guides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as path from 'path';
import { getFile, updateFolderFromArchive, updateFile } from '../src/utils/file-helper';
import { get } from '../src/utils/config';

const PATH_CONFIG = get('dir_path');
const GUIDES_CONFIG = get('guides');

const archiveUrl = new URL(path.join(
GUIDES_CONFIG.updateUrl,
GUIDES_CONFIG.zip,
)).toString();

const buildInfoUrl = new URL(path.join(
GUIDES_CONFIG.updateUrl,
GUIDES_CONFIG.buildInfo,
)).toString();

async function init() {
try {
// // get archive
const data = await getFile(archiveUrl);

// extract archive to default folder
await updateFolderFromArchive(PATH_CONFIG.defaultGuides, data);

// // get build info
const buildInfo = await getFile(buildInfoUrl);

// save build info to default folder
await updateFile(PATH_CONFIG.defaultGuides, GUIDES_CONFIG.buildInfo, buildInfo);

process.exit(0);
} catch (e) {
console.error('Something went wrong trying to get default guides archive', e);
process.exit(1);
}
}

init();
39 changes: 39 additions & 0 deletions redisinsight/api/scripts/default-tutorials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as path from 'path';
import { getFile, updateFolderFromArchive, updateFile } from '../src/utils/file-helper';
import { get } from '../src/utils/config';

const PATH_CONFIG = get('dir_path');
const TUTORIALS_CONFIG = get('tutorials');

const archiveUrl = new URL(path.join(
TUTORIALS_CONFIG.updateUrl,
TUTORIALS_CONFIG.zip,
)).toString();

const buildInfoUrl = new URL(path.join(
TUTORIALS_CONFIG.updateUrl,
TUTORIALS_CONFIG.buildInfo,
)).toString();

async function init() {
try {
// get archive
const data = await getFile(archiveUrl);

// extract archive to default folder
await updateFolderFromArchive(PATH_CONFIG.defaultTutorials, data);

// get build info
const buildInfo = await getFile(buildInfoUrl);

// save build info to default folder
await updateFile(PATH_CONFIG.defaultTutorials, TUTORIALS_CONFIG.buildInfo, buildInfo);

process.exit(0);
} catch (e) {
console.error('Something went wrong trying to get default tutorials archive', e);
process.exit(1);
}
}

init();
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import config from 'src/utils/config';
import { AutoUpdatedStaticsProvider } from './auto-updated-statics.provider';

const PATH_CONFIG = config.get('dir_path');
const ENABLEMENT_AREA_CONFIG = config.get('enablementArea');
const GUIDES = config.get('guides');

jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
Expand All @@ -26,13 +26,13 @@ describe('AutoUpdatedStaticsProvider', () => {
jest.mock('adm-zip', () => jest.fn().mockImplementation(() => mockedAdmZip));

service = new AutoUpdatedStaticsProvider({
name: 'EnablementAreaProvider',
destinationPath: PATH_CONFIG.enablementArea,
defaultSourcePath: PATH_CONFIG.defaultEnablementArea,
updateUrl: ENABLEMENT_AREA_CONFIG.updateUrl,
buildInfo: ENABLEMENT_AREA_CONFIG.buildInfo,
zip: ENABLEMENT_AREA_CONFIG.zip,
devMode: ENABLEMENT_AREA_CONFIG.devMode,
name: 'GuidesProvider',
destinationPath: PATH_CONFIG.guides,
defaultSourcePath: PATH_CONFIG.defaultGuides,
updateUrl: GUIDES.updateUrl,
buildInfo: GUIDES.buildInfo,
zip: GUIDES.zip,
devMode: GUIDES.devMode,
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import axios from 'axios';
import * as fs from 'fs-extra';
import * as AdmZip from 'adm-zip';
import { URL } from 'url';
import { join } from 'path';
import { get } from 'lodash';
import { getFile } from 'src/utils';

import { IStaticsProviderOptions } from './auto-updated-statics.interface';

Expand Down Expand Up @@ -83,14 +83,7 @@ export class AutoUpdatedStaticsProvider implements OnModuleInit {
*/
async getLatestArchive() {
try {
const { data } = await axios.get(
new URL(join(this.options.updateUrl, this.options.zip)).toString(),
{
responseType: 'arraybuffer',
},
);

return data;
return await getFile(new URL(join(this.options.updateUrl, this.options.zip)).toString());
} catch (e) {
this.logger.error('Unable to get remote archive', e);
return null;
Expand All @@ -114,11 +107,7 @@ export class AutoUpdatedStaticsProvider implements OnModuleInit {
*/
async getRemoteBuildInfo(): Promise<Record<string, any>> {
try {
const { data } = await axios.get(
new URL(join(this.options.updateUrl, this.options.buildInfo)).toString(),
);

return data;
return await getFile(new URL(join(this.options.updateUrl, this.options.buildInfo)).toString());
} catch (e) {
this.logger.error('Unable to get remote build info', e);
return {};
Expand Down
Loading