Skip to content

Commit

Permalink
feat: revert "Releases file for Windows not uploaded to Github #190"
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed May 13, 2016
1 parent 05121df commit 079989a
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 74 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/Code Signing.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ travis encrypt 'CSC_KEY_PASSWORD=beAwareAboutBashEscaping!!!' --add
# Where to buy certificate

[StartSSL](https://startssl.com/Support?v=34) is recommended.
It can be used to sign OS X app also, so, you don't need to buy Apple Certificate in addition (please note, it works, but we are waiting official confirmation).
It can be used to sign OS X app also, so, you don't need to buy Apple Certificate in addition.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"globby": "^4.0.0",
"hosted-git-info": "^2.1.4",
"image-size": "^0.5.0",
"lodash.template": "^4.2.4",
"lodash.template": "^4.2.5",
"mime": "^1.3.4",
"progress": "^1.1.8",
"progress-stream": "^1.2.0",
Expand Down
10 changes: 7 additions & 3 deletions src/osxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PlatformPackager, BuildInfo, normalizeTargets } from "./platformPackage
import { Platform, OsXBuildOptions, MasBuildOptions } from "./metadata"
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { log, debug, debug7z, spawn, statOrNull } from "./util"
import { log, debug, debug7z, spawn, statOrNull, warn } from "./util"
import { createKeychain, deleteKeychain, CodeSigningInfo, generateKeychainName } from "./codeSign"
import { path7za } from "7zip-bin"
import deepAssign = require("deep-assign")
Expand Down Expand Up @@ -82,11 +82,15 @@ export default class OsXPackager extends PlatformPackager<OsXBuildOptions> {

const identity = codeSigningInfo.name
if (<string | null>identity == null) {
log("App is not signed: CSC_LINK or CSC_NAME are not specified")
const message = "App is not signed: CSC_LINK or CSC_NAME are not specified, see https://github.com/electron-userland/electron-builder/wiki/Code-Signing"
if (masOptions != null) {
throw new Error(message)
}
warn(message)
return
}

log(`Signing app (${identity})`)
log(`Signing app (identity: ${identity})`)

const baseSignOptions: BaseSignOptions = {
app: path.join(appOutDir, this.appName + ".app"),
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const debug: Debugger = debugFactory("electron-builder")
export const debug7z: Debugger = debugFactory("electron-builder:7z")

export function warn(message: string) {
console.warn(yellow(message))
console.warn(yellow(`Warning: ${message}`))
}

const DEFAULT_APP_DIR_NAMES = ["app", "www"]
Expand Down
45 changes: 12 additions & 33 deletions src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Promise as BluebirdPromise } from "bluebird"
import { PlatformPackager, BuildInfo } from "./platformPackager"
import { Platform, WinBuildOptions } from "./metadata"
import * as path from "path"
import { log, statOrNull } from "./util"
import { readFile, deleteFile, rename, copy, emptyDir, writeFile, open, close, read, move } from "fs-extra-p"
import { log, statOrNull, warn } from "./util"
import { deleteFile, rename, emptyDir, open, close, read, move } from "fs-extra-p"
import { sign } from "signcode-tf"
import ElectronPackagerOptions = ElectronPackager.ElectronPackagerOptions

Expand Down Expand Up @@ -52,6 +52,10 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
}

async pack(outDir: string, arch: string, postAsyncTasks: Array<Promise<any>>): Promise<any> {
if (arch === "ia32") {
warn("For windows consider only distributing 64-bit, see https://github.com/electron-userland/electron-builder/issues/359#issuecomment-214851130")
}

// we must check icon before pack because electron-packager uses icon and it leads to cryptic error message "spawn wine ENOENT"
await this.iconPath

Expand All @@ -64,7 +68,7 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
}

