Skip to content

Commit 992be09

Browse files
authored
refactor: major project structure update (#1564)
* refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * build: universal only Signed-off-by: Adam Setch <[email protected]> * refactor: split code into main and renderer modules, adopt TS for main, and improve webpack process for bundling Signed-off-by: Adam Setch <[email protected]> * build: remove resize polyfill dep Signed-off-by: Adam Setch <[email protected]> * build: macos dist Signed-off-by: Adam Setch <[email protected]> * build: macos dist Signed-off-by: Adam Setch <[email protected]> * build: fix order of source maps Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent 3e549c7 commit 992be09

File tree

203 files changed

+2047
-887
lines changed

Some content is hidden

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

203 files changed

+2047
-887
lines changed

.github/workflows/build.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
cache: 'pnpm'
2323
- run: pnpm install
2424
- run: pnpm build
25-
- run: pnpm make:macos --publish=never -c.mac.identity=null
25+
- run: pnpm prepare:remove-source-maps
26+
- run: pnpm package:macos --publish=never -c.mac.identity=null
2627
env:
2728
CSC_LINK: ${{ secrets.mac_certs }}
2829
CSC_KEY_PASSWORD: ${{ secrets.mac_certs_password }}
@@ -47,7 +48,8 @@ jobs:
4748
cache: 'pnpm'
4849
- run: pnpm install
4950
- run: pnpm build
50-
- run: pnpm make:win --publish=never
51+
- run: pnpm prepare:remove-source-maps
52+
- run: pnpm package:win --publish=never
5153
- name: Clean up builds
5254
run: Remove-Item dist/win-unpacked -Recurse
5355
- uses: actions/upload-artifact@v4
@@ -69,7 +71,8 @@ jobs:
6971
cache: 'pnpm'
7072
- run: pnpm install
7173
- run: pnpm build
72-
- run: pnpm make:linux --publish=never
74+
- run: pnpm prepare:remove-source-maps
75+
- run: pnpm package:linux --publish=never
7376
- name: Clean up builds
7477
run: rm -rfv dist/linux-unpacked
7578
- uses: actions/upload-artifact@v4

.github/workflows/release.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
env:
2727
OAUTH_CLIENT_ID: ${{ secrets.oauth_client_id }}
2828
OAUTH_CLIENT_SECRET: ${{ secrets.oauth_client_secret }}
29-
- run: pnpm make:macos --publish onTagOrDraft
29+
- run: pnpm prepare:remove-source-maps
30+
- run: pnpm package:macos --publish onTagOrDraft
3031
env:
3132
APPLEID_USERNAME: ${{ secrets.appleid_username }}
3233
APPLEID_PASSWORD: ${{ secrets.appleid_password }}
@@ -57,7 +58,8 @@ jobs:
5758
env:
5859
OAUTH_CLIENT_ID: ${{ secrets.oauth_client_id }}
5960
OAUTH_CLIENT_SECRET: ${{ secrets.oauth_client_secret }}
60-
- run: pnpm make:win --publish onTagOrDraft
61+
- run: pnpm prepare:remove-source-maps
62+
- run: pnpm package:win --publish onTagOrDraft
6163
env:
6264
GH_TOKEN: ${{ secrets.github_token }}
6365
- uses: actions/upload-artifact@v4
@@ -82,7 +84,8 @@ jobs:
8284
env:
8385
OAUTH_CLIENT_ID: ${{ secrets.oauth_client_id }}
8486
OAUTH_CLIENT_SECRET: ${{ secrets.oauth_client_secret }}
85-
- run: pnpm make:linux --publish onTagOrDraft
87+
- run: pnpm prepare:remove-source-maps
88+
- run: pnpm package:linux --publish onTagOrDraft
8689
env:
8790
GH_TOKEN: ${{ secrets.github_token }}
8891
- uses: actions/upload-artifact@v4

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Mac Files
2-
.DS_Store
3-
41
# Build files
52
dist/
63
build/
@@ -23,3 +20,6 @@ npm-debug.log*
2320
# Temporary folders
2421
tmp/
2522
temp/
23+
24+
# Mac Files
25+
.DS_Store

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# Settings as per electron-builder note: https://www.electron.build/index.html#note-for-pnpm
12
node-linker=hoisted
23
shamefully-hoist=true

config/webpack.config.common.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type webpack from 'webpack';
2+
3+
const configuration: webpack.Configuration = {
4+
module: {
5+
rules: [
6+
{
7+
test: /\.(js|ts|tsx)?$/,
8+
use: 'ts-loader',
9+
exclude: /node_modules/,
10+
},
11+
],
12+
},
13+
14+
resolve: {
15+
extensions: ['.tsx', '.ts', '.js'],
16+
},
17+
18+
node: {
19+
__dirname: false,
20+
__filename: false,
21+
},
22+
};
23+
24+
export default configuration;

config/webpack.config.main.base.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import path from 'node:path';
2+
import type webpack from 'webpack';
3+
import { merge } from 'webpack-merge';
4+
import baseConfig from './webpack.config.common';
5+
import webpackPaths from './webpack.paths';
6+
7+
const configuration: webpack.Configuration = {
8+
devtool: 'inline-source-map',
9+
10+
mode: 'development',
11+
12+
target: 'electron-main',
13+
14+
entry: [path.join(webpackPaths.srcMainPath, 'main.ts')],
15+
16+
output: {
17+
path: webpackPaths.buildPath,
18+
filename: 'main.js',
19+
library: {
20+
type: 'umd',
21+
},
22+
},
23+
};
24+
25+
export default merge(baseConfig, configuration);

config/webpack.config.main.prod.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import TerserPlugin from 'terser-webpack-plugin';
2+
import type webpack from 'webpack';
3+
import { merge } from 'webpack-merge';
4+
import baseConfig from './webpack.config.main.base';
5+
6+
const configuration: webpack.Configuration = {
7+
devtool: 'source-map',
8+
9+
mode: 'production',
10+
11+
optimization: {
12+
minimize: true,
13+
minimizer: [new TerserPlugin()],
14+
},
15+
};
16+
17+
export default merge(baseConfig, configuration);
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import path from 'node:path';
2+
import CopyWebpackPlugin from 'copy-webpack-plugin';
3+
import HtmlWebpackPlugin from 'html-webpack-plugin';
4+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
5+
import webpack from 'webpack';
6+
import { merge } from 'webpack-merge';
7+
import baseConfig from './webpack.config.common';
8+
import webpackPaths from './webpack.paths';
9+
10+
const configuration: webpack.Configuration = {
11+
devtool: 'inline-source-map',
12+
13+
mode: 'development',
14+
15+
target: 'electron-renderer',
16+
17+
entry: [path.join(webpackPaths.srcRendererPath, 'index.tsx')],
18+
19+
output: {
20+
path: webpackPaths.buildPath,
21+
filename: 'renderer.js',
22+
library: {
23+
type: 'umd',
24+
},
25+
},
26+
27+
module: {
28+
rules: [
29+
{
30+
test: /\.css$/,
31+
use: [
32+
MiniCssExtractPlugin.loader, // Extract CSS into a separate file
33+
'css-loader', // Translates CSS into CommonJS
34+
'postcss-loader', // Automatically uses the postcss.config.js file
35+
],
36+
},
37+
],
38+
},
39+
40+
plugins: [
41+
// Development Keys - See README.md
42+
new webpack.EnvironmentPlugin({
43+
OAUTH_CLIENT_ID: '3fef4433a29c6ad8f22c',
44+
OAUTH_CLIENT_SECRET: '9670de733096c15322183ff17ed0fc8704050379',
45+
}),
46+
47+
// Extract CSS into a separate file
48+
new MiniCssExtractPlugin({
49+
filename: 'styles.css', // Output file for the CSS
50+
}),
51+
52+
// Generate HTML file with script and link tags injected
53+
new HtmlWebpackPlugin({
54+
filename: path.join('index.html'),
55+
template: path.join(webpackPaths.srcRendererPath, 'index.html'),
56+
minify: {
57+
collapseWhitespace: true,
58+
removeAttributeQuotes: true,
59+
removeComments: true,
60+
},
61+
isBrowser: false,
62+
}),
63+
64+
// Twemoji SVGs for Emoji parsing
65+
new CopyWebpackPlugin({
66+
patterns: [
67+
{
68+
from: path.join(
69+
webpackPaths.nodeModulesPath,
70+
'@discordapp/twemoji',
71+
'dist',
72+
'svg',
73+
),
74+
to: 'images/twemoji',
75+
},
76+
],
77+
}),
78+
],
79+
};
80+
81+
export default merge(baseConfig, configuration);
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
2+
import TerserPlugin from 'terser-webpack-plugin';
3+
import type webpack from 'webpack';
4+
import { merge } from 'webpack-merge';
5+
import baseConfig from './webpack.config.renderer.base';
6+
7+
const configuration: webpack.Configuration = {
8+
devtool: 'source-map',
9+
10+
mode: 'production',
11+
12+
optimization: {
13+
minimize: true,
14+
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
15+
},
16+
};
17+
18+
export default merge(baseConfig, configuration);

config/webpack.paths.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from 'node:path';
2+
3+
const rootPath = path.join(__dirname, '..');
4+
5+
const nodeModulesPath = path.join(rootPath, 'node_modules');
6+
7+
const srcPath = path.join(rootPath, 'src');
8+
const srcMainPath = path.join(srcPath, 'main');
9+
const srcRendererPath = path.join(srcPath, 'renderer');
10+
11+
const buildPath = path.join(rootPath, 'build');
12+
13+
const distPath = path.join(rootPath, 'dist');
14+
15+
export default {
16+
rootPath,
17+
nodeModulesPath,
18+
srcPath,
19+
srcMainPath,
20+
srcRendererPath,
21+
buildPath,
22+
distPath,
23+
};

jest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Config } from 'jest';
22

33
const config: Config = {
44
preset: 'ts-jest',
5-
setupFiles: ['<rootDir>/src/__helpers__/setupEnvVars.js'],
5+
setupFiles: ['<rootDir>/src/renderer/__helpers__/setupEnvVars.js'],
66
testEnvironment: 'jsdom',
77
collectCoverage: true,
88
moduleNameMapper: {

0 commit comments

Comments
 (0)