Skip to content

Commit

Permalink
refactor: extract dmg-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Aug 24, 2017
1 parent 4a2c599 commit 5f64ef7
Show file tree
Hide file tree
Showing 142 changed files with 424 additions and 335 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.

3 changes: 2 additions & 1 deletion .idea/electron-builder.iml

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

2 changes: 1 addition & 1 deletion docs/api/electron-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
| isTwoPackageJsonProjectLayoutUsed = <code>true</code>| <code>Boolean</code> |
| eventEmitter = <code>new EventEmitter()</code>| <code>internal:EventEmitter</code> |
| **appInfo**| <code>[AppInfo](#AppInfo)</code> |
| tempDirManager = <code>new TmpDir()</code>| <code>module:electron-builder-util/out/tmp.TmpDir</code> |
| tempDirManager = <code>new TmpDir()</code>| <code>module:builder-util/out/tmp.TmpDir</code> |
| options| <code>[PackagerOptions](Options#PackagerOptions)</code> |
| **repositoryInfo**| <code>Promise&lt; \| [SourceRepositoryInfo](#SourceRepositoryInfo)&gt;</code> |
| **productionDeps**| <code>[Lazy](electron-builder-http#Lazy)&lt;Array&lt;module:electron-builder/out/util/packageDependencies.Dependency&gt;&gt;</code> |
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
"private": true,
"license": "MIT",
"scripts": {
"compile": "ts-babel packages/asar-integrity packages/electron-builder-http packages/electron-builder-util packages/electron-publish packages/electron-builder packages/electron-builder-squirrel-windows packages/electron-updater packages/electron-publisher-s3 test && yarn schema",
"//": "do not wrap into single quotes - windows doesn't unwrap arg in this case",
"compile": "ts-babel \"packages/*\" test && yarn schema",
"lint": "node test/out/helpers/lint.js",
"lint-deps": "node ./test/out/helpers/checkDeps.js",
"pretest": "yarn compile && node test/out/helpers/lint.js && node ./test/out/helpers/checkDeps.js",
"///": "Please see https://github.com/electron-userland/electron-builder/blob/master/CONTRIBUTING.md#run-test-using-cli how to run particular test instead full (and very slow) run",
"test": "node ./test/out/helpers/runTests.js skipArtifactPublisher ALL_TESTS=isCi",
"test-all": "yarn pretest && node ./test/out/helpers/runTests.js",
"test-linux": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/electron-builder:wine /bin/bash -c \"yarn && yarn test\"",
"//": "Update wiki if docs changed. Update only if functionalily are generally available (latest release, not next)",
"////": "Update wiki if docs changed. Update only if functionalily are generally available (latest release, not next)",
"update-wiki": "(git branch -D wiki || true) && git subtree split -b wiki --prefix docs/ && git push -f wiki wiki:master",
"whitespace": "whitespace 'src/**/*.ts'",
"docker-images": "docker/build.sh",
"update-deps": "node ./scripts/update-deps.js",
"set-versions": "node test/out/helpers/setVersions.js",
"release": "yarn set-versions && yarn compile && ./scripts/npm-publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
"schema": "typescript-json-schema packages/electron-builder/tsconfig.json Config --out packages/electron-builder/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles --required",
"jsdoc": "ts2jsdoc packages/electron-builder-http packages/electron-updater packages/electron-builder-util packages/electron-builder packages/electron-publish",
"jsdoc": "ts2jsdoc packages/electron-builder-http packages/electron-updater packages/builder-util packages/electron-builder packages/electron-publish",
"jsdoc2md": "node scripts/jsdoc2md.js",
"api": "yarn jsdoc && yarn jsdoc2md"
},
Expand All @@ -27,6 +28,7 @@
"///": "all dependencies for all packages (hoisted)",
"dependencies": {
"7zip-bin": "^2.2.3",
"@types/debug": "^0.0.30",
"ajv": "^5.2.2",
"ajv-keywords": "^2.1.0",
"archiver": "^2.0.0",
Expand All @@ -40,7 +42,7 @@
"dotenv": "^4.0.0",
"dotenv-expand": "^4.0.1",
"ejs": "^2.5.7",
"electron-download-tf": "4.3.1",
"electron-download-tf": "4.3.4",
"electron-is-dev": "^0.3.0",
"electron-osx-sign": "0.4.7",
"fcopy-pre-bundled": "0.3.4",
Expand Down Expand Up @@ -74,8 +76,9 @@
"devDependencies": {
"@types/dotenv": "^4.0.1",
"@types/ini": "^1.3.29",
"@types/jest": "^20.0.7",
"@types/jest": "^20.0.8",
"@types/js-yaml": "^3.9.1",
"@types/sanitize-filename": "^1.1.28",
"@types/source-map-support": "^0.4.0",
"@types/xml2js": "^0.4.0",
"babel-preset-ts-node4-bluebird": "^0.1.0",
Expand All @@ -90,7 +93,7 @@
"jest-junit": "^2.1.0",
"jsdoc-to-markdown": "^3.0.0",
"path-sort": "^0.1.0",
"ts-babel": "^4.0.1",
"ts-babel": "^4.1.3",
"ts-jsdoc": "^2.0.5",
"tslint": "^5.6.0",
"typescript": "^2.5.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "electron-builder-util",
"name": "builder-util",
"version": "0.0.0-semantic-release",
"main": "out/util.js",
"author": "Vladimir Krivosheev",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# electron-builder-util
# builder-util

Part of [electron-builder](https://github.com/electron-userland/electron-builder).
7 changes: 7 additions & 0 deletions packages/builder-util/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface PackageBuilder {
readonly buildResourcesDir: string

readonly resourceList: Promise<Array<string>>

getTempFile(suffix: string): Promise<string>
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { CancellationToken } from "electron-builder-http"
import { debug } from "electron-builder-util"
import { NestedError } from "electron-builder-util/out/promise"
import { NestedError } from "./promise"
import { debug } from "./util"

export class AsyncTaskManager {
readonly tasks: Array<Promise<any>> = []
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export function toLangWithRegion(lang: string): string {
return result == null ? `${lang}_${lang.toUpperCase()}` : result
}

/** @internal */
export const lcid: any = {
af_ZA: 1078,
am_ET: 1118,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as path from "path"
import { PlatformPackager } from "../platformPackager"
import { langIdToName, toLangWithRegion } from "../util/langs"
import { PackageBuilder } from "./api"
import { langIdToName, toLangWithRegion } from "./langs"

/** @internal */
export async function getLicenseFiles(packager: PlatformPackager<any>): Promise<Array<LicenseFile>> {
export async function getLicenseFiles(packager: PackageBuilder): Promise<Array<LicenseFile>> {
const files = (await packager.resourceList)
.filter(it => {
const name = it.toLowerCase()
Expand All @@ -30,7 +29,6 @@ export async function getLicenseFiles(packager: PlatformPackager<any>): Promise<
})
}

/** @internal */
export interface LicenseFile {
file: string
lang: string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { log, warn, task, subTask } from "./log"
export { isMacOsSierra } from "./macosVersion"
export { execWine, prepareWindowsExecutableArgs } from "./wine"
export { Arch, toLinuxArchString, getArchSuffix, ArchType, archFromString } from "./arch"
export { AsyncTaskManager } from "./asyncTaskManager"

export const debug = _debug("electron-builder")
export const debug7z = _debug("electron-builder:7z")
Expand Down Expand Up @@ -72,6 +73,13 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecOp
message += `\n${yellow(stdout.toString())}`
}
if (stderr.length !== 0) {
if (file.endsWith("wine")) {
stderr = stderr.toString()
.split("\n")
.filter(it => !it.includes("wine: cannot find L\"C:\\\\windows\\\\system32\\\\winemenubuilder.exe\"") && !it.includes("err:wineboot:ProcessRunKeys Error running cmd L\"C:\\\\windows\\\\system32\\\\winemenubuilder.exe"))
.join("\n")
}

message += `\n${red(stderr.toString())}`
}

Expand Down Expand Up @@ -163,7 +171,7 @@ export function handleProcess(event: string, childProcess: ChildProcess, command

childProcess.once(event, (code: number) => {
if (code === 0 && debug.enabled) {
debug(`${command} (${childProcess.pid}) exited with exit code 0`)
debug(`${path.basename(command)} (${childProcess.pid}) exited with exit code 0`)
}

if (code === 0) {
Expand All @@ -188,10 +196,7 @@ export function use<T, R>(value: T | null, task: (it: T) => R): R | null {
export function debug7zArgs(command: "a" | "x"): Array<string> {
const args = [command, "-bd"]
if (debug7z.enabled) {
args.push("-bb3")
}
else if (!debug.enabled) {
args.push("-bb0")
args.push("-bb")
}
return args
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { isMacOsSierra } from "./macosVersion"
import { debug, exec, ExecOptions, isEnvTrue } from "./util"

const wineExecutable = new Lazy<ToolInfo>(async () => {
debug(`USE_SYSTEM_WINE: ${process.env.USE_SYSTEM_WINE}`)
if (!isEnvTrue(process.env.USE_SYSTEM_WINE) && await isMacOsSierra()) {
const isUseSystemWine = isEnvTrue(process.env.USE_SYSTEM_WINE)
if (isUseSystemWine) {
debug("Using system wine is forced")
}
if (!isUseSystemWine && await isMacOsSierra()) {
// noinspection SpellCheckingInspection
const wineDir = await getBinFromGithub("wine", "2.0.1-mac-10.12", "IvKwDml/Ob0vKfYVxcu92wxUzHu8lTQSjjb8OlCTQ6bdNpVkqw17OM14TPpzGMIgSxfVIrQZhZdCwpkxLyG3mg==")
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"../../typings/semver.d.ts",
"../../typings/stat-mode.d.ts",
"../../typings/chalk.d.ts",
"../../typings/debug.d.ts",
"../../typings/node-emoji.d.ts",
"../../typings/fcopy-pre-bundled.d.ts"
],
Expand Down
21 changes: 21 additions & 0 deletions packages/dmg-builder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "dmg-builder",
"version": "0.0.0-semantic-release",
"main": "out/httpExecutor.js",
"author": "Vladimir Krivosheev",
"license": "MIT",
"repository": "electron-userland/electron-builder",
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"files": [
"out"
],
"dependencies": {
"fs-extra-p": "^4.4.0",
"bluebird-lst": "^1.0.3",
"iconv-lite": "^0.4.18",
"parse-color": "^1.0.0",
"builder-util": "^0.0.0-semantic-release"
},
"typings": "./out/dmg.d.ts"
}
3 changes: 3 additions & 0 deletions packages/dmg-builder/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# electron-builder-http

Part of [electron-builder](https://github.com/electron-userland/electron-builder).
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { debug, exec } from "electron-builder-util"
import { debug, exec } from "builder-util"
import { PackageBuilder } from "builder-util/out/api"
import { getLicenseFiles } from "builder-util/out/license"
import { outputFile, readFile } from "fs-extra-p"
import { PlatformPackager } from "../../platformPackager"
import { getLicenseFiles } from "../license"
import { getVendorPath } from "../../util/pathManager"
import { getDmgVendorPath } from "./dmgUtil"

/** @internal */
export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath: string) {
export async function addLicenseToDmg(packager: PackageBuilder, dmgPath: string) {
const licenseFiles = await getLicenseFiles(packager)
if (licenseFiles.length === 0) {
return
Expand Down Expand Up @@ -60,7 +59,7 @@ export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath:
await exec("/usr/bin/python", [tempFile], {
env: {
...process.env,
PYTHONPATH: getVendorPath(),
PYTHONPATH: getDmgVendorPath(),
LC_CTYPE: "en_US.UTF-8",
LANG: "en_US.UTF-8",
}
Expand Down
80 changes: 80 additions & 0 deletions packages/dmg-builder/src/dmgUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import BluebirdPromise from "bluebird-lst"
import { exec } from "builder-util"
import { PackageBuilder } from "builder-util/out/api"
import { AsyncTaskManager } from "builder-util/out/asyncTaskManager"
import { executeFinally } from "builder-util/out/promise"
import { outputFile, readFile } from "fs-extra-p"
import * as path from "path"

const root = path.join(__dirname, "..")

export function getDmgTemplatePath() {
return path.join(root, "templates")
}

export function getDmgVendorPath() {
return path.join(root, "vendor")
}

export async function attachAndExecute(dmgPath: string, readWrite: boolean, task: () => Promise<any>) {
//noinspection SpellCheckingInspection
const args = ["attach", "-noverify", "-noautoopen"]
if (readWrite) {
args.push("-readwrite")
}

args.push(dmgPath)
const attachResult = await exec("hdiutil", args, {maxBuffer: 2 * 1024 * 1024})
const deviceResult = attachResult == null ? null : /^(\/dev\/\w+)/.exec(attachResult)
const device = deviceResult == null || deviceResult.length !== 2 ? null : deviceResult[1]
if (device == null) {
throw new Error(`Cannot mount: ${attachResult}`)
}

return await executeFinally(task(), () => detach(device))
}

export async function detach(name: string) {
try {
await exec("hdiutil", ["detach", name])
}
catch (e) {
await new BluebirdPromise((resolve, reject) => {
setTimeout(() => {
exec("hdiutil", ["detach", "-force", name])
.then(resolve)
.catch(reject)
}, 1000)
})
}
}

export function computeBackgroundColor(rawValue: string) {
return require("parse-color")(rawValue).hex
}

export async function computeBackground(packager: PackageBuilder) {
const resourceList = await packager.resourceList
if (resourceList.includes("background.tiff")) {
return path.join(packager.buildResourcesDir, "background.tiff")
}
else if (resourceList.includes("background.png")) {
return path.join(packager.buildResourcesDir, "background.png")
}
else {
return path.join(getDmgTemplatePath(), "background.tiff")
}
}

export async function applyProperties(entries: any, env: any, asyncTaskManager: AsyncTaskManager, packager: PackageBuilder) {
const dmgPropertiesFile = await packager.getTempFile("dmgProperties.pl")

asyncTaskManager.addTask(outputFile(dmgPropertiesFile, (await readFile(path.join(getDmgTemplatePath(), "dmgProperties.pl"), "utf-8")).replace("$ENTRIES", entries)))

await asyncTaskManager.awaitTasks()

await exec("/usr/bin/perl", [dmgPropertiesFile], {
cwd: getDmgVendorPath(),
env
})
}
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions packages/dmg-builder/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"outDir": "out"
},
"include": [
"src/**/*.ts"
]
}
3 changes: 0 additions & 3 deletions packages/electron-builder-http/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@
},
"include": [
"src/**/*.ts"
],
"files": [
"../../typings/debug.d.ts"
]
}
2 changes: 1 addition & 1 deletion packages/electron-builder-squirrel-windows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"out"
],
"dependencies": {
"electron-builder-util": "~0.0.0-semantic-release",
"builder-util": "^0.0.0-semantic-release",
"bluebird-lst": "^1.0.3",
"fs-extra-p": "^4.4.0",
"archiver": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, debug, exec, execWine, log, prepareWindowsExecutableArgs as prepareArgs, spawn } from "electron-builder-util"
import { copyFile, walk } from "electron-builder-util/out/fs"
import { Arch, debug, exec, execWine, log, prepareWindowsExecutableArgs as prepareArgs, spawn } from "builder-util"
import { copyFile, walk } from "builder-util/out/fs"
import { WinPackager } from "electron-builder/out/winPackager"
import { createWriteStream, ensureDir, remove, stat, unlink } from "fs-extra-p"
import * as path from "path"
Expand Down
Loading

0 comments on commit 5f64ef7

Please sign in to comment.