Skip to content

Commit 0f31fde

Browse files
authored
Merge pull request #2217 from RedisInsight/feature/RI-2850_Electron_improvment
Feature/ri 2850 electron improvment
2 parents c79dcf5 + 8f108ad commit 0f31fde

File tree

96 files changed

+1912
-1571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1912
-1571
lines changed

.eslintrc.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,63 @@
11
module.exports = {
22
root: true,
3+
env: {
4+
node: true,
5+
},
36
extends: ['airbnb-typescript'],
47
plugins: ['@typescript-eslint'],
58
parser: '@typescript-eslint/parser',
69
rules: {
7-
'max-len': ['warn', 120],
10+
semi: ['error', 'never'],
11+
quotes: [2, 'single', { avoidEscape: true }],
12+
'max-len': ['error', { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true, code: 120 }],
813
'class-methods-use-this': 'off',
914
'import/no-extraneous-dependencies': 'off', // temporary disabled
15+
'@typescript-eslint/semi': ['error', 'never'],
16+
'object-curly-newline': 'off',
17+
'import/prefer-default-export': 'off',
18+
'@typescript-eslint/comma-dangle': 'off',
19+
'implicit-arrow-linebreak': 'off',
20+
'import/order': [
21+
1,
22+
{
23+
groups: [
24+
'external',
25+
'builtin',
26+
'internal',
27+
'sibling',
28+
'parent',
29+
'index',
30+
],
31+
pathGroups: [
32+
{
33+
pattern: 'desktopSrc/**',
34+
group: 'internal',
35+
position: 'after'
36+
},
37+
{
38+
pattern: 'uiSrc/**',
39+
group: 'internal',
40+
position: 'after'
41+
},
42+
{
43+
pattern: 'apiSrc/**',
44+
group: 'internal',
45+
position: 'after'
46+
},
47+
],
48+
warnOnUnassignedImports: true,
49+
pathGroupsExcludedImportTypes: ['builtin']
50+
},
51+
],
1052
},
1153
parserOptions: {
1254
project: './tsconfig.json',
55+
ecmaVersion: 2020,
56+
sourceType: 'module',
57+
createDefaultProgram: true,
1358
},
1459
ignorePatterns: [
1560
'redisinsight/ui',
61+
'redisinsight/api',
1662
],
17-
};
63+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ dll
5656
main.js
5757
main.js.map
5858
vendor
59+
redisinsight/main.js.LICENSE.txt
60+
redisinsight/main.prod.js.LICENSE.txt
61+
5962

6063
# E2E tests report
6164
/tests/e2e/report

configs/paths.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

configs/webpack.config.base.js renamed to configs/webpack.config.base.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import path from 'path';
21
import webpack from 'webpack';
3-
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
2+
import TsconfigPathsPlugins from 'tsconfig-paths-webpack-plugin';
3+
import webpackPaths from './webpack.paths';
44
import { dependencies as externals } from '../redisinsight/package.json';
55

