Skip to content

Commit

Permalink
feat: support finding electron version in build.electronVersion or el…
Browse files Browse the repository at this point in the history
…ectron-prebuilt-compile
  • Loading branch information
develar committed May 26, 2016
1 parent 73e7c14 commit 4c1f06d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

# For all files in this project:
# - 2-space soft tabs
# - All files end with a line-break
# - Trim trailing whitespace
[*]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ before_install:

install:
- nvm install $NODE_VERSION
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$NODE_VERSION" == "4" ]]; then npm install npm -g ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" || "$NODE_VERSION" == "6" ]]; then npm install && npm prune ; fi
- if [[ "$NODE_VERSION" == "4" ]]; then npm install npm -g ; fi
- npm install
- npm prune

script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm run test ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run --rm -v ${PWD}:/project -v ~/.electron:/root/.electron electronuserland/electron-builder:wine /test.sh ; fi

after_success:
- node out/cleanup.js
- if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" && "$AUTO_PUBLISH" != "false" && "$NODE_VERSION" == "6" ]]; then npm run semantic-release ; fi
- if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" && "$AUTO_PUBLISH" != "false" ]]; then npm run semantic-release ; fi

branches:
except:
Expand Down
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ cache:
install:
- ps: Install-Product node 6 x64
- npm install npm -g
- node -v
- npm -v
- npm prune
- npm install
- npm prune

build: off

Expand Down
28 changes: 21 additions & 7 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ export function handleProcess(event: string, childProcess: ChildProcess, command
}

export async function getElectronVersion(packageData: any, packageJsonPath: string): Promise<string> {
const build = packageData.build
// build is required, but this check is performed later, so, we should check for null
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
}
Expand All @@ -133,13 +138,7 @@ export async function getElectronVersion(packageData: any, packageJsonPath: stri
}
}

const devDependencies = packageData.devDependencies
let electronPrebuiltDep = devDependencies == null ? null : devDependencies["electron-prebuilt"]
if (electronPrebuiltDep == null) {
const dependencies = packageData.dependencies
electronPrebuiltDep = dependencies == null ? null : dependencies["electron-prebuilt"]
}

const electronPrebuiltDep = findFromElectronPrebuilt(packageData)
if (electronPrebuiltDep == null) {
throw new Error("Cannot find electron-prebuilt dependency to get electron version in the '" + packageJsonPath + "'")
}
Expand All @@ -148,6 +147,21 @@ export async function getElectronVersion(packageData: any, packageJsonPath: stri
return firstChar === "^" || firstChar === "~" ? electronPrebuiltDep.substring(1) : electronPrebuiltDep
}

function findFromElectronPrebuilt(packageData: any): any {
for (let name of ["electron-prebuilt", "electron-prebuilt-compile"]) {
const devDependencies = packageData.devDependencies
let electronPrebuiltDep = devDependencies == null ? null : devDependencies[name]
if (electronPrebuiltDep == null) {
const dependencies = packageData.dependencies
electronPrebuiltDep = dependencies == null ? null : dependencies[name]
}
if (electronPrebuiltDep != null) {
return electronPrebuiltDep
}
}
return null
}

export async function statOrNull(file: string): Promise<Stats | null> {
try {
return await stat(file)
Expand Down
19 changes: 17 additions & 2 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,32 @@ test("relative index", () => assertPack("test-app", allPlatforms(false), {
}, true)
}))

test("version from electron-prebuilt dependency", () => assertPack("test-app-one", currentPlatform(false), {
const electronVersion = "0.37.8"

test("electron version from electron-prebuilt dependency", () => assertPack("test-app-one", {
platform: [Platform.LINUX],
dist: false,
}, {
tempDirCreated: projectDir => BluebirdPromise.all([
outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), {
version: "0.37.8"
version: electronVersion
}),
modifyPackageJson(projectDir, data => {
data.devDependencies = {}
})
])
}))

test("electron version from build", () => assertPack("test-app-one", {
platform: [Platform.LINUX],
dist: false,
}, {
tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.devDependencies = {}
data.build.electronVersion = electronVersion
})
}))

test("www as default dir", () => assertPack("test-app", currentPlatform(), {
tempDirCreated: projectDir => move(path.join(projectDir, "app"), path.join(projectDir, "www"))
}))
Expand Down

0 comments on commit 4c1f06d

Please sign in to comment.