bostondv / electron-windows-store

:package: Turn Electron Apps into Windows AppX Packages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Electron Apps in the Windows Store

npm version

Electron-Windows-Store: A CLI that takes the packaged output of your Electron app, then converts it into an AppX package. Once Windows Codename Redstone (also known as the "Windows Anniversary Update") is released, you will be able to submit your AppX packages to the Windows Store. πŸ“¦ Users will also be able to just double-click your .appx to automatically install it.

To install this command line tool, get it directly from npm:

npm install -g electron-windows-store

To turn an Electron app into an AppX package, run:

electron-windows-store --input-directory C:\myelectronapp  --output-directory C:\output\myelectronapp --flatten true --package-version 1.0.0.0 --package-name myelectronapp

This tool supports two methods to create AppX packages: Either using manual file copy operations, or using Windows Containers. The first option requires only the Windows 10 SDK, while the second option also requires the Desktop App Converter.

Usage

Before running the Electron-Windows-Store CLI, let's make sure we have all the prerequisites in place. You will need:

  • Windows 10 Anniversary Update - Enterprise Edition (This is build 14316 and up - as of May 2016, it's part of the latest Windows Insiders Preview)
  • Windows 10 SDK from here
  • Node 4 or above (to check, run node -v)

Package Your Electron Application

Package the application using electron-packager (or something similar). Make sure to remove node_modules that you don't need in your final application.

The output should look roughly like this:

β”œβ”€β”€ Ghost.exe
β”œβ”€β”€ LICENSE
β”œβ”€β”€ content_resources_200_percent.pak
β”œβ”€β”€ node.dll
β”œβ”€β”€ pdf.dll
β”œβ”€β”€ resources
β”‚   β”œβ”€β”€ app
β”‚   └── atom.asar
β”œβ”€β”€ snapshot_blob.bin
β”œβ”€β”€ [... and more files]

Convert with File Copying

From an elevated PowerShell (run it "as Administrator"), run electron-windows-store with the required parameters, passing both the input and output directories, the app's name and version, and confirmation that node_modules should be flattened. If you don't pass these parameters, we will simply ask you for them.

electron-windows-store --input-directory C:\myelectronapp  --output-directory C:\output\myelectronapp --flatten true --package-version 1.0.0.0 --package-name myelectronapp

These are all options for the CLI:

  -h, --help                                 output usage information
  -V, --version                              output the version number
  -c, --container-virtualization             Create package using Windows Container virtualization
  -b, --windows-build                        Display Windows Build information
  -i, --input-directory <path>               Directory containing your application
  -o, --output-directory <path>              Output directory for the appx
  -f, --flatten <true|false>                 Flatten Node modules without warning
  -p, --package-version <version>            Version of the app package
  -n, --package-name <name>                  Name of the app package
      --package-display-name <displayName>   Dispay name of the package
      --package-description <description>    Description of the package
  -e, --package-executable <executablePath>  Path to the package executable
  -a, --assets <assetsPath>                  Path to the visual assets for the appx
  -m, --manifest <manifestPath>              Path to a manifest, if you want to be overwritten
  -d, --deploy <true|false>                  Should the app be deployed after creation?
  --publisher <publisher>                    Publisher to use (example: CN=developmentca)
  --windows-kit <windows-kit>                Path to the Windows Kit bin folder
  --dev-cert <dev-cert>                      Path to the developer certificate to use
  --desktop-converter <desktop-converter>    Path to the desktop converter tools
  --expaned-base-image <base-image>          Path to the expanded base image
  --makeappx-params <params>                 Additional parameters for Make-AppXPackage (example: --makeappx-params "/l","/d")
  --signtool-params <params>                 Additional parameters for signtool.exe (example: --makeappx-params "/l","/d")

Convert with Container Virtualization

The Desktop App Converter is capabable of running an installer and your app during conversion inside a Windows Container. This is useful if you're not entirely sure what your application does, but requires installation of the Desktop App Converter.

πŸ’» Ensure that your computer is capable of running containers: You'll need a 64 bit (x64) processor, hardware-assisted virtualization and second Level Address Translation (SLAT).

πŸ’‘ Before running the CLI for the first time, you will have to setup the "Windows Desktop App Converter". This will take a few minutes, but don't worry - you only have to do this once. Download and the Desktop App Converter from here. You will receive two files: DesktopAppConverter.zip and BaseImage-14316.wim.

  1. Unzip DesktopAppConverter.zip. From an elevated PowerShell (opened with "run as Administrator"., ensure that your systems execution policy allows us to run everything we inted to run by calling Set-ExecutionPolicy bypass.
  2. Then, run the installation of the Desktop App Converter, passing in the location of the Windows .ase Image (downloaded as BaseImage-14316.wim), by calling .\DesktopAppConverter.ps1 -Setup -BaseImage .\BaseImage-14316.wim.
  3. If running the above command prompts you for a reboot, please restart your machine and run the above command again after a successful restart.

Then, run electron-windows-store with the --container-virtualization flag!

What is the CLI Doing?

Once executed, the tool goes to work: It accepts your Electron app as an input, flattening the node_modules. Then, it archives your application as app.zip. Using an installer and a Windows Container, the tool creates an "expanded" AppX package - including the Windows Application Manifest (AppXManifest.xml) as well as the virtual file system and the virtual registry inside your output folder.

Once we have the expanded AppX files, the tool uses the Windows App Packager (MakeAppx.exe) to create a single-file AppX package from those files on disk. Finally, the tool can be used to create a trusted certificate on your computer to sign the new AppX pacakge. With the signed AppX package, the CLI can also automatically install the package on your machine.

Configuration

πŸ’‘ The first time you run this tool, it needs to know some settings. It will ask you only once and store your answers in your profile folder in a .electron-windows-store file. You can also provide these values as a parameter when running the CLI.

{
  "publisher": "CN=developmentca",
  "windowsKit": "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\x64",
  "devCert": "C:\\Tools\\DesktopConverter\\Certs\\devcert.pfx",
  "desktopConverter": "C:\\Tools\\DesktopConverter",
  "expandedBaseImage": "C:\\ProgramData\\Microsoft\\Windows\\Images\\BaseImage-14316\\"
}

Using all the fancy Windows APIs

You can pair up your Electron app with a little invisible UWP side-kick, enabling your Electron app to call all WinRT APIs. Check out an example over here.

License

Licensed using the MIT License (MIT); Copyright (c) Microsoft Corporation. For more information, please see LICENSE.

About

:package: Turn Electron Apps into Windows AppX Packages

License:MIT License


Languages

Language:JavaScript 85.4%Language:C# 7.6%Language:PowerShell 7.0%