Skip to content

Commit

Permalink
feat(nsis): Change installation directory when not using 'oneClick' w…
Browse files Browse the repository at this point in the history
…ith NSIS

Closes electron-userland#596
  • Loading branch information
develar committed Jan 5, 2017
1 parent 1bc808e commit be5f413
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 615 deletions.
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
| oneClick | <a name="NsisOptions-oneClick"></a>One-click installation. Defaults to `true`.
| perMachine | <a name="NsisOptions-perMachine"></a><p>Defaults to <code>false</code>.</p> <p>If <code>oneClick</code> is <code>true</code> (default): Install per all users (per-machine).</p> <p>If <code>oneClick</code> is <code>false</code>: no install mode installer page (choice per-machine or per-user), always install per-machine.</p>
| allowElevation | <a name="NsisOptions-allowElevation"></a>*boring installer only.* Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
| allowToChangeInstallationDirectory | <a name="NsisOptions-allowToChangeInstallationDirectory"></a>*boring installer only.* Whether to allow user to change installation directory. Defaults to `false`.
| runAfterFinish | <a name="NsisOptions-runAfterFinish"></a>*one-click installer only.* Run application after finish. Defaults to `true`.
| guid | <a name="NsisOptions-guid"></a>See [GUID vs Application Name](https://github.com/electron-userland/electron-builder/wiki/NSIS#guid-vs-application-name).
| installerIcon | <a name="NsisOptions-installerIcon"></a>The path to installer icon. Defaults to `build/installerIcon.ico` or application icon.
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
"test-deps-mac": "brew install rpm dpkg mono lzip gnu-tar graphicsmagick xz && brew install wine --without-x11",
"postinstall": "lerna bootstrap",
"update-deps": "lerna exec -- npm-check-updates --reject 'electron-builder-http,electron-builder-util' -a",
"lerna-publish": "lerna publish --skip-npm --skip-git",
"set-versions": "node test/out/helpers/setVersions.js p",
"set-dep-versions": "node test/out/helpers/setVersions.js"
"lerna-publish": "node test/out/helpers/setVersions.js p && lerna publish --skip-npm --skip-git && node test/out/helpers/setVersions.js && conventional-changelog -p angular -i CHANGELOG.md -s",
"npm-publish": "./packages/npm-publish.sh"
},
"devDependencies": {
"@develar/semantic-release": "^6.3.26",
"@types/electron": "^1.4.30",
"@types/ini": "^1.3.29",
"@types/jest": "^16.0.3",
Expand Down
5 changes: 5 additions & 0 deletions packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export interface NsisOptions {
*/
readonly allowElevation?: boolean

/*
*boring installer only.* Whether to allow user to change installation directory. Defaults to `false`.
*/
readonly allowToChangeInstallationDirectory?: boolean

/*
*one-click installer only.* Run application after finish. Defaults to `true`.
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ export default class NsisTarget extends Target {
defines.MULTIUSER_INSTALLMODE_ALLOW_ELEVATION = null
}

if (options.allowToChangeInstallationDirectory) {
if (oneClick) {
throw new Error("allowToChangeInstallationDirectory makes sense only for boring installer (please set oneClick to false)")
}
defines.allowToChangeInstallationDirectory = null
}

// Error: invalid VIProductVersion format, should be X.X.X.X
// so, we must strip beta
const localeId = options.language || "1033"
Expand Down
4 changes: 3 additions & 1 deletion packages/electron-builder/templates/nsis/boringInstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
!define MUI_FINISHPAGE_RUN_FUNCTION "StartApp"

!ifdef LICENSE_FILE

Function licensePre
${GetParameters} $R0
${GetOptions} $R0 "--update" $R1
Expand All @@ -42,6 +41,9 @@
!define MUI_CUSTOMFUNCTION_GUIINIT GuiInit
!endif

!ifdef allowToChangeInstallationDirectory
!insertmacro MUI_PAGE_DIRECTORY
!endif
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!else
Expand Down
9 changes: 9 additions & 0 deletions packages/npm-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e

npm publish packages/electron-builder-http || true
npm publish packages/electron-builder-core || true
npm publish packages/electron-builder-util || true
npm publish packages/electron-builder || true
npm publish packages/electron-builder-squirrel-windows || true
npm publish packages/electron-auto-updater || true
20 changes: 17 additions & 3 deletions test/src/helpers/setVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ async function main(): Promise<void> {
}

async function setPackageVersions(packages: Array<string>, packageData: Array<any>) {
const versions = await BluebirdPromise.map(packages, it => exec("node", [path.join(rootDir, "test", "vendor", "yarn.js"), "info", "--json", it, "dist-tags"]).then((it: string) => JSON.parse(it).data))
const versions = await BluebirdPromise.map(packages, it => exec("node", [path.join(rootDir, "test", "vendor", "yarn.js"), "info", "--json", it, "dist-tags"])
.then((it: string) => {
if (it === "") {
// {"type":"error","data":"Received invalid response from npm."}
// not yet published to npm
return "0.0.1"
}

try {
return JSON.parse(it).data
}
catch (e) {
throw new Error(`Cannot parse ${it}: ${e.stack || e}`)
}
}))
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i]
const packageJson = packageData[i]
Expand Down Expand Up @@ -52,12 +66,12 @@ async function setDepVersions(packages: Array<string>, packageData: Array<any>)
let changed = false
for (let depIndex = 0; depIndex < packages.length; depIndex++) {
const depPackageName = packages[depIndex]
const oldVersion = packageJson.dependencies[depPackageName]
const newVersion = versions[depIndex]
const oldVersion = packageJson.dependencies == null ? null : packageJson.dependencies[depPackageName]
if (oldVersion == null) {
continue
}

const newVersion = versions[depIndex]
if (oldVersion == newVersion) {
console.log(`Skip ${depPackageName} for ${packageName} — version ${newVersion} is actual`)
continue
Expand Down
14 changes: 14 additions & 0 deletions test/src/windows/nsisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ test.ifDevOrLinuxCi("custom script", app({targets: nsisTarget}, {
packed: context => assertThat(path.join(context.projectDir, "build", "customInstallerScript")).isFile(),
}))

test.ifDevOrLinuxCi("allowToChangeInstallationDirectory", app({
targets: nsisTarget,
appMetadata: {
name: "test-custom-inst-dir",
productName: "Test Custom Installation Dir"
},
config: {
nsis: {
allowToChangeInstallationDirectory: true,
oneClick: false,
}
}
}))

test("menuCategory", app({
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32),
appMetadata: {
Expand Down
Loading

0 comments on commit be5f413

Please sign in to comment.