PHPackages                             uuf6429/electron-installer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. uuf6429/electron-installer

ActiveCustom-installer

uuf6429/electron-installer
==========================

A Composer package which installs the Electron binary (Linux, Windows, Mac) into `/bin` of your project.

v2.0.0(4y ago)0182MITPHPPHP ^7.2 || ^8.0

Since Mar 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/uuf6429/electron-installer)[ Packagist](https://packagist.org/packages/uuf6429/electron-installer)[ RSS](/packages/uuf6429-electron-installer/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

electron-installer
==================

[](#electron-installer)

[![Packagist](https://camo.githubusercontent.com/dbff3219e7a634125db26c9f6ea8a70c7b243ba5dafaf94070991dff2f2a1350/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f757566363432392f656c656374726f6e2d696e7374616c6c65722e737667)](https://packagist.org/packages/uuf6429/electron-installer)[![Build Status](https://camo.githubusercontent.com/92e191b717b1aa7896b0271ef4c984cf0e8668feab8c4ea4a34712e2d660b846/68747470733a2f2f6170692e7472617669732d63692e636f6d2f757566363432392f656c656374726f6e2d696e7374616c6c65722e706e67)](https://app.travis-ci.com/github/uuf6429/electron-installer)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/uuf6429/electron-installer/master/LICENSE)

A Composer package which installs the Electron binary (Linux, Windows, Mac) into `/bin` of your project.

##### Table of Contents

[](#table-of-contents)

- [Installation](#installation)
- [How to require a specific version of Electron?](#how-to-require-specific-versions-of-electron)
- [How does this work internally?](#how-does-this-work-internally)
- [How to access the binary easily by using ElectronInstaller\\ElectronBinary?](#electronbinary)
- [How to package for another platform by overriding platform requirements?](#override-platform-requirements)
- [How to use a Mirror or a custom CDN URL for downloading?](#downloading-from-a-mirror)

Installation
------------

[](#installation)

To install Electron as a local, per-project dependency to your project, simply add a dependency on `uuf6429/electron-installer` to your project's `composer.json` file.

```
{
  "require": {
    "uuf6429/electron-installer": "^2"
  },
  "scripts": {
    "post-install-cmd": [
      "ElectronInstaller\\Installer::installElectron"
    ],
    "post-update-cmd": [
      "ElectronInstaller\\Installer::installElectron"
    ]
  }
}
```

For a development dependency, change `require` to `require-dev`.

The default download source used is: You might change it by setting a custom CDN URL, which is explained in the section "[Downloading from a mirror](#downloading-from-a-mirror)".

By setting the Composer configuration directive `bin-dir`, the [vendor binaries](https://getcomposer.org/doc/articles/vendor-binaries.md#can-vendor-binaries-be-installed-somewhere-other-than-vendor-bin-)will be installed into the defined folder. **Important! Composer will install the binaries into `vendor\bin` by default.**

The `scripts` section is necessary, because currently Composer does not pass events to the handler scripts of dependencies. If you leave it away, you might execute the installer manually.

Now, assuming that the scripts section is set up as required, the Electron binary will be installed into the `/bin`folder and updated alongside the project's Composer dependencies.

How to require specific versions of Electron?
---------------------------------------------

[](#how-to-require-specific-versions-of-electron)

The environment and server variable `ELECTRON_VERSION` enables you specify the version requirement at the time of packaging.

You can also set the `electron-version` in the `extra` section of your `composer.json`:

```
{
  "extra": {
    "uuf6429/electron-installer": {
      "electron-version": "16.0.0"
    }
  }
}
```

The search order for the version is `$_ENV`, `$_SERVER`, `composer.json` (extra section), fallback to the latest version on GitHub.

How does this work internally?
------------------------------

[](#how-does-this-work-internally)

### Fetching the Electron Installer

[](#fetching-the-electron-installer)

In your composer.json you require the package "electron-installer". The package is fetched by composer and stored into `./vendor/uuf6429/electron-installer`. It contains only one file the `ElectronInstaller\\Installer`.

### Platform-specific download of Electron

[](#platform-specific-download-of-electron)

The `ElectronInstaller\\Installer` is run as a "post-install-cmd". That's why you need the "scripts" section in your " composer.json". The installer creates a new composer in-memory package "electron", detects your OS and downloads the correct Electron version to the folder `./vendor/uuf6429/electron`. All Electron files reside there.

### Installation into `/bin` folder

[](#installation-into-bin-folder)

The binary is linked from `./vendor/uuf6429/electron` to your composer configured `bin-dir` folder.

### Generation of ElectronBinary

[](#generation-of-electronbinary)

The installer generates a PHP file `ElectronInstaller/ElectronBinary` and inserts the path to the binary.

ElectronBinary
--------------

[](#electronbinary)

To access information about the binary, the class `ElectronBinary` is created automatically during installation.

The class defines the following constants:

- `BIN` is the full-path to the Electron binary file, e.g. `/your_project/bin/electron`
- `DIR` is the folder of the binary, e.g. `/your_project/bin`
- `VERSION` the version used during the installation, e.g. `16.1.2`

Usage:

```
