Initial commit

Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com>
Co-Authored-By: Johan  <4934465+joolsus@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
This commit is contained in:
Michael Cartner
2024-01-26 11:52:55 +01:00
commit b9c60b07dc
2789 changed files with 868795 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import { execSync } from 'child_process';
import { valueToBoolean } from '../../../scripts/helper';
import { BuildTarget, getDistPlatform } from './platform/build-platforms';
(async function () {
// Inputs
const DISABLE_SIGNING = valueToBoolean(process.env.DISABLE_SIGNING);
const TARGET_PLATFORM = process.env.TARGET_PLATFORM;
if (!TARGET_PLATFORM) throw new Error('TARGET_PLATFORM is falsy');
// Variables
const [platform, arch] = TARGET_PLATFORM.trim().split('-');
// @ts-expect-error TODO: Add validation on the input.
const target: BuildTarget = { platform, arch };
// Debug Configuration
console.log('@ -> packages/noodl-editor/scripts/build.ts');
console.log('--- Configuration');
console.log('> DISABLE_SIGNING: ', DISABLE_SIGNING);
console.log('> TARGET_PLATFORM: ', TARGET_PLATFORM);
console.log('---');
// Build Renderer
console.log("--- Run webpack 'webpack.renderer.production.js' ...");
execSync('npx webpack --config=webpackconfigs/webpack.renderer.production.js', {
stdio: 'inherit',
env: process.env
});
console.log('--- done!');
// Build Main
console.log("--- Run webpack 'webpack.main.production.js' ...");
execSync('npx webpack --config=webpackconfigs/webpack.main.production.js', {
stdio: 'inherit',
env: process.env
});
console.log('--- done!');
const platformName = getDistPlatform(target.platform);
const args = [`--${platformName}`, `--${target.arch}`].join(' ');
console.log(`--- Run: 'npx electron-builder ${args}' ...`);
execSync('npx electron-builder ' + args, {
stdio: [0, 1, 2],
env: Object.assign(
DISABLE_SIGNING
? {}
: {
// CSC_NAME: 'Add signing name here'
},
process.env
)
});
})();

View File

@@ -0,0 +1,28 @@
import { build, Platform } from 'electron-builder';
import { BuildTarget } from './build-platforms';
const config = require('../package.json').build;
function createTarget(buildTarget: BuildTarget) {
switch (buildTarget.platform) {
case 'darwin':
return Platform.MAC.createTarget(undefined, buildTarget.arch as any);
case 'win32':
return Platform.WINDOWS.createTarget();
case 'linux':
return Platform.LINUX.createTarget(undefined, buildTarget.arch as any);
default:
const targetName = `${buildTarget.platform}-${buildTarget.arch}`;
throw 'Unsupported platform: ' + targetName;
}
}
export function execElectronBuilder(buildTarget: BuildTarget) {
return build({
targets: createTarget(buildTarget),
config
});
}

View File

@@ -0,0 +1,45 @@
import { ArchType } from 'builder-util';
export interface BuildTarget {
platform: NodeJS.Platform;
arch: ArchType;
}
export function isGitHubActions() {
return process.env.GITHUB_ACTIONS === 'true';
}
export function getDistArchitecture(): 'arm64' | 'x64' {
// If a specific npm_config_arch is set, we use that one instead of the OS arch (to support cross compilation)
if (process.env.npm_config_arch === 'arm64' || process.env.npm_config_arch === 'x64') {
return process.env.npm_config_arch;
}
if (process.arch === 'arm64') {
return 'arm64';
}
// TODO: Check if it's x64 running on an arm64 Windows with IsWow64Process2
// More info: https://www.rudyhuyn.com/blog/2017/12/13/how-to-detect-that-your-x86-application-runs-on-windows-on-arm/
// Right now (March 3, 2021) is not very important because support for x64
// apps on an arm64 Windows is experimental. See:
// https://blogs.windows.com/windows-insider/2020/12/10/introducing-x64-emulation-in-preview-for-windows-10-on-arm-pcs-to-the-windows-insider-program/
return 'x64';
}
export function getDistPlatform(targetPlatform: string): 'win' | 'linux' | 'mac' {
if (targetPlatform === 'win32') {
return 'win';
}
if (targetPlatform === 'linux') {
return 'linux';
}
if (targetPlatform === 'darwin') {
return 'mac';
}
throw new Error(`Unsupported platform: ${targetPlatform}`);
}