const unpackedDir = path.join(outDir, `win${arch === "x64" ? "" : `-${arch}`}-unpacked`)
const finalAppOut = path.join(outDir, `win${arch === "x64" ? "" : `-${arch}`}-unpacked`, "lib", "net45")
const finalAppOut = path.join(unpackedDir, "lib", "net45")
const installerOut = computeDistOut(outDir, arch)
log("Removing %s and %s", path.relative(this.projectDir, installerOut), path.relative(this.projectDir, unpackedDir))
await BluebirdPromise.all([
Expand Down Expand Up @@ -166,38 +170,13 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {

const version = this.metadata.version
const archSuffix = arch === "x64" ? "" : ("-" + arch)
const releasesFile = path.join(installerOutDir, "RELEASES")
const nupkgVersion = winstaller.convertVersion(version)
const nupkgPathOriginal = `${this.metadata.name}-${nupkgVersion}-full.nupkg`
const nupkgPathWithArch = `${this.metadata.name}-${nupkgVersion}${archSuffix}-full.nupkg`

async function changeFileNameInTheReleasesFile(): Promise<void> {
const data = (await readFile(releasesFile, "utf8")).replace(new RegExp(" " + nupkgPathOriginal + " ", "g"), " " + nupkgPathWithArch + " ")
await writeFile(releasesFile, data)
}

const promises: Array<Promise<any>> = [
rename(path.join(installerOutDir, "Setup.exe"), path.join(installerOutDir, `${this.appName} Setup ${version}${archSuffix}.exe`))
.then(it => this.dispatchArtifactCreated(it, `${this.metadata.name}-Setup-${version}${archSuffix}.exe`)),
]
const nupkgPath = `${this.metadata.name}-${winstaller.convertVersion(version)}-full.nupkg`

if (archSuffix === "") {
this.dispatchArtifactCreated(path.join(installerOutDir, nupkgPathOriginal))
this.dispatchArtifactCreated(path.join(installerOutDir, "RELEASES"))
}
else {
promises.push(
rename(path.join(installerOutDir, nupkgPathOriginal), path.join(installerOutDir, nupkgPathWithArch))
.then(it => this.dispatchArtifactCreated(it))
)
promises.push(
changeFileNameInTheReleasesFile()
.then(() => copy(releasesFile, path.join(installerOutDir, "RELEASES-ia32")))
.then(it => this.dispatchArtifactCreated(it))
)
}
this.dispatchArtifactCreated(path.join(installerOutDir, nupkgPath))
this.dispatchArtifactCreated(path.join(installerOutDir, "RELEASES"))

await BluebirdPromise.all(promises)
await rename(path.join(installerOutDir, "Setup.exe"), path.join(installerOutDir, `${this.appName} Setup ${version}${archSuffix}.exe`))
.then(it => this.dispatchArtifactCreated(it, `${this.metadata.name}-Setup-${version}${archSuffix}.exe`))
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/src/helpers/avaEx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare module "ava-tf" {
export const ifOsx: typeof test;
export const ifNotCi: typeof test;
export const ifNotCiOsx: typeof test;
export const ifDevOrWinCi: typeof test;
export const ifNotTravis: typeof test;
}

Expand Down Expand Up @@ -39,6 +40,11 @@ Object.defineProperties(test, {
get: function () {
return process.platform === "darwin" ? this : this.skip
}
},
"ifDevOrWinCi": {
get: function () {
return !process.env.CI || process.platform === "win32" ? this : this.skip
}
}
})

Expand Down
27 changes: 12 additions & 15 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export async function assertPack(fixtureName: string, packagerOptions: PackagerO

await packAndCheck(projectDir, Object.assign({
projectDir: projectDir,
cscLink: CSC_LINK,
cscKeyPassword: CSC_KEY_PASSWORD,
cscInstallerLink: CSC_INSTALLER_LINK,
cscInstallerKeyPassword: CSC_INSTALLER_KEY_PASSWORD,
dist: true,
}, packagerOptions), checkOptions)

Expand Down Expand Up @@ -206,7 +202,7 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO

function getWinExpected(archSuffix: string) {
return [
`RELEASES${archSuffix}`,
`RELEASES`,
`${productName} Setup 1.1.0${archSuffix}.exe`,
`TestApp-1.1.0${archSuffix}-full.nupkg`,
]
Expand All @@ -221,16 +217,9 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO
return
}

let i = filenames.indexOf("RELEASES-ia32")
if (i !== -1) {
assertThat((await readFile(artifacts[i].file, "utf8")).indexOf("ia32")).not.equal(-1)
}

if (archSuffix == "") {
const expectedArtifactNames = expected.slice()
expectedArtifactNames[1] = `TestAppSetup-1.1.0${archSuffix}.exe`
assertThat(artifacts.map(it => it.artifactName).filter(it => it != null)).deepEqual([`TestApp-Setup-1.1.0${archSuffix}.exe`])
}
const expectedArtifactNames = expected.slice()
expectedArtifactNames[1] = `TestAppSetup-1.1.0${archSuffix}.exe`
assertThat(artifacts.map(it => it.artifactName).filter(it => it != null)).deepEqual([`TestApp-Setup-1.1.0${archSuffix}.exe`])

const packageFile = path.join(path.dirname(artifacts[0].file), `TestApp-1.1.0${archSuffix}-full.nupkg`)
const unZipper = new DecompressZip(packageFile)
Expand Down Expand Up @@ -292,4 +281,12 @@ export function platform(platform: Platform): PackagerOptions {
return {
platform: [platform]
}
}

export function signed(packagerOptions: PackagerOptions): PackagerOptions {
packagerOptions.cscLink = CSC_LINK
packagerOptions.cscKeyPassword = CSC_KEY_PASSWORD
packagerOptions.cscInstallerLink = CSC_INSTALLER_LINK
packagerOptions.cscInstallerKeyPassword = CSC_INSTALLER_KEY_PASSWORD
return packagerOptions
}
22 changes: 10 additions & 12 deletions test/src/osxPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from "./helpers/avaEx"
import { assertPack, platform, modifyPackageJson } from "./helpers/packTester"
import { assertPack, platform, modifyPackageJson, signed } from "./helpers/packTester"
import { Platform } from "out"
import OsXPackager from "out/osxPackager"
import { move, writeFile } from "fs-extra-p"
import * as path from "path"
import { BuildInfo } from "out/platformPackager"
import { BuildInfo, PackagerOptions } from "out/platformPackager"
import { Promise as BluebirdPromise } from "bluebird"
import * as assertThat from "should/as-function"
import ElectronPackagerOptions = ElectronPackager.ElectronPackagerOptions
Expand All @@ -14,15 +14,15 @@ import { SignOptions, FlatOptions } from "electron-osx-sign-tf"
//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

test.ifOsx("two-package", () => assertPack("test-app", {
test.ifOsx("two-package", () => assertPack("test-app", signed({
platform: [Platform.OSX],
arch: "all",
}))
})))

test.ifOsx("one-package", () => assertPack("test-app-one", platform(Platform.OSX)))
test.ifOsx("one-package", () => assertPack("test-app-one", signed(platform(Platform.OSX))))

function createTargetTest(target: Array<string>, expectedContents: Array<string>) {
const options = {
let options: PackagerOptions = {
platform: [Platform.OSX],
devMetadata: {
build: {
Expand All @@ -32,6 +32,10 @@ function createTargetTest(target: Array<string>, expectedContents: Array<string>
}
}
}
if (target.includes("mas")) {
options = signed(options)
}

return () => assertPack("test-app-one", options, {
expectedContents: expectedContents
})
Expand All @@ -49,8 +53,6 @@ test.ifOsx("custom mas", () => {
return assertPack("test-app-one", {
platform: [Platform.OSX],
platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingOsXPackager(packager, cleanupTasks),
cscLink: null,
cscInstallerLink: null,
devMetadata: {
build: {
osx: {
Expand Down Expand Up @@ -84,8 +86,6 @@ test.ifOsx("identity in package.json", () => {
return assertPack("test-app-one", {
platform: [Platform.OSX],
platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingOsXPackager(packager, cleanupTasks),
cscLink: null,
cscInstallerLink: null,
devMetadata: {
build: {
osx: {
Expand All @@ -112,8 +112,6 @@ test.ifOsx("entitlements in build dir", () => {
return assertPack("test-app-one", {
platform: [Platform.OSX],
platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingOsXPackager(packager, cleanupTasks),
cscLink: null,
cscInstallerLink: null,
devMetadata: {
build: {
osx: {
Expand Down
14 changes: 6 additions & 8 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Platform } from "out"
import test from "./helpers/avaEx"
import { assertPack, platform, modifyPackageJson } from "./helpers/packTester"
import { assertPack, platform, modifyPackageJson, signed } from "./helpers/packTester"
import { move, outputFile } from "fs-extra-p"
import * as path from "path"
import { WinPackager, computeDistOut } from "out/winPackager"
Expand All @@ -12,7 +12,7 @@ import ElectronPackagerOptions = ElectronPackager.ElectronPackagerOptions
//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

test.ifNotCiOsx("win", () => assertPack("test-app-one", platform(Platform.WINDOWS),
test.ifNotCiOsx("win", () => assertPack("test-app-one", signed(platform(Platform.WINDOWS)),
{
tempDirCreated: process.env.TEST_DELTA ? it => modifyPackageJson(it, data => {
data.build.win = {
Expand All @@ -22,17 +22,15 @@ test.ifNotCiOsx("win", () => assertPack("test-app-one", platform(Platform.WINDOW
}
))

test.ifNotCiOsx("win f", () => {
test.ifDevOrWinCi("win f", () => {
const metadata: any = {
version: "3.0.0-beta.2"
}

return assertPack("test-app-one", {
platform: [Platform.WINDOWS],
cscLink: null,
cscInstallerLink: null,
devMetadata: metadata
}, {
platform: [Platform.WINDOWS],
devMetadata: metadata
}, {
expectedArtifacts: [
"RELEASES",
"TestApp Setup 3.0.0-beta.2.exe",
Expand Down

0 comments on commit 079989a

Please sign in to comment.