From ecdf9e36ac08d43c74560d3933b5aecb08a9f6ec Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 14 Nov 2023 08:56:39 +0100 Subject: [PATCH] added make file and updated readme --- .gitignore | 3 +- Makefile | 102 ++++++++++++++++++++++++++++++ README.md | 19 ++---- scss_plugin.go => esbuild_scss.go | 36 +++++++++++ 4 files changed, 145 insertions(+), 15 deletions(-) create mode 100644 Makefile rename scss_plugin.go => esbuild_scss.go (72%) diff --git a/.gitignore b/.gitignore index 8986423..e90ba23 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.so *.h out.js -.idea \ No newline at end of file +.idea +/build \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b98996f --- /dev/null +++ b/Makefile @@ -0,0 +1,102 @@ +## Platform Makefile +## + +VERSION=0.19.5 + +platform-all: + @$(MAKE) --no-print-directory -j4 \ + platform-darwin-arm64 \ + platform-darwin-x64 \ + platform-freebsd-arm64 \ + platform-freebsd-x64 \ + platform-linux-arm \ + platform-linux-arm64 \ + platform-linux-ia32 \ + platform-linux-loong64 \ + platform-linux-mips64el \ + platform-linux-ppc64 \ + platform-linux-riscv64 \ + platform-linux-s390x \ + platform-linux-x64 \ + platform-netbsd-x64 \ + platform-openbsd-x64 \ + platform-sunos-x64 \ + platform-wasm \ + platform-win32-arm64 \ + platform-win32-ia32 \ + platform-win32-x64 + +build-win32: + CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build $(GO_FLAGS) -o "$(BUILDDIR)/package/esbuild.exe" ./esbuild_scss.go + tar -czf "build/$(GOOS)-$(GOARCH)-$(VERSION).tgz" --directory $(BUILDDIR) package + +platform-win32-x64: + @$(MAKE) --no-print-directory GOOS=windows GOARCH=amd64 BUILDDIR=build/win32-x64 build-win32 + +platform-win32-ia32: + @$(MAKE) --no-print-directory GOOS=windows GOARCH=386 BUILDDIR=build/win32-ia32 build-win32 + +platform-win32-arm64: + @$(MAKE) --no-print-directory GOOS=windows GOARCH=arm64 BUILDDIR=build/win32-arm64 build-win32 + +build-platform: + @test -n "$(GOOS)" || (echo "The environment variable GOOS must be provided" && false) + @test -n "$(GOARCH)" || (echo "The environment variable GOARCH must be provided" && false) + @test -n "$(BUILDDIR)" || (echo "The environment variable BUILDDIR must be provided" && false) + CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build $(GO_FLAGS) -o "$(BUILDDIR)/package/bin/esbuild" ./esbuild_scss.go + tar -czf "build/$(GOOS)-$(GOARCH)-$(VERSION).tgz" --directory $(BUILDDIR) package + +## Define the build targets for each platform. +platform-darwin-x64: + @$(MAKE) --no-print-directory GOOS=darwin GOARCH=amd64 BUILDDIR=build/darwin-x64 build-platform + +platform-darwin-arm64: + @$(MAKE) --no-print-directory GOOS=darwin GOARCH=arm64 BUILDDIR=build/darwin-arm64 build-platform + +platform-freebsd-x64: + @$(MAKE) --no-print-directory GOOS=freebsd GOARCH=amd64 BUILDDIR=build/freebsd-x64 build-platform + +platform-freebsd-arm64: + @$(MAKE) --no-print-directory GOOS=freebsd GOARCH=arm64 BUILDDIR=build/freebsd-arm64 build-platform + +platform-netbsd-x64: + @$(MAKE) --no-print-directory GOOS=netbsd GOARCH=amd64 BUILDDIR=build/netbsd-x64 build-platform + +platform-openbsd-x64: + @$(MAKE) --no-print-directory GOOS=openbsd GOARCH=amd64 BUILDDIR=build/openbsd-x64 build-platform + +platform-linux-x64: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=amd64 BUILDDIR=build/linux-x64 build-platform + +platform-linux-ia32: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=386 BUILDDIR=build/linux-ia32 build-platform + +platform-linux-arm: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=arm BUILDDIR=build/linux-arm build-platform + +platform-linux-arm64: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=arm64 BUILDDIR=build/linux-arm64 build-platform + +platform-linux-loong64: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=loong64 BUILDDIR=build/linux-loong64 build-platform + +platform-linux-mips64el: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=mips64le BUILDDIR=build/linux-mips64el build-platform + +platform-linux-ppc64: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=ppc64le BUILDDIR=build/linux-ppc64 build-platform + +platform-linux-riscv64: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=riscv64 BUILDDIR=build/linux-riscv64 build-platform + +platform-linux-s390x: + @$(MAKE) --no-print-directory GOOS=linux GOARCH=s390x BUILDDIR=build/linux-s390x build-platform + +platform-sunos-x64: + @$(MAKE) --no-print-directory GOOS=illumos GOARCH=amd64 BUILDDIR=build/sunos-x64 build-platform + +platform-wasm: + @$(MAKE) --no-print-directory GOOS=js GOARCH=wasm BUILDDIR=build/esbuild-wasm build-platform + +clean: + rm -rf build diff --git a/README.md b/README.md index 927f6bb..3cad736 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,13 @@ -## POC to use esbuild with java and plugins +## Scss enabled version of esbuild -This is a poc to see if we can use esbuild in java, but more integrated. -Maybe we can even use esbuild and extend it with Java based plugins. +This project extends esbuild with a scss plugin. +The normal cli still works, but it has a scss plugin added. ### To build ```cmd -go build -o libhello.so -buildmode=c-shared hello.go -chmod -x libhello.so - -mvn package -export LD_LIBRARY_PATH= - -java -jar target/go-helloworld-1.0.0-SNAPSHOT-jar-with-dependencies.jar +make platform-all ``` -### TODO -* rename this project to not be called helloworld -* make the go code call java -* create an interface for the java and go communication \ No newline at end of file +This is used by esbuild-java for the quarkus web bundler \ No newline at end of file diff --git a/scss_plugin.go b/esbuild_scss.go similarity index 72% rename from scss_plugin.go rename to esbuild_scss.go index b740f94..b226ed0 100644 --- a/scss_plugin.go +++ b/esbuild_scss.go @@ -1,9 +1,12 @@ package main import ( + "fmt" + "io" "os" "path/filepath" "strings" + "time" "github.com/bep/godartsass/v2" "github.com/evanw/esbuild/pkg/api" @@ -93,5 +96,38 @@ var scssPlugin = api.Plugin{ func main() { osArgs := os.Args[1:] + for _, arg := range osArgs { + switch { + case arg == "--version": + fmt.Printf("%s\n", "0.19.5") + os.Exit(0) + case arg == "--watch": + go func() { + // This just discards information from stdin because we don't use + // it and we can avoid unnecessarily allocating space for it + buffer := make([]byte, 512) + for { + _, err := os.Stdin.Read(buffer) + if err != nil { + + // Only exit cleanly if stdin was closed cleanly + if err == io.EOF { + os.Exit(0) + } else { + os.Exit(1) + } + } + + // Some people attempt to keep esbuild's watch mode open by piping + // an infinite stream of data to stdin such as with "< /dev/zero". + // This will make esbuild spin at 100% CPU. To avoid this, put a + // small delay after we read some data from stdin. + time.Sleep(4 * time.Millisecond) + } + }() + osArgs = osArgs[1:] + } + + } os.Exit(cli.RunWithPlugins(osArgs, []api.Plugin{scssPlugin})) }