Skip to content

Commit

Permalink
Generate entry file in Forge's generateAssets step (Automattic#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-jackson authored Mar 19, 2024
1 parent b6de6f7 commit 5f48ee8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
13 changes: 13 additions & 0 deletions forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MakerZIP } from '@electron-forge/maker-zip';
import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives';
import { WebpackPlugin } from '@electron-forge/plugin-webpack';
import ForgeExternalsPlugin from '@timfish/forge-externals-plugin';
import ejs from 'ejs';
import { isErrnoException } from './src/lib/is-errno-exception';
import { mainConfig } from './webpack.main.config';
import { rendererConfig } from './webpack.renderer.config';
Expand Down Expand Up @@ -98,6 +99,18 @@ const config: ForgeConfig = {
new ForgeExternalsPlugin( { externals: Object.keys( mainConfig.externals ?? {} ) } ),
],
hooks: {
generateAssets: async () => {
console.log( 'Building the HTML entry file ...' );

const REACT_DEV_TOOLS =
process.env.REACT_DEV_TOOLS === 'true' || process.env.REACT_DEV_TOOLS === '1';

const ejsTemplate = fs.readFileSync( './src/index.ejs', 'utf8' );
const data = { REACT_DEV_TOOLS };
const renderedHtml = ejs.render( ejsTemplate, data );
fs.mkdirSync( './dist', { recursive: true } );
fs.writeFileSync( './dist/index.html', renderedHtml );
},
prePackage: async () => {
console.log( "Ensuring latest WordPress zip isn't included in production build ..." );

Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
"directory": "/"
},
"scripts": {
"prestart": "node ./scripts/build-entry-html.mjs",
"start": "electron-forge start",
"start-wayland": "electron-forge start -- --enable-features=UseOzonePlatform --ozone-platform=wayland .",
"postinstall": "node ./scripts/download-wp.mjs",
"prepackage": "node ./scripts/build-entry-html.mjs",
"package": "electron-forge package",
"make": "electron-forge make",
"make:macos": "SKIP_DMG=true electron-forge make --arch=universal --platform=darwin",
Expand Down Expand Up @@ -45,6 +43,7 @@
"@testing-library/user-event": "^14.5.2",
"@timfish/forge-externals-plugin": "^0.2.1",
"@types/archiver": "^6.0.2",
"@types/ejs": "^3.1.5",
"@types/jest": "^29.5.11",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
Expand Down
11 changes: 0 additions & 11 deletions scripts/build-entry-html.mjs

This file was deleted.

0 comments on commit 5f48ee8

Please sign in to comment.