Electron Forge CLI is a complete command-line tool for building modern Electron applications. It provides a unified toolchain that simplifies the entire Electron development workflow from project creation to distribution, offering commands for initializing projects, starting development servers, building applications, packaging for distribution, and publishing to various platforms.
npm install -g @electron-forge/cliElectron Forge CLI is primarily used as a command-line tool via the electron-forge binary. For programmatic usage:
import { getMakeOptions } from "@electron-forge/cli/dist/electron-forge-make";
import { resolveWorkingDir } from "@electron-forge/cli/dist/util/resolve-working-dir";
import { checkSystem, checkPackageManager, SystemCheckContext } from "@electron-forge/cli/dist/util/check-system";const { getMakeOptions } = require("@electron-forge/cli/dist/electron-forge-make");
const { resolveWorkingDir } = require("@electron-forge/cli/dist/util/resolve-working-dir");
const { checkSystem, checkPackageManager } = require("@electron-forge/cli/dist/util/check-system");# Install globally
npm install -g @electron-forge/cli
# Initialize a new Electron app
electron-forge init my-app
# Start development server
electron-forge start
# Package the application
electron-forge package
# Create distributables
electron-forge make
# Publish to distribution platforms
electron-forge publishElectron Forge CLI is built around several key components:
Core commands for creating and importing Electron projects with template support and configuration options.
// Init command options
interface InitOptions {
dir: string;
interactive: boolean;
copyCIFiles?: boolean;
force?: boolean;
skipGit?: boolean;
template?: string;
}
// Import command options
interface ImportOptions {
dir: string;
interactive: boolean;
skipGit?: boolean;
}Development server and build commands for packaging and creating distributables.
// Start command options
interface StartOptions {
dir: string;
interactive: boolean;
enableLogging?: boolean;
runAsNode?: boolean;
inspect?: boolean;
inspectBrk?: boolean;
appPath?: string;
args?: string[];
}
// Package command options
interface PackageOptions {
dir: string;
interactive: boolean;
arch?: string;
platform?: string;
}Commands for creating distributables and publishing to various platforms.
// Make command options
interface MakeOptions {
dir: string;
interactive: boolean;
skipPackage?: boolean;
overrideTargets?: string[];
arch?: string;
platform?: string;
}
// Publish command options
interface PublishOptions {
dir: string;
interactive: boolean;
dryRun?: boolean;
dryRunResume?: boolean;
publishTargets?: string[];
makeOptions?: MakeOptions;
}Helper functions for directory resolution and system validation.
/**
* Resolves the directory in which to use a CLI command
* @param dir - Directory specified by user (relative or absolute)
* @param checkExisting - Check if directory exists, fallback to cwd if not
* @returns Resolved absolute directory path
*/
function resolveWorkingDir(dir: string, checkExisting?: boolean): string;
/**
* System validation context for pre-flight checks
*/
interface SystemCheckContext {
command: string;
git: boolean;
node: boolean;
packageManager: boolean;
}
/**
* Validates system requirements before command execution
* @param callerTask - Listr task for progress reporting
* @returns Promise resolving to validation result
*/
function checkSystem(callerTask: ForgeListrTask<SystemCheckContext>): Promise<any>;All CLI commands support these global options:
-V, --version - Output the current version-h, --help - Output usage informationThe package provides three executable binaries:
// Main CLI binary
"electron-forge": "dist/electron-forge.js"
// VSCode integration scripts
"electron-forge-vscode-nix": "script/vscode.sh" // Unix-like systems
"electron-forge-vscode-win": "script/vscode.cmd" // Windows