Skip to content

Commit

Permalink
fix: check wine version
Browse files Browse the repository at this point in the history
Closes #352
  • Loading branch information
develar committed May 3, 2016
1 parent 92573ec commit d77c8da
Show file tree
Hide file tree
Showing 25 changed files with 359 additions and 186 deletions.
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ os:
- osx
- linux

osx_image: xcode7.3
osx_image: xcode7

dist: trusty
sudo: required

env:
- NODE_VERSION=4
Expand All @@ -19,17 +22,21 @@ cache:

addons:
apt:
sources:
- mono
packages:
- icnsutils
- graphicsmagick
- mono-devel

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gnu-tar dpkg libicns graphicsmagick git-lfs; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then git lfs pull; fi
- gem install --no-rdoc --no-ri fpm
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl -L https://github.com/github/git-lfs/releases/download/v1.1.2/git-lfs-linux-amd64-1.1.2.tar.gz | tar -xz; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git-lfs-1.1.2/git-lfs pull; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then test/install-linux-dependencies.sh; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl -L https://github.com/github/git-lfs/releases/download/v1.2.0/git-lfs-linux-amd64-1.2.0.tar.gz | tar -xz; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git-lfs-1.2.0/git-lfs pull; fi

install:
- nvm install $NODE_VERSION
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@
"bluebird": "^3.3.5",
"chalk": "^1.1.3",
"command-line-args": "^2.1.6",
"compare-versions": "^2.0.1",
"debug": "^2.2.0",
"deep-assign": "^2.0.0",
"electron-osx-sign-tf": "~0.5.0-beta.0",
"electron-packager-tf": "^7.0.2-beta.0",
"electron-winstaller-fixed": "~2.4.0-beta.1",
"fs-extra-p": "^0.4.0",
"fs-extra-p": "^1.0.0",
"globby": "^4.0.0",
"hosted-git-info": "^2.1.4",
"image-size": "^0.5.0",
Expand All @@ -75,7 +76,7 @@
"signcode-tf": "^0.5.0",
"source-map-support": "^0.4.0",
"tmp": "0.0.28",
"typescript": "1.9.0-dev.20160425"
"typescript": "^1.9.0-dev.20160502"
},
"optionalDependencies": {
"appdmg-tf": "^0.3.11"
Expand All @@ -88,8 +89,8 @@
"devDependencies": {
"ava-tf": "^0.12.4-beta.6",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-es2015-parameters": "^6.7.0",
"babel-plugin-transform-es2015-spread": "^6.6.5",
"babel-plugin-transform-es2015-parameters": "^6.8.0",
"babel-plugin-transform-es2015-spread": "^6.8.0",
"decompress-zip": "^0.3.0",
"electron-download": "^2.1.2",
"json-parse-helpfulerror": "^1.0.3",
Expand All @@ -98,7 +99,7 @@
"pre-git": "^3.8.3",
"semantic-release": "^4.3.5",
"should": "^8.3.1",
"ts-babel": "^0.7.0",
"ts-babel": "^0.8.6",
"tsconfig-glob": "^0.4.3",
"tslint": "next",
"typescript": "^1.9.0-dev.20160414"
Expand Down
16 changes: 8 additions & 8 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { log } from "./util"
//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")

export async function createPublisher(packager: Packager, options: BuildOptions, repoSlug: InfoRetriever, isPublishOptionGuessed: boolean = false): Promise<Publisher> {
export async function createPublisher(packager: Packager, options: BuildOptions, repoSlug: InfoRetriever, isPublishOptionGuessed: boolean = false): Promise<Publisher | null> {
const info = await repoSlug.getInfo(packager)
if (info == null) {
if (isPublishOptionGuessed) {
Expand All @@ -20,22 +20,22 @@ export async function createPublisher(packager: Packager, options: BuildOptions,
throw new Error("Please specify 'repository' in the dev package.json ('" + packager.devPackageFile + "')")
}
else {
return new GitHubPublisher(info.user, info.project, packager.metadata.version, options.githubToken, options.publish !== "onTagOrDraft")
return new GitHubPublisher(info.user, info.project, packager.metadata.version, options.githubToken!, options.publish !== "onTagOrDraft")
}
}

export interface BuildOptions extends PackagerOptions, PublishOptions {
}

export async function build(originalOptions?: BuildOptions): Promise<void> {
const options = Object.assign({
const options: BuildOptions = Object.assign({
cscLink: process.env.CSC_LINK,
csaLink: process.env.CSA_LINK,
cscKeyPassword: process.env.CSC_KEY_PASSWORD,
githubToken: process.env.GH_TOKEN || process.env.GH_TEST_TOKEN,
}, originalOptions)

options.platform = normalizePlatforms(originalOptions.platform)
options.platform = normalizePlatforms(options.platform)

const lifecycleEvent = process.env.npm_lifecycle_event
if (options.publish) {
Expand Down Expand Up @@ -69,13 +69,13 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
const repositoryInfo = new InfoRetriever()
const packager = new Packager(options, repositoryInfo)
if (options.publish != null && options.publish !== "never") {
let publisher: BluebirdPromise<Publisher> = null
let publisher: Promise<Publisher> | null = null
packager.artifactCreated(event => {
if (publisher == null) {
publisher = <BluebirdPromise<Publisher>>createPublisher(packager, options, repositoryInfo, isPublishOptionGuessed)
publisher = createPublisher(packager, options, repositoryInfo, isPublishOptionGuessed)
}

if (publisher != null) {
if (publisher) {
publisher
.then(it => publishTasks.push(<BluebirdPromise<any>>it.upload(event.file, event.artifactName)))
}
Expand All @@ -85,7 +85,7 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
await executeFinally(packager.build(), errorOccurred => {
if (errorOccurred) {
for (let task of publishTasks) {
task.cancel()
task!.cancel()
}
return BluebirdPromise.resolve(null)
}
Expand Down
16 changes: 8 additions & 8 deletions src/codeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const __awaiter = require("./awaiter")

export interface CodeSigningInfo {
name: string
keychainName?: string
keychainName?: string | null

installerName?: string
installerName?: string | null
}

function randomString(): string {
Expand All @@ -25,7 +25,7 @@ export function generateKeychainName(): string {
return "csc-" + randomString() + ".keychain"
}

export function createKeychain(keychainName: string, cscLink: string, cscKeyPassword: string, cscILink?: string, cscIKeyPassword?: string, csaLink?: string): Promise<CodeSigningInfo> {
export function createKeychain(keychainName: string, cscLink: string, cscKeyPassword: string, cscILink?: string | null, cscIKeyPassword?: string | null, csaLink?: string | null): Promise<CodeSigningInfo> {
const certLinks = [csaLink || "https://developer.apple.com/certificationauthority/AppleWWDRCA.cer"]
if (csaLink == null) {
certLinks.push("https://startssl.com/certs/sca.code2.crt", "https://startssl.com/certs/sca.code3.crt")
Expand Down Expand Up @@ -56,14 +56,14 @@ export function createKeychain(keychainName: string, cscLink: string, cscKeyPass
})
}

async function importCerts(keychainName: string, paths: Array<string>, keyPasswords: Array<string>): Promise<CodeSigningInfo> {
async function importCerts(keychainName: string, paths: Array<string>, keyPasswords: Array<string | null | undefined>): Promise<CodeSigningInfo> {
for (let f of paths.slice(0, -keyPasswords.length)) {
await exec("security", ["import", f, "-k", keychainName, "-T", "/usr/bin/codesign"])
await exec("security", ["import", f!, "-k", keychainName, "-T", "/usr/bin/codesign"])
}

const namePromises: Array<Promise<string>> = []
for (let i = paths.length - keyPasswords.length, j = 0; i < paths.length; i++, j++) {
const password = keyPasswords[j]
const password = keyPasswords[j]!
const certPath = paths[i]
await exec("security", ["import", certPath, "-k", keychainName, "-T", "/usr/bin/codesign", "-T", "/usr/bin/productbuild", "-P", password])

Expand All @@ -81,12 +81,12 @@ async function importCerts(keychainName: string, paths: Array<string>, keyPasswo
function extractCommonName(password: string, certPath: string): BluebirdPromise<string> {
return exec("openssl", ["pkcs12", "-nokeys", "-nodes", "-passin", "pass:" + password, "-nomacver", "-clcerts", "-in", certPath])
.then(result => {
const match = result[0].toString().match(/^subject.*\/CN=([^\/\n]+)/m)
const match = <Array<string | null> | null>(result[0].toString().match(/^subject.*\/CN=([^\/\n]+)/m))
if (match == null || match[1] == null) {
throw new Error("Cannot extract common name from p12")
}
else {
return match[1]
return match[1]!
}
})
}
Expand Down
22 changes: 11 additions & 11 deletions src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ export interface Publisher {
}

export interface PublishOptions {
publish?: "onTag" | "onTagOrDraft" | "always" | "never"
githubToken?: string
publish?: "onTag" | "onTagOrDraft" | "always" | "never" | null
githubToken?: string | null
}

export class GitHubPublisher implements Publisher {
private tag: string
private _releasePromise: BluebirdPromise<Release>

get releasePromise(): Promise<Release> {
get releasePromise(): Promise<Release | null> {
return this._releasePromise
}

constructor(private owner: string, private repo: string, version: string, private token: string, private createReleaseIfNotExists: boolean = true) {
constructor(private owner: string, private repo: string, version: string, private token: string | null, private createReleaseIfNotExists: boolean = true) {
if (token == null || token.length === 0) {
throw new Error("GitHub Personal Access Token is not specified")
}
Expand All @@ -40,20 +40,20 @@ export class GitHubPublisher implements Publisher {
this._releasePromise = <BluebirdPromise<Release>>this.init()
}

private async init(): Promise<Release> {
private async init(): Promise<Release | null> {
// we don't use "Get a release by tag name" because "tag name" means existing git tag, but we draft release and don't create git tag
const releases = await gitHubRequest<Array<Release>>(`/repos/${this.owner}/${this.repo}/releases`, this.token)
for (let release of releases) {
if (release.tag_name === this.tag) {
if (!release.draft) {
if (release!.tag_name === this.tag) {
if (!release!.draft) {
if (this.createReleaseIfNotExists) {
throw new Error("Release must be a draft")
}
else {
return null
}
}
return release
return release!
}
}

Expand All @@ -70,7 +70,7 @@ export class GitHubPublisher implements Publisher {
const fileName = artifactName || basename(file)
const release = await this.releasePromise
if (release == null) {
return null
return
}

const parsedUrl = parseUrl(release.upload_url.substring(0, release.upload_url.indexOf("{")) + "?name=" + fileName)
Expand Down Expand Up @@ -113,8 +113,8 @@ export class GitHubPublisher implements Publisher {
log("Artifact %s already exists, overwrite one", fileName)
const assets = await gitHubRequest<Array<Asset>>(`/repos/${this.owner}/${this.repo}/releases/${release.id}/assets`, this.token)
for (let asset of assets) {
if (asset.name === fileName) {
await gitHubRequest<void>(`/repos/${this.owner}/${this.repo}/releases/assets/${asset.id}`, this.token, null, "DELETE")
if (asset!.name === fileName) {
await gitHubRequest<void>(`/repos/${this.owner}/${this.repo}/releases/assets/${asset!.id}`, this.token, null, "DELETE")
continue uploadAttempt
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/gitHubRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Promise as BluebirdPromise } from "bluebird"
const __awaiter = require("./awaiter")
Array.isArray(__awaiter)

export function gitHubRequest<T>(path: string, token: string, data: { [name: string]: any; } = null, method: string = "GET"): BluebirdPromise<T> {
export function gitHubRequest<T>(path: string, token: string | null, data: { [name: string]: any; } | null = null, method: string = "GET"): BluebirdPromise<T> {
const options: any = {
hostname: "api.github.com",
path: path,
Expand All @@ -27,7 +27,7 @@ export function gitHubRequest<T>(path: string, token: string, data: { [name: str
return doGitHubRequest<T>(options, token, it => it.end(encodedData))
}

export function doGitHubRequest<T>(options: RequestOptions, token: string, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void): BluebirdPromise<T> {
export function doGitHubRequest<T>(options: RequestOptions, token: string | null, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void): BluebirdPromise<T> {
if (token != null) {
(<any>options.headers).authorization = "token " + token
}
Expand Down Expand Up @@ -80,12 +80,12 @@ Please double check that your GitHub Token is correct. Due to security reasons G
addTimeOutHandler(request, reject)
request.on("error", reject)
requestProcessor(request, reject)
onCancel(() => request.abort())
onCancel!(() => request.abort())
})
}

export class HttpError extends Error {
constructor(public response: IncomingMessage, public description: any = null) {
super(response.statusCode + " " + response.statusMessage + (description == null ? "" : ("\n" + JSON.stringify(description, null, " "))) + "\nHeaders: " + JSON.stringify(response.headers, null, " "))
super(response.statusCode + " " + response.statusMessage + (description == null ? "" : ("\n" + JSON.stringify(description, <any>null, " "))) + "\nHeaders: " + JSON.stringify(response.headers, <any>null, " "))
}
}
4 changes: 2 additions & 2 deletions src/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function _download(url: string, destination: string, callback: (error: Error) =>
doDownload(url, destination, 0, callback)
}

export function addTimeOutHandler(request: ClientRequest, callback: (error: Error | string) => void) {
export function addTimeOutHandler(request: ClientRequest, callback: (error: Error) => void) {
request.on("socket", function (socket: Socket) {
socket.setTimeout(60 * 1000, () => {
callback("Request timed out")
callback(new Error("Request timed out"))
request.abort()
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/install-app-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const devPackageFile = path.join(projectDir, "package.json")
async function main() {
const devMetadata: DevMetadata = await readPackageJson(devPackageFile)
const results: Array<string> = await BluebirdPromise.all([
computeDefaultAppDirectory(projectDir, use(devMetadata.directories, it => it.app) || args.appDir),
computeDefaultAppDirectory(projectDir, use(devMetadata.directories, it => it!.app) || args.appDir),
getElectronVersion(devMetadata, devPackageFile)
])

Expand Down
12 changes: 6 additions & 6 deletions src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ Icon=${this.metadata.name}
const mappings: Array<string> = []
const pngIconsDir = path.join(this.buildResourcesDir, "icons")
for (let file of (await readdir(pngIconsDir))) {
if (file.endsWith(".png") || file.endsWith(".PNG")) {
if (file!.endsWith(".png") || file!.endsWith(".PNG")) {
// If parseInt encounters a character that is not a numeral in the specified radix,
// it returns the integer value parsed up to that point
try {
const size = parseInt(file, 10)
const size = parseInt(file!, 10)
if (size > 0) {
mappings.push(`${pngIconsDir}/${file}=/usr/share/icons/hicolor/${size}x${size}/apps/${this.metadata.name}.png`)
}
Expand Down Expand Up @@ -194,13 +194,13 @@ Icon=${this.metadata.name}
"--url", projectUrl,
]

use(this.metadata.license || this.devMetadata.license, it => args.push("--license", it))
use(this.computeBuildNumber(), it => args.push("--iteration", it))
use(this.metadata.license || this.devMetadata.license, it => args.push("--license", it!))
use(this.computeBuildNumber(), it => args.push("--iteration", it!))

use(options.fpm, it => args.push(...it))
use(options.fpm, it => args.push(...<any>it))

args.push(`${appOutDir}/=/opt/${this.appName}`)
args.push(...(await this.packageFiles))
args.push(...<any>(await this.packageFiles)!)
await exec("fpm", args)
return destination
}
Expand Down
Loading

0 comments on commit d77c8da

Please sign in to comment.