diff --git a/Makefile b/Makefile index 15f708e..4fbb4c1 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,9 @@ bin/git-sync: bin/process-version-host: go build $(GO_BUILD_ARGS) -o bin/process-version-host ./cmd/process-version-host +bin/process-version: + go build $(GO_BUILD_ARGS) -o bin/process-version ./cmd/process-version + .PHONY: schema schema: ./bin/packages human > schema_human.json diff --git a/cmd/process-version/main.go b/cmd/process-version/main.go index 6e050f8..2fb0497 100644 --- a/cmd/process-version/main.go +++ b/cmd/process-version/main.go @@ -95,12 +95,20 @@ func (j optimizeJob) emitFromWorkspace(src string) { if _, ok := doNotCompress[ext]; !ok { outBr := fmt.Sprintf("%s.br", dest) - compress.Brotli11CLI(j.Ctx, src, outBr) - log.Printf("br %s -> %s\n", src, outBr) + if _, err := os.Stat(outBr); err == nil { + log.Printf("file %s already exists at the output\n", outBr) + } else { + compress.Brotli11CLI(j.Ctx, src, outBr) + log.Printf("br %s -> %s\n", src, outBr) + } outGz := fmt.Sprintf("%s.gz", dest) - compress.Gzip9Native(j.Ctx, src, outGz) - log.Printf("gz %s -> %s\n", src, outGz) + if _, err := os.Stat(outGz); err == nil { + log.Printf("file %s already exists at the output\n", outGz) + } else { + compress.Gzip9Native(j.Ctx, src, outGz) + log.Printf("gz %s -> %s\n", src, outGz) + } } else { if err := copyFile(src, dest); err != nil { log.Fatalf("failed to copy file: %s", err) diff --git a/compress/js.go b/compress/js.go index b087816..e222154 100644 --- a/compress/js.go +++ b/compress/js.go @@ -17,18 +17,16 @@ var ( // Js performs a compression of the file. func Js(ctx context.Context, file string) *string { + if strings.HasSuffix(file, ".min.js") { + log.Printf("%s is already compressed\n", file) + return nil + } + ext := path.Ext(file) outfile := file[0:len(file)-len(ext)] + ".min.js" - // compressed file already exists, ignore if _, err := os.Stat(outfile); err == nil { - log.Printf("compressed file already exists: %s\n", outfile) - return nil - } - - // Already minified, ignore - if strings.HasSuffix(file, ".min.js") { - log.Printf("%s.min.js compressed file already exists\n", file) + log.Printf("%s already has corresponding compressed file\n", outfile) return nil } diff --git a/scripts/test-process-version.sh b/scripts/test-process-version.sh index f3fd002..0e3de69 100644 --- a/scripts/test-process-version.sh +++ b/scripts/test-process-version.sh @@ -7,8 +7,7 @@ echo "processing $package $version" export DOCKER_BUILDKIT=1 mkdir -p /tmp/input /tmp/output - -rm -rf /tmp/output/* +rm -rf /tmp/output/* /tmp/input/* echo "loading new version files" curl --fail https://storage.googleapis.com/cdnjs-incoming-prod/$package-$version.tgz > /tmp/input/new-version.tgz