Skip to content

Commit

Permalink
apply suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JKobrynski committed Mar 21, 2024
1 parent cc93841 commit e059dd1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
5 changes: 4 additions & 1 deletion config/webpack/CustomVersionFilePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class CustomVersionFilePlugin {
const versionPath = path.join(__dirname, '/../../dist/version.json');
fs.mkdir(path.dirname(versionPath), {recursive: true}, (dirErr) => {
if (dirErr) {
console.error('Error creating version.json directory', dirErr);
return;
}
fs.writeFile(versionPath, JSON.stringify({version: APP_VERSION}), {encoding: 'utf8'}, () => {});
fs.writeFile(versionPath, JSON.stringify({version: APP_VERSION}), {encoding: 'utf8'}, (err) => {
console.error('Error writing to version.json', err);
});
});
});
}
Expand Down
6 changes: 1 addition & 5 deletions config/webpack/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type {Configuration} from 'webpack';

type EnvFile = {
envFile?: string;
platform?: 'web' | 'desktop';
};

type WebpackConfig = Configuration;

// eslint-disable-next-line import/prefer-default-export
export type {EnvFile, WebpackConfig};
export type {EnvFile};
4 changes: 2 additions & 2 deletions config/webpack/webpack.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import dotenv from 'dotenv';
import fs from 'fs';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
import type {Configuration} from 'webpack';
import {DefinePlugin, EnvironmentPlugin, IgnorePlugin, ProvidePlugin} from 'webpack';
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer';
import CustomVersionFilePlugin from './CustomVersionFilePlugin';
import type {WebpackConfig} from './types';

// require is necessary, there are no types for this package and the declaration file can't be seen by the build process which causes an error.
const PreloadWebpackPlugin = require('@vue/preload-webpack-plugin');
Expand Down Expand Up @@ -47,7 +47,7 @@ function mapEnvToLogoSuffix(envFile: string): string {
/**
* Get a production grade config for web or desktop
*/
const getCommonConfig = ({envFile = '.env', platform = 'web'}): WebpackConfig => ({
const getCommonConfig = ({envFile = '.env', platform = 'web'}): Configuration => ({
mode: 'production',
devtool: 'source-map',
entry: {
Expand Down
5 changes: 2 additions & 3 deletions config/webpack/webpack.desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import type {Configuration} from 'webpack';
import webpack from 'webpack';
// eslint-disable-next-line @dword-design/import-alias/prefer-alias, import/no-relative-packages -- alias imports don't work for webpack
import {dependencies as desktopDependencies} from '../../desktop/package.json';
import type {WebpackConfig} from './types';
import type {EnvFile} from './types';
import getCommonConfig from './webpack.common';
import type {EnvFile} from './webpack.dev';

/**
* Desktop creates 2 configurations in parallel
* 1. electron-main - the core that serves the app content
* 2. web - the app content that would be rendered in electron
* Everything is placed in desktop/dist and ready for packaging
*/
const getConfig = (env: EnvFile = {}): WebpackConfig[] => {
const getConfig = (env: EnvFile = {}): Configuration[] => {
const rendererConfig = getCommonConfig({...env, platform: 'desktop'});
const outputPath = path.resolve(__dirname, '../../desktop/dist');

Expand Down
13 changes: 6 additions & 7 deletions config/webpack/webpack.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
import path from 'path';
import portfinder from 'portfinder';
import {TimeAnalyticsPlugin} from 'time-analytics-webpack-plugin';
import type webpack from 'webpack';
import type {Configuration} from 'webpack';
import {DefinePlugin} from 'webpack';
import type * as webpackDevServer from 'webpack-dev-server';
import type {Configuration as DevServerConfiguration} from 'webpack-dev-server';
import {merge} from 'webpack-merge';
import type {EnvFile, WebpackConfig} from './types';
import type {EnvFile} from './types';
import getCommonConfig from './webpack.common';

const BASE_PORT = 8082;

/**
* Configuration for the local dev server
*/
const getConfig = (env: EnvFile = {}): Promise<WebpackConfig> =>
const getConfig = (env: EnvFile = {}): Promise<Configuration> =>
portfinder.getPortPromise({port: BASE_PORT}).then((port) => {
// Check if the USE_WEB_PROXY variable has been provided
// and rewrite any requests to the local proxy server
const proxySettings: Pick<webpackDevServer.Configuration, 'proxy'> =
const proxySettings: Pick<DevServerConfiguration, 'proxy'> =
process.env.USE_WEB_PROXY === 'false'
? {}
: {
Expand Down Expand Up @@ -76,10 +76,9 @@ const getConfig = (env: EnvFile = {}): Promise<WebpackConfig> =>
/([\\/]node_modules[\\/](?!react-native-onyx))/,
],
},
} as webpack.Configuration);
});

return TimeAnalyticsPlugin.wrap(config);
});

export default getConfig;
export type {EnvFile};
3 changes: 1 addition & 2 deletions scripts/build-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ npx webpack --config config/webpack/webpack.desktop.ts --env envFile=$ENV_FILE
title "Building Desktop App Archive Using Electron"
info ""
shift 1
# npx electron-builder --config config/electronBuilder.config.js --publish always "$@"
npx electron-builder --config config/electronBuilder.config.js "$@"
npx electron-builder --config config/electronBuilder.config.js --publish always "$@"

0 comments on commit e059dd1

Please sign in to comment.