Add Windows installer script

This commit is contained in:
hensm
2019-03-05 01:13:20 +00:00
parent c2222b27ee
commit 1f144e486f
5 changed files with 108 additions and 13 deletions

View File

@@ -50,19 +50,19 @@ sudo dnf install fx_cast_bridge-<version>.<arch>.rpm
macOS: macOS:
````sh ````sh
brew install dpkg rpm brew install dpkg rpm makensis
```` ````
Debian/Ubuntu: Debian/Ubuntu:
````sh ````sh
sudo apt install dpkg rpm sudo apt install dpkg rpm makensis
```` ````
Fedora: Fedora:
````sh ````sh
sudo dnf install dpkg rpm-build sudo dnf install dpkg rpm-build mingw-nsis
```` ````
Archlinux: Archlinux:
@@ -71,7 +71,7 @@ At the moment, `pkg` has a [bug](https://github.com/zeit/pkg/issues/584), until
```sh ```sh
sudo pacman -S nvm dpkg sudo pacman -S nvm dpkg
yay -S rpm-org yay -S rpm-org nsis
echo 'source /usr/share/nvm/init-nvm.sh' >> ~/.bashrc echo 'source /usr/share/nvm/init-nvm.sh' >> ~/.bashrc
nvm install 10.12.0 nvm install 10.12.0
``` ```

View File

@@ -1,9 +1,12 @@
"use strict";
const fs = require("fs-extra"); const fs = require("fs-extra");
const os = require("os"); const os = require("os");
const path = require("path"); const path = require("path");
const minimist = require("minimist"); const minimist = require("minimist");
const glob = require("glob"); const glob = require("glob");
const mustache = require("mustache"); const mustache = require("mustache");
const makensis = require("makensis");
const { spawnSync } = require("child_process"); const { spawnSync } = require("child_process");
const { exec: pkgExec } = require("pkg"); const { exec: pkgExec } = require("pkg");
@@ -18,14 +21,16 @@ const { executableName
, manifestName , manifestName
, manifestPath , manifestPath
, pkgPlatform , pkgPlatform
, DIST_PATH } = require("./lib/paths"); , DIST_PATH
, WIN_REGISTRY_KEY } = require("./lib/paths");
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
boolean: [ "package" ] boolean: [ "package" ]
, string: [ "platform", "packageType" ] , string: [ "platform", "arch", "packageType" ]
, default: { , default: {
platform: os.platform() platform: os.platform()
, arch: os.arch()
, package: false , package: false
// Linux package type (deb/rpm) // Linux package type (deb/rpm)
, packageType: "deb" , packageType: "deb"
@@ -75,8 +80,9 @@ async function build () {
, "allowed_extensions": [ extensionId ] , "allowed_extensions": [ extensionId ]
, "path": argv.package , "path": argv.package
// Add either installed path or dist path // Add either installed path or dist path
? path.join(executablePath[argv.platform] ? (argv.platform === "win32" ? path.win32 : path)
, executableName[argv.platform]) .join(executablePath[argv.platform]
, executableName[argv.platform])
: path.join(DIST_PATH, executableName[argv.platform]) : path.join(DIST_PATH, executableName[argv.platform])
}; };
@@ -106,12 +112,12 @@ async function build () {
// Package executable // Package executable
await pkgExec([ await pkgExec([
BUILD_PATH BUILD_PATH
, "--target", pkgPlatform[argv.platform] , "--target", `${pkgPlatform[argv.platform]}-${argv.arch}`
, "--output", path.join(BUILD_PATH, executableName[argv.platform]) , "--output", path.join(BUILD_PATH, executableName[argv.platform])
]); ]);
if (argv.package) { if (argv.package) {
const installerName = await package(argv.platform); const installerName = await packageApp(argv.platform);
if (installerName) { if (installerName) {
// Move installer to dist // Move installer to dist
@@ -134,7 +140,7 @@ async function build () {
} }
function package (platform) { function packageApp (platform) {
switch (platform) { switch (platform) {
case "darwin": case "darwin":
return packageDarwin(platform); return packageDarwin(platform);
@@ -148,7 +154,7 @@ function package (platform) {
} }
case "win32": case "win32":
return packageWin32(); return packageWin32(platform);
default: default:
console.log("Cannot build installer package for this platform"); console.log("Cannot build installer package for this platform");
@@ -295,6 +301,7 @@ function packageLinuxRpm (platform, packageType) {
fs.readFileSync(specPath).toString() fs.readFileSync(specPath).toString()
, view)); , view));
// TODO: Use argv.arch
spawnSync( spawnSync(
`rpmbuild -bb ${specOutputPath} ` `rpmbuild -bb ${specOutputPath} `
+ `--define "_distdir ${BUILD_PATH}" ` + `--define "_distdir ${BUILD_PATH}" `
@@ -305,7 +312,37 @@ function packageLinuxRpm (platform, packageType) {
return glob.sync("**/*.rpm", { cwd: BUILD_PATH })[0]; return glob.sync("**/*.rpm", { cwd: BUILD_PATH })[0];
} }
function packageWin32 () {} function packageWin32 (platform) {
const scriptPath = path.join(__dirname, "../packaging/win/installer.nsi");
const scriptOutputPath = path.join(BUILD_PATH, path.basename(scriptPath));
const outFile = "installer.exe";
const view = {
applicationName
, applicationVersion
, executableName: executableName[platform]
, executablePath: executablePath[platform]
, manifestName
, winRegistryKey: WIN_REGISTRY_KEY
, outFile
};
fs.writeFileSync(scriptOutputPath
, mustache.render(
fs.readFileSync(scriptPath).toString()
, view));
const output = makensis.compileSync(scriptOutputPath);
if (output.status === 0) {
console.log(output.stdout);
} else {
console.error(output.stderr);
}
return outFile;
}
build().catch(e => { build().catch(e => {

15
app/package-lock.json generated
View File

@@ -18,6 +18,12 @@
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==", "integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==",
"dev": true "dev": true
}, },
"@nsis/language-data": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/@nsis/language-data/-/language-data-0.5.1.tgz",
"integrity": "sha512-rsbghvYNfVTmbTSHlMqF8kpG70mUlJTg6IiUf9IBAqidCyC19vlsYQXShrzPUeRqPP2GiXnIQPjDJ+Z7H0TTyw==",
"dev": true
},
"@types/dnssd": { "@types/dnssd": {
"version": "0.4.1", "version": "0.4.1",
"resolved": "https://registry.npmjs.org/@types/dnssd/-/dnssd-0.4.1.tgz", "resolved": "https://registry.npmjs.org/@types/dnssd/-/dnssd-0.4.1.tgz",
@@ -1453,6 +1459,15 @@
"resolved": "https://registry.npmjs.org/long/-/long-2.4.0.tgz", "resolved": "https://registry.npmjs.org/long/-/long-2.4.0.tgz",
"integrity": "sha1-n6GAux2VAM3CnEFWdmoZleH0Uk8=" "integrity": "sha1-n6GAux2VAM3CnEFWdmoZleH0Uk8="
}, },
"makensis": {
"version": "0.17.0",
"resolved": "https://registry.npmjs.org/makensis/-/makensis-0.17.0.tgz",
"integrity": "sha512-tzNcjuYvhE+MWD3X0S5to7ufyRmzcCV70/h65mT7voeIINnQEJuzVOUh9pjBBX+WfhoiLmb3xAJS98EbDHgoUQ==",
"dev": true,
"requires": {
"@nsis/language-data": "^0.5.1"
}
},
"map-cache": { "map-cache": {
"version": "0.2.2", "version": "0.2.2",
"resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz",

View File

@@ -26,6 +26,7 @@
"@types/mime-types": "^2.1.0", "@types/mime-types": "^2.1.0",
"@types/node": "^11.9.5", "@types/node": "^11.9.5",
"@types/node-fetch": "^2.1.6", "@types/node-fetch": "^2.1.6",
"makensis": "^0.17.0",
"mustache": "^3.0.1", "mustache": "^3.0.1",
"pkg": "^4.3.5", "pkg": "^4.3.5",
"tslint": "^5.13.0" "tslint": "^5.13.0"

View File

@@ -0,0 +1,42 @@
!include LogicLib.nsh
!define MANIFEST_KEY "Software\Mozilla\NativeMessagingHosts\{{manifestName}}"
!define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\{{winRegistryKey}}"
Name "{{applicationName}} v{{applicationVersion}}"
OutFile "{{outFile}}"
InstallDir "{{executablePath}}"
RequestExecutionLevel user
Section
SetRegView 64
SetOutPath $INSTDIR
# Main executable
File "{{executableName}}"
File "{{manifestName}}"
# Native manifest key
WriteRegStr HKLM "${MANIFEST_KEY}" "" "$INSTDIR\{{manifestName}}"
# Create and register uninstaller
WriteUninstaller "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${UNINSTALL_KEY}" "DisplayName" "{{applicationName}}"
WriteRegStr HKLM "${UNINSTALL_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "${UNINSTALL_KEY}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
SectionEnd
Section "uninstall"
SetRegView 64
# Remove uninstaller
Delete "$INSTDIR\uninstall.exe"
DeleteRegKey HKLM "${UNINSTALL_KEY}"
# Remove manifest and executable dir
DeleteRegKey HKLM "${MANIFEST_KEY}"
Delete "$INSTDIR\{{executableName}}"
Delete "$INSTDIR\{{manifestName}}"
RMDir $INSTDIR
SectionEnd