6-
export default {
6+
const configuration: webpack.Configuration = {
77
externals: [...Object.keys(externals || {})],
88

9+
stats: 'errors-only',
10+
911
module: {
1012
rules: [
1113
{
@@ -22,28 +24,22 @@ export default {
2224
},
2325

2426
output: {
25-
path: path.join(__dirname, '..'),
26-
// commonjs2 https://github.com/webpack/webpack/issues/1114
27-
libraryTarget: 'commonjs2',
27+
path: webpackPaths.riPath,
28+
// https://github.com/webpack/webpack/issues/1114
29+
library: {
30+
type: 'commonjs2',
31+
},
2832
},
2933

3034
resolve: {
3135
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx', '.scss'],
32-
plugins: [
33-
new TsconfigPathsPlugin({
34-
configFile: path.join(__dirname, '..', 'tsconfig.json'),
35-
}),
36-
],
37-
alias: {
38-
src: path.resolve(__dirname, '../redisinsight/api/src'),
39-
apiSrc: path.resolve(__dirname, '../redisinsight/api/src'),
40-
uiSrc: path.resolve(__dirname, '../redisinsight/ui/src'),
41-
},
42-
modules: [path.join(__dirname, '../redisinsight/api'), 'node_modules'],
36+
modules: [webpackPaths.apiPath, 'node_modules'],
37+
plugins: [new TsconfigPathsPlugins()],
4338
},
4439

4540
plugins: [
4641
new webpack.EnvironmentPlugin({
42+
NODE_ENV: 'production',
4743
}),
4844

4945
new webpack.IgnorePlugin({
@@ -81,3 +77,5 @@ export default {
8177
}),
8278
],
8379
};
80+
81+
export default configuration;

configs/webpack.config.eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/* eslint import/no-unresolved: off, import/no-self-import: off */
33
require('@babel/register');
44

5-
module.exports = require('./webpack.config.renderer.dev.babel').default;
5+
module.exports = require('./webpack.config.renderer.dev').default;

configs/webpack.config.main.prod.babel.js renamed to configs/webpack.config.main.prod.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import path from 'path';
22
import webpack from 'webpack';
33
import { merge } from 'webpack-merge';
4-
import { toString } from 'lodash'
4+
import { toString } from 'lodash';
55
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
66
import baseConfig from './webpack.config.base';
77
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
88
import { version } from '../redisinsight/package.json';
9+
import webpackPaths from './webpack.paths';
910

1011
DeleteSourceMaps();
1112

@@ -23,19 +24,17 @@ export default merge(baseConfig, {
2324

2425
target: 'electron-main',
2526

26-
entry: './redisinsight/main.dev.ts',
27-
28-
resolve: {
29-
alias: {
30-
['apiSrc']: path.resolve(__dirname, '../redisinsight/api/src'),
31-
['src']: path.resolve(__dirname, '../redisinsight/api/src'),
32-
},
33-
extensions: ['.tsx', '.ts', '.js', '.jsx'],
27+
entry: {
28+
main: path.join(webpackPaths.desktopPath, 'index.ts'),
29+
preload: path.join(webpackPaths.desktopPath, 'preload.ts'),
3430
},
3531

3632
output: {
37-
path: path.join(__dirname, '../redisinsight'),
38-
filename: 'main.prod.js',
33+
path: webpackPaths.distMainPath,
34+
filename: '[name].js',
35+
library: {
36+
type: 'umd',
37+
},
3938
},
4039

4140
// optimization: {
@@ -46,10 +45,6 @@ export default merge(baseConfig, {
4645
// ],
4746
// },
4847

49-
// alias: {
50-
// 'apiSrc': path.resolve(__dirname, '../redisinsight/api/src/')
51-
// },
52-
5348
plugins: [
5449
new BundleAnalyzerPlugin({
5550
analyzerMode: process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled',
@@ -75,6 +70,10 @@ export default merge(baseConfig, {
7570
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
7671
: toString(30 * 1000), // 30 sec
7772
}),
73+
74+
new webpack.DefinePlugin({
75+
'process.type': '"browser"',
76+
}),
7877
],
7978

8079
/**

configs/webpack.config.main.stage.babel.js renamed to configs/webpack.config.main.stage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import webpack from 'webpack';
22
import { merge } from 'webpack-merge';
3+
import { toString } from 'lodash';
34
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
4-
import { toString } from 'lodash'
5-
import mainProdConfig from './webpack.config.main.prod.babel';
5+
import mainProdConfig from './webpack.config.main.prod';
66
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
77
import { version } from '../redisinsight/package.json';
88

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import path from 'path';
2+
import webpack from 'webpack';
3+
import { merge } from 'webpack-merge';
4+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
5+
import baseConfig from './webpack.config.base';
6+
import webpackPaths from './webpack.paths';
7+
8+
const configuration: webpack.Configuration = {
9+
devtool: 'inline-source-map',
10+
11+
mode: 'development',
12+
13+
target: 'electron-preload',
14+
15+
entry: path.join(webpackPaths.desktopPath, 'preload.ts'),
16+
17+
output: {
18+
path: webpackPaths.dllPath,
19+
filename: 'preload.js',
20+
library: {
21+
type: 'umd',
22+
},
23+
},
24+
25+
plugins: [
26+
new BundleAnalyzerPlugin({
27+
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
28+
}),
29+
30+
/**
31+
* Create global constants which can be configured at compile time.
32+
*
33+
* Useful for allowing different behaviour between development builds and
34+
* release builds
35+
*
36+
* NODE_ENV should be production so that modules do not perform certain
37+
* development checks
38+
*
39+
* By default, use 'development' as NODE_ENV. This can be overriden with
40+
* 'staging', for example, by changing the ENV variables in the npm scripts
41+
*/
42+
new webpack.EnvironmentPlugin({
43+
NODE_ENV: 'development',
44+
}),
45+
46+
new webpack.LoaderOptionsPlugin({
47+
debug: true,
48+
}),
49+
],
50+
51+
/**
52+
* Disables webpack processing of __dirname and __filename.
53+
* If you run the bundle in node.js it falls back to these values of node.js.
54+
* https://github.com/webpack/webpack/issues/2010
55+
*/
56+
node: {
57+
__dirname: false,
58+
__filename: false,
59+
},
60+
61+
watch: true,
62+
};
63+
64+
export default merge(baseConfig, configuration);
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import webpack from 'webpack';
22
import path from 'path';
33
import { merge } from 'webpack-merge';
4-
import { toString } from 'lodash'
54
import baseConfig from './webpack.config.base';
5+
import webpackPaths from './webpack.paths';
66
import { dependencies } from '../package.json';
77
import { dependencies as dependenciesApi } from '../redisinsight/package.json';
88

99
console.log('dependenciesApi', dependenciesApi);
1010

11-
const dist = path.join(__dirname, '../dll');
11+
const dist = webpackPaths.dllPath;
1212

1313
export default merge(baseConfig, {
14-
context: path.join(__dirname, '..'),
14+
context: webpackPaths.rootPath,
1515

1616
devtool: 'eval',
1717

@@ -24,17 +24,19 @@ export default merge(baseConfig, {
2424
/**
2525
* Use `module` from `webpack.config.renderer.dev.js`
2626
*/
27-
module: require('./webpack.config.renderer.dev.babel').default.module,
27+
module: require('./webpack.config.renderer.dev').default.module,
2828

2929
entry: {
3030
renderer: [...Object.keys(dependencies || {}), ...Object.keys(dependenciesApi || {})],
3131
},
3232

3333
output: {
34-
library: 'renderer',
3534
path: dist,
3635
filename: '[name].dev.dll.js',
37-
libraryTarget: 'var',
36+
library: {
37+
name: 'renderer',
38+
type: 'var',
39+
},
3840
},
3941

4042
stats: 'errors-only',
@@ -47,29 +49,16 @@ export default merge(baseConfig, {
4749

4850
new webpack.EnvironmentPlugin({
4951
NODE_ENV: 'development',
50-
APP_ENV: 'electron',
51-
API_PREFIX: 'api',
52-
BASE_API_URL: 'http://localhost',
53-
RESOURCES_BASE_URL: 'http://localhost',
54-
SCAN_COUNT_DEFAULT: '500',
55-
SCAN_TREE_COUNT_DEFAULT: '10000',
56-
PIPELINE_COUNT_DEFAULT: '5',
57-
SEGMENT_WRITE_KEY:
58-
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
59-
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
60-
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
61-
: toString(30 * 1000), // 30 sec
6252
}),
6353

6454
new webpack.LoaderOptionsPlugin({
6555
debug: true,
6656
options: {
67-
context: path.join(__dirname, '..'),
57+
context: webpackPaths.desktopPath,
6858
output: {
69-
path: path.join(__dirname, '../dll'),
59+
path: webpackPaths.dllPath,
7060
},
7161
},
7262
}),
73-
7463
],
7564
});

0 commit comments

Comments
 (0)