From 1b2fa075850fb4debc7e2106e07885d4286f05a8 Mon Sep 17 00:00:00 2001 From: Lutz Roeder Date: Thu, 1 Feb 2024 18:32:10 -0800 Subject: [PATCH] Electron Forge support (#632) --- .gitignore | 1 + package.js | 38 ++++++++++++++++++++++-- package.json | 3 ++ publish/forge.config.js | 65 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 publish/forge.config.js diff --git a/.gitignore b/.gitignore index c1020df2ab..bd0362a785 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store .DS_Store? dist/* +out/* node_modules/* third_party/* package-lock.json diff --git a/package.js b/package.js index b40fa41e4a..59aeb5ab81 100644 --- a/package.js +++ b/package.js @@ -91,11 +91,12 @@ const unlink = async (dir, filter) => { await Promise.all(promises); }; -const exec = async (command, encoding) => { +const exec = async (command, encoding, cwd) => { + cwd = cwd || dirname(); if (encoding) { - return child_process.execSync(command, { cwd: dirname(), encoding: encoding }); + return child_process.execSync(command, { cwd: cwd, encoding: encoding }); } - child_process.execSync(command, { cwd: dirname(), stdio: [ 0,1,2 ] }); + child_process.execSync(command, { cwd: cwd, stdio: [ 0,1,2 ] }); return ''; /* return new Promise((resolve, reject) => { @@ -579,6 +580,36 @@ const coverage = async () => { await exec('nyc --instrument npx electron ./dist/nyc'); }; +const forge = async() => { + const command = read(); + switch (command) { + case 'install': { + await exec('npm install @electron-forge/cli@7.2.0'); + await exec('npm install @electron-forge/core@7.2.0'); + await exec('npm install @electron-forge/maker-snap@7.2.0'); + await exec('npm install @electron-forge/maker-dmg@7.2.0'); + await exec('npm install @electron-forge/maker-zip@7.2.0'); + break; + } + case 'build': { + const cwd = path.join(dirname(), '..', 'forge'); + const node_modules = path.join(cwd, 'node_modules'); + const links = path.join(cwd, '.links'); + const exists = await access(node_modules); + if (!exists) { + await exec('yarn', null, cwd); + } + await exec('yarn build', null, cwd); + await exec('yarn link:prepare', null, cwd); + await exec(`yarn link @electron-forge/core --link-folder=${links}`); + break; + } + default: { + throw new Error(`Unsupported forge command ${command}.`); + } + } +}; + const analyze = async () => { const exists = await access('third_party/tools/codeql'); if (!exists) { @@ -630,6 +661,7 @@ const next = async () => { case 'pull': await pull(); break; case 'analyze': await analyze(); break; case 'coverage': await coverage(); break; + case 'forge': await forge(); break; default: throw new Error(`Unsupported task '${task}'.`); } } catch (err) { diff --git a/package.json b/package.json index 17b83356bf..e9eb8a300e 100755 --- a/package.json +++ b/package.json @@ -104,6 +104,9 @@ "report-dir": "dist/nyc/coverage", "temp-dir": "dist/nyc/.nyc_output" }, + "config": { + "forge": "publish/forge.config.js" + }, "build": { "appId": "com.lutzroeder.netron", "productName": "Netron", diff --git a/publish/forge.config.js b/publish/forge.config.js new file mode 100644 index 0000000000..15b2623f46 --- /dev/null +++ b/publish/forge.config.js @@ -0,0 +1,65 @@ + +/* +const APPLE_API_KEY_ID = process.env.APPLE_API_KEY_ID; +const APPLE_API_KEY_ISSUER_ID = process.env.APPLE_API_KEY_ISSUER_ID; +*/ + +export default { + outDir: 'dist', + packagerConfig: { + icon: "publish/icon", + dir: [ + 'source' + ], + ignore: [ + "publish", + "third_party", + "test", + "tools" + ], + /* + osxNotarize: { + tool: 'notarytool', + appleApiKey: `~/.private_keys/AuthKey_${APPLE_API_KEY_ID}.p8`, + appleApiKeyId: APPLE_API_KEY_ID, + appleApiIssuer: APPLE_API_KEY_ISSUER_ID + }, + */ + asar: true + }, + /* + makeTargets: { + win32: ['nsis'], + darwin: ['dmg', 'zip'], + linux: ['snap'], + }, + */ + makers: [ + { + name: '@electron-forge/maker-zip', + config: { + platforms: [ 'darwin' ], + // name: "${name}-${version}-mac.zip" + } + }, + { + name: '@electron-forge/maker-dmg', + config: { + background: './publish/background.png', + /* eslint-disable no-template-curly-in-string */ + name: "Netron-${version}" + /* eslint-enable no-template-curly-in-string */ + } + } + ], + publishers: [ + { + "name": "@electron-forge/publisher-github", + "config": {} + }, + { + "name": "@electron-forge/publisher-snapcraft", + "config": {} + } + ] +};