Skip to content

Commit

Permalink
refactor: major project structure update (#1564)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
setchy authored Oct 4, 2024
1 parent 3e549c7 commit 992be09
Show file tree
Hide file tree
Showing 203 changed files with 2,047 additions and 887 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm build
- run: pnpm make:macos --publish=never -c.mac.identity=null
- run: pnpm prepare:remove-source-maps
- run: pnpm package:macos --publish=never -c.mac.identity=null
env:
CSC_LINK: ${{ secrets.mac_certs }}
CSC_KEY_PASSWORD: ${{ secrets.mac_certs_password }}
Expand All @@ -47,7 +48,8 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm build
- run: pnpm make:win --publish=never
- run: pnpm prepare:remove-source-maps
- run: pnpm package:win --publish=never
- name: Clean up builds
run: Remove-Item dist/win-unpacked -Recurse
- uses: actions/upload-artifact@v4
Expand All @@ -69,7 +71,8 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm build
- run: pnpm make:linux --publish=never
- run: pnpm prepare:remove-source-maps
- run: pnpm package:linux --publish=never
- name: Clean up builds
run: rm -rfv dist/linux-unpacked
- uses: actions/upload-artifact@v4
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
env:
OAUTH_CLIENT_ID: ${{ secrets.oauth_client_id }}
OAUTH_CLIENT_SECRET: ${{ secrets.oauth_client_secret }}
- run: pnpm make:macos --publish onTagOrDraft
- run: pnpm prepare:remove-source-maps
- run: pnpm package:macos --publish onTagOrDraft
env:
APPLEID_USERNAME: ${{ secrets.appleid_username }}
APPLEID_PASSWORD: ${{ secrets.appleid_password }}
Expand Down Expand Up @@ -57,7 +58,8 @@ jobs:
env:
OAUTH_CLIENT_ID: ${{ secrets.oauth_client_id }}
OAUTH_CLIENT_SECRET: ${{ secrets.oauth_client_secret }}
- run: pnpm make:win --publish onTagOrDraft
- run: pnpm prepare:remove-source-maps
- run: pnpm package:win --publish onTagOrDraft
env:
GH_TOKEN: ${{ secrets.github_token }}
- uses: actions/upload-artifact@v4
Expand All @@ -82,7 +84,8 @@ jobs:
env:
OAUTH_CLIENT_ID: ${{ secrets.oauth_client_id }}
OAUTH_CLIENT_SECRET: ${{ secrets.oauth_client_secret }}
- run: pnpm make:linux --publish onTagOrDraft
- run: pnpm prepare:remove-source-maps
- run: pnpm package:linux --publish onTagOrDraft
env:
GH_TOKEN: ${{ secrets.github_token }}
- uses: actions/upload-artifact@v4
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Mac Files
.DS_Store

# Build files
dist/
build/
Expand All @@ -23,3 +20,6 @@ npm-debug.log*
# Temporary folders
tmp/
temp/

# Mac Files
.DS_Store
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Settings as per electron-builder note: https://www.electron.build/index.html#note-for-pnpm
node-linker=hoisted
shamefully-hoist=true
24 changes: 24 additions & 0 deletions config/webpack.config.common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type webpack from 'webpack';

const configuration: webpack.Configuration = {
module: {
rules: [
{
test: /\.(js|ts|tsx)?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},

resolve: {
extensions: ['.tsx', '.ts', '.js'],
},

node: {
__dirname: false,
__filename: false,
},
};

export default configuration;
25 changes: 25 additions & 0 deletions config/webpack.config.main.base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import path from 'node:path';
import type webpack from 'webpack';
import { merge } from 'webpack-merge';
import baseConfig from './webpack.config.common';
import webpackPaths from './webpack.paths';

const configuration: webpack.Configuration = {
devtool: 'inline-source-map',

mode: 'development',

target: 'electron-main',

entry: [path.join(webpackPaths.srcMainPath, 'main.ts')],

output: {
path: webpackPaths.buildPath,
filename: 'main.js',
library: {
type: 'umd',
},
},
};

export default merge(baseConfig, configuration);
17 changes: 17 additions & 0 deletions config/webpack.config.main.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import TerserPlugin from 'terser-webpack-plugin';
import type webpack from 'webpack';
import { merge } from 'webpack-merge';
import baseConfig from './webpack.config.main.base';

const configuration: webpack.Configuration = {
devtool: 'source-map',

mode: 'production',

optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
};

export default merge(baseConfig, configuration);
81 changes: 81 additions & 0 deletions config/webpack.config.renderer.base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import path from 'node:path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import baseConfig from './webpack.config.common';
import webpackPaths from './webpack.paths';

const configuration: webpack.Configuration = {
devtool: 'inline-source-map',

mode: 'development',

target: 'electron-renderer',

entry: [path.join(webpackPaths.srcRendererPath, 'index.tsx')],

output: {
path: webpackPaths.buildPath,
filename: 'renderer.js',
library: {
type: 'umd',
},
},

module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader, // Extract CSS into a separate file
'css-loader', // Translates CSS into CommonJS
'postcss-loader', // Automatically uses the postcss.config.js file
],
},
],
},

plugins: [
// Development Keys - See README.md
new webpack.EnvironmentPlugin({
OAUTH_CLIENT_ID: '3fef4433a29c6ad8f22c',
OAUTH_CLIENT_SECRET: '9670de733096c15322183ff17ed0fc8704050379',
}),

// Extract CSS into a separate file
new MiniCssExtractPlugin({
filename: 'styles.css', // Output file for the CSS
}),

// Generate HTML file with script and link tags injected
new HtmlWebpackPlugin({
filename: path.join('index.html'),
template: path.join(webpackPaths.srcRendererPath, 'index.html'),
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
},
isBrowser: false,
}),

// Twemoji SVGs for Emoji parsing
new CopyWebpackPlugin({
patterns: [
{
from: path.join(
webpackPaths.nodeModulesPath,
'@discordapp/twemoji',
'dist',
'svg',
),
to: 'images/twemoji',
},
],
}),
],
};

export default merge(baseConfig, configuration);
18 changes: 18 additions & 0 deletions config/webpack.config.renderer.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import type webpack from 'webpack';
import { merge } from 'webpack-merge';
import baseConfig from './webpack.config.renderer.base';

const configuration: webpack.Configuration = {
devtool: 'source-map',

mode: 'production',

optimization: {
minimize: true,
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
};

export default merge(baseConfig, configuration);
23 changes: 23 additions & 0 deletions config/webpack.paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from 'node:path';

const rootPath = path.join(__dirname, '..');

const nodeModulesPath = path.join(rootPath, 'node_modules');

const srcPath = path.join(rootPath, 'src');
const srcMainPath = path.join(srcPath, 'main');
const srcRendererPath = path.join(srcPath, 'renderer');

const buildPath = path.join(rootPath, 'build');

const distPath = path.join(rootPath, 'dist');

export default {
rootPath,
nodeModulesPath,
srcPath,
srcMainPath,
srcRendererPath,
buildPath,
distPath,
};
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest',
setupFiles: ['<rootDir>/src/__helpers__/setupEnvVars.js'],
setupFiles: ['<rootDir>/src/renderer/__helpers__/setupEnvVars.js'],
testEnvironment: 'jsdom',
collectCoverage: true,
moduleNameMapper: {
Expand Down
Loading

0 comments on commit 992be09

Please sign in to comment.