Skip to content

Commit

Permalink
fix: unify cache folder handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Oct 19, 2023
1 parent 5fe5ef7 commit 4abb10d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
13 changes: 5 additions & 8 deletions internal/esbuild/sass.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"

"github.com/FriendsOfShopware/shopware-cli/internal/system"
"github.com/FriendsOfShopware/shopware-cli/logging"
)

const dartSassVersion = "1.67.0"
const dartSassVersion = "1.69.4"

//go:embed static/variables.scss
var scssVariables []byte
Expand All @@ -30,14 +32,9 @@ func downloadDartSass(ctx context.Context) (string, error) {
return path, nil
}

cacheDir, err := os.UserCacheDir()
if err != nil {
cacheDir = "/tmp"
}

cacheDir += "/dart-sass-" + dartSassVersion
cacheDir := path.Join(system.GetShopwareCliCacheDir(), "dart-sass", dartSassVersion)

expectedPath := fmt.Sprintf("%s/sass", cacheDir)
expectedPath := path.Join(cacheDir, "sass")

if _, err := os.Stat(expectedPath); err == nil {
return expectedPath, nil
Expand Down
12 changes: 5 additions & 7 deletions internal/phplint/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ import (
"os"
"path"

"github.com/FriendsOfShopware/shopware-cli/internal/system"
"github.com/FriendsOfShopware/shopware-cli/logging"
)

func getShopwareCliCacheDir() string {
cacheDir, _ := os.UserCacheDir()

return path.Join(cacheDir, "shopware-cli")
}

func findPHPWasmFile(ctx context.Context, phpVersion string) ([]byte, error) {
expectedFile := "php-" + phpVersion + ".wasm"
expectedPathLocation := path.Join(getShopwareCliCacheDir(), "wasm", "php", expectedFile)
expectedPathLocation := path.Join(system.GetShopwareCliCacheDir(), "wasm", "php", expectedFile)

if _, err := os.Stat(expectedPathLocation); err == nil {
logging.FromContext(ctx).Infof("Using existing PHP %s wasm build from %s", phpVersion, expectedPathLocation)
return os.ReadFile(expectedPathLocation)
}

logging.FromContext(ctx).Infof("Downloading PHP %s wasm build", phpVersion)

downloadUrl := "https://github.com/FriendsOfShopware/php-cli-wasm-binaries/releases/download/1.0.0/" + expectedFile

r, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadUrl, nil)
Expand Down
3 changes: 2 additions & 1 deletion internal/phplint/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"path"

"github.com/FriendsOfShopware/shopware-cli/internal/system"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)

func getWazeroRuntime(ctx context.Context) (wazero.Runtime, error) {
cache, err := wazero.NewCompilationCacheWithDir(path.Join(getShopwareCliCacheDir(), "wasm", "cache"))
cache, err := wazero.NewCompilationCacheWithDir(path.Join(system.GetShopwareCliCacheDir(), "wasm", "cache"))
if err != nil {
return nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions internal/system/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package system

import (
"os"
"path"
)

func GetShopwareCliCacheDir() string {
cacheDir, _ := os.UserCacheDir()

return path.Join(cacheDir, "shopware-cli")
}

0 comments on commit 4abb10d

Please sign in to comment.