Skip to content

Commit

Permalink
feat: support electron package electron-userland/electron-prebuilt#160
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Aug 4, 2016
1 parent 1778a8d commit aa0682f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Here documented only `electron-builder` specific options:
| app-category-type | <a name="BuildMetadata-app-category-type"></a><p>*macOS-only.* The application category type, as shown in the Finder via *View -&gt; Arrange by Application Category* when viewing the Applications directory.</p> <p>For example, <code>app-category-type=public.app-category.developer-tools</code> will set the application category to *Developer Tools*.</p> <p>Valid values are listed in [Apple’s documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).</p>
| asar | <a name="BuildMetadata-asar"></a><p>Whether to package the application’s source code into an archive, using [Electron’s archive format](https://github.com/electron/asar). Defaults to <code>true</code>. Reasons why you may want to disable this feature are described in [an application packaging tutorial in Electron’s documentation](http://electron.atom.io/docs/latest/tutorial/application-packaging/#limitations-on-node-api/).</p> <p>Or you can pass object of any asar options.</p> <p>electron-builder detects node modules that must be unpacked automatically, you don’t need to explicitly set <code>asar.unpackDir</code> - please file issue if this doesn’t work.</p>
| productName | <a name="BuildMetadata-productName"></a>See [AppMetadata.productName](#AppMetadata-productName).
| files | <a name="BuildMetadata-files"></a><p>A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package. See [File Patterns](#multiple-glob-patterns).</p>
| files | <a name="BuildMetadata-files"></a><p>A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package.</p> <p>See [File Patterns](#multiple-glob-patterns).</p>
| extraResources | <a name="BuildMetadata-extraResources"></a><p>A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the project directory, when specified, copy the file or directory with matching names directly into the app’s resources directory (<code>Contents/Resources</code> for MacOS, <code>resources</code> for Linux/Windows).</p> <p>Glob rules the same as for [files](#multiple-glob-patterns).</p>
| extraFiles | <a name="BuildMetadata-extraFiles"></a>The same as [extraResources](#BuildMetadata-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows).
| mac | <a name="BuildMetadata-mac"></a>See [.build.mac](#MacOptions).
Expand Down
1 change: 1 addition & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface BuildMetadata {

/**
A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package.
See [File Patterns](#multiple-glob-patterns).
*/
readonly files?: Array<string> | string | null
Expand Down
2 changes: 1 addition & 1 deletion src/util/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function minimatchAll(path: string, patterns: Array<Minimatch>): boolean {
}

// partial match — pattern: foo/bar.txt path: foo — we must allow foo
// use it only for non-negate patterns: const m = new Minimatch("!node_modules/@(electron-download|electron-prebuilt)/**/*", {dot: true }); m.match("node_modules", true) will return false, but must be true
// use it only for non-negate patterns: const m = new Minimatch("!node_modules/@(electron-download|electron)/**/*", {dot: true }); m.match("node_modules", true) will return false, but must be true
match = pattern.match(path, !pattern.negate)
}
return match
Expand Down
29 changes: 16 additions & 13 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,37 @@ export async function getElectronVersion(packageData: any, packageJsonPath: stri
if (build != null && build.electronVersion != null) {
return build.electronVersion
}
try {
return (await readJson(path.join(path.dirname(packageJsonPath), "node_modules", "electron-prebuilt", "package.json"))).version
}
catch (e) {
if (e.code !== "ENOENT") {
warn(`Cannot read electron version from electron-prebuilt package.json: ${e.message}`)

for (let name of ["electron", "electron-prebuilt", "electron-prebuilt-compile"]) {
try {
return (await readJson(path.join(path.dirname(packageJsonPath), "node_modules", name, "package.json"))).version
}
catch (e) {
if (e.code !== "ENOENT") {
warn(`Cannot read electron version from ${name} package.json: ${e.message}`)
}
}
}

const electronPrebuiltDep = findFromElectronPrebuilt(packageData)
if (electronPrebuiltDep == null) {
throw new Error("Cannot find electron-prebuilt dependency to get electron version in the '" + packageJsonPath + "'")
throw new Error("Cannot find electron dependency to get electron version in the '" + packageJsonPath + "'")
}

const firstChar = electronPrebuiltDep[0]
return firstChar === "^" || firstChar === "~" ? electronPrebuiltDep.substring(1) : electronPrebuiltDep
}

function findFromElectronPrebuilt(packageData: any): any {
for (let name of ["electron-prebuilt", "electron-prebuilt-compile"]) {
for (let name of ["electron", "electron-prebuilt", "electron-prebuilt-compile"]) {
const devDependencies = packageData.devDependencies
let electronPrebuiltDep = devDependencies == null ? null : devDependencies[name]
if (electronPrebuiltDep == null) {
let dep = devDependencies == null ? null : devDependencies[name]
if (dep == null) {
const dependencies = packageData.dependencies
electronPrebuiltDep = dependencies == null ? null : dependencies[name]
dep = dependencies == null ? null : dependencies[name]
}
if (electronPrebuiltDep != null) {
return electronPrebuiltDep
if (dep != null) {
return dep
}
}
return null
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/app-executable-deps/app/start-electron.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const electron = require('electron-prebuilt'),
const electron = require('electron'),
proc = require('child_process'),
child = proc.spawn(electron, ['.']);
2 changes: 1 addition & 1 deletion test/fixtures/app-executable-deps/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"electron-builder": "next",
"electron-prebuilt": "^1.3.2"
"electron": "^1.3.2"
},
"build": {
"app-category-type": "public.app-category.business"
Expand Down
19 changes: 17 additions & 2 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,35 @@ test("relative index", () => assertPack("test-app", allPlatforms(false), {

const electronVersion = "1.3.2"

test.ifNotWindows("electron version from electron-prebuilt dependency", () => assertPack("test-app-one", {
test.ifDevOrLinuxCi("electron version from electron-prebuilt dependency", () => assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
}, {
tempDirCreated: projectDir => BluebirdPromise.all([
outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), {
version: electronVersion
}),
modifyPackageJson(projectDir, data => {
delete data.build.electronVersion
data.devDependencies = {}
})
])
}))

test.ifNotWindows("electron version from build", () => assertPack("test-app-one", {
test.ifDevOrLinuxCi("electron version from electron dependency", () => assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
}, {
tempDirCreated: projectDir => BluebirdPromise.all([
outputJson(path.join(projectDir, "node_modules", "electron", "package.json"), {
version: electronVersion
}),
modifyPackageJson(projectDir, data => {
delete data.build.electronVersion
data.devDependencies = {}
})
])
}))

test.ifDevOrLinuxCi("electron version from build", () => assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
}, {
tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
Expand Down

0 comments on commit aa0682f

Please sign in to comment.