Skip to content

Commit

Permalink
feat: use cache dir per OS convention
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Nov 5, 2016
1 parent eec5b32 commit 20a247c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ machine:
dependencies:
cache_directories:
- "~/.electron"
- "~/.cache"
- "~/.cache/electron-builder"

# https://discuss.circleci.com/t/installing-git-lfs/867
# circleci doesn't cache after test, only after deps, so, we do test in this phase
Expand All @@ -14,7 +14,7 @@ dependencies:
- sudo apt-get install git-lfs=1.3.0
- ssh git@github.com git-lfs-authenticate $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git download
- git lfs pull
- docker run --rm --env-file ./test/docker-env.list -v ${PWD}:/project -v ~/.electron:/root/.electron -v ~/.cache:/root/.cache electronuserland/electron-builder:$([ "$CIRCLE_NODE_INDEX" == "2" ] && echo "4" || echo "wine") /test.sh
- docker run --rm --env-file ./test/docker-env.list -v ${PWD}:/project -v ~/.electron:/root/.electron -v ~/.cache/electron-builder:/root/.cache/electron-builder electronuserland/electron-builder:$([ "$CIRCLE_NODE_INDEX" == "2" ] && echo "4" || echo "wine") /test.sh

test:
override:
Expand Down
4 changes: 2 additions & 2 deletions src/cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#! /usr/bin/env node

import { homedir } from "os"
import { readdir, lstat, Stats, remove, readFile } from "fs-extra-p"
import BluebirdPromise from "bluebird-lst-c"
import * as path from "path"
import { getCacheDirectory } from "./util/util"

async function main() {
const dir = path.join(homedir(), ".cache", "fpm")
const dir = path.join(getCacheDirectory(), "fpm")
let items: string[] | null = null
try {
items = await readdir(dir)
Expand Down
7 changes: 3 additions & 4 deletions src/codeSign.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { exec, getTempName, isEmptyOrSpaces, isCi } from "./util/util"
import { exec, getTempName, isEmptyOrSpaces, isCi, getCacheDirectory } from "./util/util"
import { deleteFile, outputFile, copy, rename } from "fs-extra-p"
import { download } from "./util/httpRequest"
import * as path from "path"
import { executeFinally, all } from "./util/promise"
import BluebirdPromise from "bluebird-lst-c"
import { randomBytes } from "crypto"
import { homedir } from "os"
import { TmpDir } from "./util/tmp"

const appleCertificatePrefixes = ["Developer ID Application:", "3rd Party Mac Developer Application:", "Developer ID Installer:", "3rd Party Mac Developer Installer:"]
Expand Down Expand Up @@ -39,8 +38,8 @@ let bundledCertKeychainAdded: Promise<any> | null = null
// /~https://github.com/electron-userland/electron-builder/issues/398
async function createCustomCertKeychain() {
// copy to temp and then atomic rename to final path
const tmpKeychainPath = path.join(homedir(), ".cache", getTempName("electron_builder_root_certs"))
const keychainPath = path.join(homedir(), ".cache", "electron_builder_root_certs.keychain")
const tmpKeychainPath = path.join(getCacheDirectory(), getTempName("electron-builder-root-certs"))
const keychainPath = path.join(getCacheDirectory(), "electron-builder-root-certs.keychain")
const results = await BluebirdPromise.all<string>([
exec("security", ["list-keychains"]),
copy(path.join(__dirname, "..", "certs", "root_certs.keychain"), tmpKeychainPath)
Expand Down
5 changes: 2 additions & 3 deletions src/util/binDownload.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { statOrNull, spawn, debug, debug7zArgs, getTempName } from "./util"
import { statOrNull, spawn, debug, debug7zArgs, getTempName, getCacheDirectory } from "./util"
import { rename, unlink, emptyDir } from "fs-extra-p"
import { download } from "./httpRequest"
import { path7za } from "7zip-bin"
import * as path from "path"
import { homedir } from "os"
import BluebirdPromise from "bluebird-lst-c"

const versionToPromise = new Map<string, BluebirdPromise<string>>()
Expand All @@ -30,7 +29,7 @@ export function getBin(name: string, dirName: string, url: string, sha2: string)
// * don't pollute user project dir (important in case of 1-package.json project structure)
// * simplify/speed-up tests (don't download fpm for each test project)
async function doGetBin(name: string, dirName: string, url: string, sha2: string): Promise<string> {
const cachePath = path.join(homedir(), ".cache", name)
const cachePath = path.join(getCacheDirectory(), name)
const dirPath = path.join(cachePath, dirName)

const dirStat = await statOrNull(dirPath)
Expand Down
12 changes: 12 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,16 @@ export function asArray<T>(v: n | T | Array<T>): Array<T> {
}
export function isCi(): boolean {
return (process.env.CI || "").toLowerCase() === "true"
}

export function getCacheDirectory(): string {
if (process.platform === "darwin") {
return path.join(homedir(), "Library", "Caches", "electron-builder")
}
else if (process.platform === "win32" && process.env.LOCALAPPDATA != null) {
return path.join(process.env.LOCALAPPDATA, "electron-builder", "cache")
}
else {
return path.join(homedir(), ".cache", "electron-builder")
}
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,8 @@ globals@^9.0.0:
resolved "https://registry.yarnpkg.com/globals/-/globals-9.12.0.tgz#992ce90828c3a55fa8f16fada177adb64664cf9d"

globby@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-6.0.0.tgz#8f5710eda32296ac53f011a97dccc70e936685dc"
version "6.1.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
dependencies:
array-union "^1.0.1"
glob "^7.0.3"
Expand Down Expand Up @@ -3449,8 +3449,8 @@ regenerate@^1.2.1:
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.1.tgz#0300203a5d2fdcf89116dce84275d011f5903f33"

regenerator-runtime@^0.9.5:
version "0.9.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.5.tgz#403d6d40a4bdff9c330dd9392dcbb2d9a8bba1fc"
version "0.9.6"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.6.tgz#d33eb95d0d2001a4be39659707c51b0cb71ce029"

regex-cache@^0.4.2:
version "0.4.3"
Expand Down Expand Up @@ -3986,8 +3986,8 @@ typedarray@~0.0.5:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^2.1.0-dev.20161101:
version "2.1.0-dev.20161104"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.0-dev.20161104.tgz#01ebabbc76b36c6fb56a77f9df34fc7fe5fe8512"
version "2.1.0-dev.20161105"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.0-dev.20161105.tgz#be261e6cfeccaad5026aeab22f938ae0d91f5897"

uc.micro@^1.0.1, uc.micro@^1.0.3:
version "1.0.3"
Expand Down

0 comments on commit 20a247c

Please sign in to comment.