Skip to content

Commit

Permalink
fix(nsis): move generated custom messages to separate files (to avoid…
Browse files Browse the repository at this point in the history
… stdin encoding issues on Windows)

Close #1447
  • Loading branch information
develar committed Apr 9, 2017
1 parent 88e52ad commit 5b83860
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"chromium-pickle-js": "^0.2.0",
"cuint": "^0.2.2",
"debug": "^2.6.3",
"electron-download-tf": "4.1.1",
"@electron-builder/electron-download": "4.2.1",
"electron-osx-sign": "0.4.4",
"fs-extra-p": "^4.1.0",
"hosted-git-info": "^2.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"electron-builder-core": "0.0.0-semantic-release",
"electron-builder-http": "0.0.0-semantic-release",
"electron-builder-util": "0.0.0-semantic-release",
"electron-download-tf": "4.1.1",
"@electron-builder/electron-download": "4.2.1",
"electron-osx-sign": "0.4.4",
"electron-publish": "0.0.0-semantic-release",
"fs-extra-p": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { chmod, emptyDir } from "fs-extra-p"
import * as path from "path"
import { PlatformPackager } from "../platformPackager"

const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download-tf"))
const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("@electron-builder/electron-download"))

function createDownloadOpts(opts: any, platform: string, arch: string, electronVersion: string) {
if (opts.download != null) {
Expand Down
16 changes: 13 additions & 3 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { asArray, debug, doSpawn, exec, getPlatformIconFileName, handleProcess,
import { getBinFromBintray } from "electron-builder-util/out/binDownload"
import { copyFile } from "electron-builder-util/out/fs"
import { log, subTask, warn } from "electron-builder-util/out/log"
import { readFile, unlink } from "fs-extra-p"
import { outputFile, readFile, unlink } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
Expand Down Expand Up @@ -407,6 +407,12 @@ export class NsisTarget extends Target {
})
}

private async writeCustomLangFile(data: string) {
const file = await this.packager.getTempFile("messages.nsh")
await outputFile(file, data)
return file
}

private async computeFinalScript(originalScript: string, isInstaller: boolean) {
const packager = this.packager
let scriptHeader = `!addincludedir "${path.win32.join(__dirname, "..", "..", "templates", "nsis", "include")}"\n`
Expand All @@ -421,14 +427,18 @@ export class NsisTarget extends Target {
scriptHeader += createMacro("licensePage", licensePage)
}

scriptHeader += "\n" + computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, "messages.yml"), "utf-8"))).join("\n") + "\n\n"
const addCustomMessageFileInclude = async (input: string) => {
scriptHeader += "!include " + await this.writeCustomLangFile(computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, input), "utf-8"))).join("\n")) + "\n"
}

await addCustomMessageFileInclude("messages.yml")

if (this.isPortable) {
return scriptHeader + originalScript
}

if (this.options.oneClick === false) {
scriptHeader += "\n" + computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, "boringMessages.yml"), "utf-8"))).join("\n") + "\n\n"
await addCustomMessageFileInclude("boringMessages.yml")
}

const customInclude = await packager.getResource(this.options.include, "installer.nsh")
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ELECTRON_VERSION, TEST_DIR } from "./config"
const util = require("../../../packages/electron-builder-util/out/util")
const isEmptyOrSpaces = util.isEmptyOrSpaces

const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download-tf"))
const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("@electron-builder/electron-download"))

runTests()
.catch(error => {
Expand Down
33 changes: 19 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
typescript "~2.1.5"
yargs "^7.0.2"

"@electron-builder/[email protected]":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@electron-builder/electron-download/-/electron-download-4.2.1.tgz#b10b7b077523ae2f6c21dc05658df145d716c223"
dependencies:
debug "^2.6.3"
env-paths "^1.0.0"
fs-extra "^2.1.2"
minimist "^1.2.0"
nugget "^2.0.1"
path-exists "^3.0.0"
rc "^1.2.1"
semver "^5.3.0"
sumchecker "^2.0.2"

"@types/electron@^1.4.35":
version "1.4.35"
resolved "https://registry.yarnpkg.com/@types/electron/-/electron-1.4.35.tgz#48e5e6ef0b49f27b9f78b87d80f796e3f0a4f33c"
Expand Down Expand Up @@ -1064,19 +1078,6 @@ ecc-jsbn@~0.1.1:
dependencies:
jsbn "~0.1.0"

[email protected]:
version "4.1.1"
resolved "https://registry.yarnpkg.com/electron-download-tf/-/electron-download-tf-4.1.1.tgz#127aaa6a10ccf598bc15ed6ae83390348ebb3b4b"
dependencies:
debug "^2.6.3"
fs-extra "^2.1.2"
minimist "^1.2.0"
nugget "^2.0.1"
path-exists "^3.0.0"
rc "^1.1.7"
semver "^5.3.0"
sumchecker "^2.0.2"

[email protected]:
version "0.4.4"
resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.4.tgz#afdf38450ccaebe6dabeca71fb0fad6294a8c57c"
Expand All @@ -1095,6 +1096,10 @@ end-of-stream@^1.0.0:
dependencies:
once "^1.4.0"

env-paths@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0"

"errno@>=0.1.1 <0.2.0-0":
version "0.1.4"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.4.tgz#b896e23a9e5e8ba33871fc996abd3635fc9a1c7d"
Expand Down Expand Up @@ -2612,7 +2617,7 @@ randomatic@^1.1.3:
is-number "^2.0.2"
kind-of "^3.0.2"

rc@^1.0.1, rc@^1.1.6, rc@^1.1.7:
rc@^1.0.1, rc@^1.1.6, rc@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.1.tgz#2e03e8e42ee450b8cb3dce65be1bf8974e1dfd95"
dependencies:
Expand Down

0 comments on commit 5b83860

Please sign in to comment.