diff --git a/Taskfile.yaml b/Taskfile.yaml index d112ea8..1198546 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -16,6 +16,7 @@ vars: includes: frontend: task/frontend.yaml backend: task/backend.yaml + yjs: task/yjs.yaml e2e: task/e2e.yaml container: task/container.yaml deploy: task/deploy.yaml @@ -45,6 +46,7 @@ tasks: build: cmds: - rm -f build/nutsh + - task: yjs:build - task: frontend:build - task: docs:build - task: backend:build diff --git a/app/yjs-server/build.sh b/app/yjs-server/build.sh new file mode 100644 index 0000000..fee1044 --- /dev/null +++ b/app/yjs-server/build.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# map Go's os and arch to Node's +os="" +if [ "$GOOS" == "linux" ]; then + os="linux" +elif [ "$GOOS" == "darwin" ]; then + os="mac" +fi + +arch="" +if [ "$GOARCH" == "amd64" ]; then + arch="x64" +elif [ "$GOARCH" == "arm64" ]; then + arch="arm64" +fi + +cmd_base="pkg -c pkg.json --output bin/yjs-server" +input_file="dist/yjs-server.js" + +# if both os and arch are set, modify the command to include the -t option +if [[ -n "$os" && -n "$arch" ]]; then + target="node20-${os}-${arch}" + cmd="$cmd_base -t ${target} $input_file" +else + # bundle for the current platform + cmd="$cmd_base $input_file" +fi + +# execute the command +echo "Executing command: $cmd" +$cmd diff --git a/app/yjs-server/pack.sh b/app/yjs-server/pack.sh new file mode 100644 index 0000000..75e6740 --- /dev/null +++ b/app/yjs-server/pack.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# map Go's os and arch to Node's +os="" +if [ "$GOOS" == "linux" ]; then + os="linux" +elif [ "$GOOS" == "darwin" ]; then + os="mac" +fi + +arch="" +if [ "$GOARCH" == "amd64" ]; then + arch="x64" +elif [ "$GOARCH" == "arm64" ]; then + arch="arm64" +fi + +rm -rf node_modules + +# if both GOOS and GOARCH are set, modify the command to include the -t option +if [[ -n "$os" && -n "$arch" ]]; then + # install dependencies w.r.t the os and arch + echo "Cross-building for ${os}-${arch}" + npm_config_platform=${os} npm_config_arch=${arch} npm install +else + # install dependencies for the current platform + echo "Building for the current platform" + npm install +fi + +# build +cross-env TS_NODE_PROJECT=\"tsconfig.webpack.json\" webpack \ No newline at end of file diff --git a/app/yjs-server/package.json b/app/yjs-server/package.json index e762911..a25a174 100644 --- a/app/yjs-server/package.json +++ b/app/yjs-server/package.json @@ -4,8 +4,8 @@ "scripts": { "dev": "nodemon src/index.ts", "lint": "eslint src/", - "build": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack.json\" webpack", - "bundle": "pkg -c pkg.json --output bin/yjs-server dist/yjs-server.js" + "pack": "bash pack.sh", + "build": "bash build.sh" }, "devDependencies": { "@types/node": "^20.11.20", diff --git a/task/yjs.yaml b/task/yjs.yaml new file mode 100644 index 0000000..435ddcb --- /dev/null +++ b/task/yjs.yaml @@ -0,0 +1,18 @@ +version: "3" + +tasks: + start: + cmds: + - npm run dev + dir: app/yjs-server + + pack: + cmds: + - npm run pack + dir: app/yjs-server + + build: + deps: [pack] + cmds: + - npm run build + dir: app/yjs-server