diff --git a/forge.config.ts b/forge.config.ts index 23813c091..32ddb0647 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -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'; @@ -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 ..." ); diff --git a/package-lock.json b/package-lock.json index efdd5f4e6..40b81496c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,6 +48,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", @@ -5036,6 +5037,12 @@ "@types/node": "*" } }, + "node_modules/@types/ejs": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@types/ejs/-/ejs-3.1.5.tgz", + "integrity": "sha512-nv+GSx77ZtXiJzwKdsASqi+YQ5Z7vwHsTP0JY2SiQgjGckkBRKZnk8nIM+7oUZ1VCtuTz0+By4qVR7fqzp/Dfg==", + "dev": true + }, "node_modules/@types/eslint": { "version": "8.56.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.2.tgz", @@ -23848,6 +23855,12 @@ "@types/node": "*" } }, + "@types/ejs": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@types/ejs/-/ejs-3.1.5.tgz", + "integrity": "sha512-nv+GSx77ZtXiJzwKdsASqi+YQ5Z7vwHsTP0JY2SiQgjGckkBRKZnk8nIM+7oUZ1VCtuTz0+By4qVR7fqzp/Dfg==", + "dev": true + }, "@types/eslint": { "version": "8.56.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.2.tgz", diff --git a/package.json b/package.json index 7b37218bc..9227e0682 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/scripts/build-entry-html.mjs b/scripts/build-entry-html.mjs deleted file mode 100644 index 31b04fc9f..000000000 --- a/scripts/build-entry-html.mjs +++ /dev/null @@ -1,11 +0,0 @@ -import fs from 'fs'; -import ejs from 'ejs'; - -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 );