From 3d14e4fdbe590215d770ace36a5ced9fb9ec886e Mon Sep 17 00:00:00 2001 From: Braxen Date: Tue, 7 Nov 2023 17:10:29 +0100 Subject: [PATCH] try converting packer to bash --- pack-dev.sh | 3 +- pack.mjs | 77 +++++++++++++++++++++++++++---------------------- pack.sh | 3 +- packer-main.sh | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 37 deletions(-) create mode 100644 packer-main.sh diff --git a/pack-dev.sh b/pack-dev.sh index 3ca276fd..d1931018 100644 --- a/pack-dev.sh +++ b/pack-dev.sh @@ -1,2 +1,3 @@ #!/bin/bash -node ./pack.mjs --prerelease \ No newline at end of file +#node ./pack.mjs --prerelease +./packer-main.sh --prerelease \ No newline at end of file diff --git a/pack.mjs b/pack.mjs index 865a5235..661d591d 100644 --- a/pack.mjs +++ b/pack.mjs @@ -1,10 +1,18 @@ -import util from "node:util"; -import fs from "node:fs"; import exec from "node:child_process"; -const client_version = JSON.parse(fs.readFileSync("./client-vue/package.json")).version; -const server_version = JSON.parse(fs.readFileSync("./server/package.json")).version; -const dumper_version = JSON.parse(fs.readFileSync("./twitch-chat-dumper/package.json")).version; -const vodchat_version = JSON.parse(fs.readFileSync("./twitch-vod-chat/package.json")).version; +import fs from "node:fs"; +import util from "node:util"; +const client_version = JSON.parse( + fs.readFileSync("./client-vue/package.json") +).version; +const server_version = JSON.parse( + fs.readFileSync("./server/package.json") +).version; +const dumper_version = JSON.parse( + fs.readFileSync("./twitch-chat-dumper/package.json") +).version; +const vodchat_version = JSON.parse( + fs.readFileSync("./twitch-vod-chat/package.json") +).version; const pexec = util.promisify(exec.exec); @@ -16,49 +24,51 @@ console.log(`twitch-vod-chat version: ${vodchat_version}`); const prerelease = process.argv.includes("--prerelease"); // simple iso date string without time -const date_string = new Date().toISOString().split('T')[0]; +const date_string = new Date().toISOString().split("T")[0]; -const release_name = `LiveStreamDVR-${date_string}-c${client_version}-s${server_version}-d${dumper_version}-v${vodchat_version}${prerelease ? "-alpha" : ""}`; +const release_name = `LiveStreamDVR-${date_string}-c${client_version}-s${server_version}-d${dumper_version}-v${vodchat_version}${ + prerelease ? "-alpha" : "" +}`; if (fs.existsSync(`./release/${release_name}.zip`)) { - fs.unlinkSync(`./release/${release_name}.zip`); + fs.unlinkSync(`./release/${release_name}.zip`); } console.log(`Release name: ${release_name}`); console.log("Building..."); // build twitch-vod-chat -await pexec('cd twitch-vod-chat && yarn install && yarn run buildlib'); +await pexec("cd twitch-vod-chat && yarn install && yarn run buildlib"); console.log("twitch-vod-chat built"); // build client -await pexec('cd client-vue && yarn install && yarn run build'); +await pexec("cd client-vue && yarn install && yarn run build"); console.log("Client built"); // build server -await pexec('cd server && yarn install && yarn run build'); +await pexec("cd server && yarn install && yarn run build"); console.log("Server built"); // build twitch-chat-dumper -await pexec('cd twitch-chat-dumper && yarn install && yarn run build'); +await pexec("cd twitch-chat-dumper && yarn install && yarn run build"); console.log("twitch-chat-dumper built"); // package files await pexec( - `7za a -tzip -xr!node_modules ./release/${release_name}.zip ` + - `client-vue/dist ` + + `7za a -tzip -xr!node_modules ./release/${release_name}.zip ` + + `client-vue/dist ` + `client-vue/package.json ` + - `server/build ` + + `server/build ` + `server/package.json ` + - `server/tsconfig.json ` + + `server/tsconfig.json ` + `twitch-chat-dumper/build ` + // `twitch-vod-chat/dist ` + `start.bat ` + `start.sh ` + - `requirements.txt ` + + `requirements.txt ` + `binaries.txt ` + - `Pipfile ` + - `Pipfile.lock ` + + `Pipfile ` + + `Pipfile.lock ` + `README.md ` + `LICENSE ` ); @@ -67,24 +77,21 @@ console.log("Files packaged"); // output metadata fs.writeFileSync( - `./release/${release_name}.json`, - JSON.stringify({ - client_version, - server_version, - dumper_version, - vodchat_version, - release_name - }) + `./release/${release_name}.json`, + JSON.stringify({ + client_version, + server_version, + dumper_version, + vodchat_version, + release_name, + }) ); -fs.writeFileSync( - `./release_name.txt`, - release_name -); +fs.writeFileSync(`./release_name.txt`, release_name); fs.writeFileSync( - `./release_notes.md`, - `This release was created automatically by the build script.\n\n` + + `./release_notes.md`, + `This release was created automatically by the build script.\n\n` + `It includes the following versions:\n\n` + `* Client: ${client_version}\n` + `* Server: ${server_version}\n` + @@ -98,7 +105,7 @@ console.log("Metadata written"); // upload to github await pexec( - `gh release create ${release_name} ` + + `gh release create ${release_name} ` + `./release/${release_name}.zip ` + `-t "${release_name}" ` + // title // `-n "${release_name}" ` + // description diff --git a/pack.sh b/pack.sh index b82d48a5..6cb0702c 100644 --- a/pack.sh +++ b/pack.sh @@ -1,2 +1,3 @@ #!/bin/bash -node ./pack.mjs \ No newline at end of file +# node ./pack.mjs +./packer-main.sh \ No newline at end of file diff --git a/packer-main.sh b/packer-main.sh new file mode 100644 index 00000000..4fed6814 --- /dev/null +++ b/packer-main.sh @@ -0,0 +1,78 @@ +#!/bin/bash +set set -euxo pipefail # exit with nonzero exit code if anything fails + +client_version=$(cat ./client-vue/package.json | jq -r '.version') +server_version=$(cat ./server/package.json | jq -r '.version') +dumper_version=$(cat ./twitch-chat-dumper/package.json | jq -r '.version') +vodchat_version=$(cat ./twitch-vod-chat/package.json | jq -r '.version') + +echo "Client version: $client_version" +echo "Server version: $server_version" +echo "twitch-chat-dumper version: $dumper_version" +echo "twitch-vod-chat version: $vodchat_version" + +prerelease=false +if [[ "$@" == *"--prerelease"* ]]; then + prerelease=true +fi + +# simple iso date string without time +date_string=$(date -u +"%Y-%m-%d") + +release_name="LiveStreamDVR-${date_string}-c${client_version}-s${server_version}-d${dumper_version}-v${vodchat_version}" +if [ "$prerelease" = true ]; then + release_name="${release_name}-alpha" +fi + +if [ -f "./release/${release_name}.zip" ]; then + rm "./release/${release_name}.zip" +fi + +echo "Release name: $release_name" +echo "Building..." + +# build twitch-vod-chat +cd twitch-vod-chat && yarn install && yarn run buildlib && cd .. + +echo "twitch-vod-chat built" + +# build client +cd client-vue && yarn install && yarn run build && cd .. + +echo "Client built" + +# build server +cd server && yarn install && yarn run build && cd .. + +echo "Server built" + +# build twitch-chat-dumper +cd twitch-chat-dumper && yarn install && yarn run build && cd .. + +echo "twitch-chat-dumper built" + +# package files +7za a -tzip -xr!node_modules "./release/${release_name}.zip" \ + "client-vue/dist" \ + "client-vue/package.json" \ + "server/build" \ + "server/package.json" \ + "server/tsconfig.json" \ + "twitch-chat-dumper/build" \ + "start.bat" \ + "start.sh" \ + "requirements.txt" \ + "binaries.txt" \ + "Pipfile" \ + "Pipfile.lock" \ + "README.md" \ + "LICENSE" + +echo "Files packaged" + +# output metadata +echo "{\"client_version\":\"$client_version\",\"server_version\":\"$server_version\",\"dumper_version\":\"$dumper_version\",\"vodchat_version\":\"$vodchat_version\",\"release_name\":\"$release_name\"}" > "./release/${release_name}.json" + +echo "$release_name" > "./release_name.txt" + +echo -e "This release was created automatically by the build script.\n\nIt includes the following versions:\n\n* Client: $client_version\n* Server: $server_version\n* twitch-chat-dumper: $dumper_version\n* twitch-vod-chat: $vodchat_version\n\n## Changelog\n\n" > "./release_notes.md"