diff --git a/.github/workflows/matter.yml b/.github/workflows/matter.yml index 51546d6b42..50420f39c5 100644 --- a/.github/workflows/matter.yml +++ b/.github/workflows/matter.yml @@ -89,7 +89,10 @@ jobs: - name: Build & Release for Linux if: startsWith(matrix.os, 'ubuntu') run: | - node src-script/build-release-package.js --platform l + npm run pack:linux + npm run pkg:linux + ls ./dist/ + npm run pack:cli:linux mv dist/zap-linux-amd64.deb dist/zap-linux-x64.deb mv dist/zap-linux-x86_64.rpm dist/zap-linux-x64.rpm diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee482a3c19..72a9247aab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -236,200 +236,86 @@ jobs: # CSC_LINK: ${{ secrets.api_key_id }} # CSC_KEY_PASSWORD: ${{ secrets.api_key_issuer_id }} - - name: Verify files in Linux x64 .zip package + - name: Verify zap-cli exists in Linux x64 .zip package if: startsWith(matrix.os, 'ubuntu') run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if ./node_modules/7zip-bin/linux/x64/7za l ./dist/zap-linux-x64.zip | grep -q "$file"; then - echo "✅ Found $file" - else - echo "❌ Missing $file" - exit 1 - fi - done - - - name: Verify files in Linux arm64 .zip package - if: startsWith(matrix.os, 'ubuntu') - run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if ./node_modules/7zip-bin/linux/x64/7za l ./dist/zap-linux-arm64.zip | grep -q "$file"; then - echo "✅ Found $file" - else - echo "❌ Missing $file" - exit 1 - fi - done - - - name: Verify files in Linux x64 .deb package - if: startsWith(matrix.os, 'ubuntu') - run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if dpkg-deb -c ./dist/zap-linux-x64.deb | awk '{print $6}' | grep -q "$file"; then - echo "✅ Found $file in .deb package" - else - echo "❌ Missing $file in .deb package" - exit 1 - fi - done - - - name: Verify files in Linux x64 .rpm package - if: startsWith(matrix.os, 'ubuntu') - run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if rpm2cpio ./dist/zap-linux-x64.rpm | cpio -t | grep -q "$file"; then - echo "✅ Found $file in .rpm package" - else - echo "❌ Missing $file in .rpm package" - exit 1 - fi - done - - - name: Verify files in macOS x64 .zip package - if: startsWith(matrix.os, 'macos') - run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if 7za l ./dist/zap-mac-x64.zip | grep -q "$file"; then - echo "✅ Found $file" - else - echo "❌ Missing $file" - exit 1 - fi - done - - - name: Verify files in macOS arm64 .zip package - if: startsWith(matrix.os, 'macos') - run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if 7za l ./dist/zap-mac-arm64.zip | grep -q "$file"; then - echo "✅ Found $file" - else - echo "❌ Missing $file" - exit 1 - fi - done - - - name: Verify files in Windows x64 .zip package - if: startsWith(matrix.os, 'macos') - run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if 7za l ./dist/zap-win-x64.zip | grep -q "$file"; then - echo "✅ Found $file" - else - echo "❌ Missing $file" - exit 1 - fi - done - - - name: Verify files in Windows arm64 .zip package - if: startsWith(matrix.os, 'macos') - run: | - files=("zap-cli" "zap.png" "apack.json") - for file in "${files[@]}"; do - if 7za l ./dist/zap-win-arm64.zip | grep -q "$file"; then - echo "✅ Found $file" - else - echo "❌ Missing $file" - exit 1 - fi - done - - - name: Verify apack.json in Linux app.asar + output=$(./node_modules/7zip-bin/linux/x64/7za l ./dist/zap-linux-x64.zip) + expression=zap-cli + if [[ $output == *"$expression"* ]]; then + echo "Output contains $expression" + else + echo "Output does not contain $expression" + exit 1 + fi + - name: Verify zap-cli exists in Linux arm64 .zip package if: startsWith(matrix.os, 'ubuntu') run: | - archive="dist/linux-unpacked/resources/app.asar" - npx asar l "$archive" | grep -q "apack.json" && echo "✅ apack.json found" || (echo "❌ apack.json missing in $archive" && exit 1) - - - name: Verify apack.json in Windows x64 app.asar - if: startsWith(matrix.os, 'macos') - run: | - archive="dist/win-unpacked/resources/app.asar" - npx asar l "$archive" | grep -q "apack.json" && echo "✅ apack.json found" || (echo "❌ apack.json missing in $archive" && exit 1) - - - name: Verify apack.json in Windows arm64 app.asar + output=$(./node_modules/7zip-bin/linux/x64/7za l ./dist/zap-linux-arm64.zip) + expression=zap-cli + if [[ $output == *"$expression"* ]]; then + echo "Output contains $expression" + else + echo "Output does not contain $expression" + exit 1 + fi + - name: Verify zap-cli exists in Windows x64 .zip package if: startsWith(matrix.os, 'macos') run: | - archive="dist/win-arm64-unpacked/resources/app.asar" - npx asar l "$archive" | grep -q "apack.json" && echo "✅ apack.json found" || (echo "❌ apack.json missing in $archive" && exit 1) - - - name: Verify apack.json in macOS x64 app.asar + output=$(7za l ./dist/zap-win-x64.zip) + expression=zap-cli + if [[ $output == *"$expression"* ]]; then + echo "Output contains $expression" + else + echo "Output does not contain $expression" + exit 1 + fi + - name: Verify zap-cli exists in Windows arm64 .zip package if: startsWith(matrix.os, 'macos') run: | - archive="dist/mac/zap.app/Contents/Resources/app.asar" - npx asar l "$archive" | grep -q "apack.json" && echo "✅ apack.json found" || (echo "❌ apack.json missing in $archive" && exit 1) - - - name: Verify apack.json in macOS arm64 app.asar + output=$(7za l ./dist/zap-win-arm64.zip) + expression=zap-cli + if [[ $output == *"$expression"* ]]; then + echo "Output contains $expression" + else + echo "Output does not contain $expression" + exit 1 + fi + - name: Verify zap-cli exists in macOS x64 .zip package if: startsWith(matrix.os, 'macos') run: | - archive="dist/mac-arm64/zap.app/Contents/Resources/app.asar" - npx asar l "$archive" | grep -q "apack.json" && echo "✅ apack.json found" || (echo "❌ apack.json missing in $archive" && exit 1) + output=$(7za l ./dist/zap-mac-x64.zip | grep zap-cli) + expression=zap-cli + if [[ $output == *"$expression"* ]]; then + echo "Output contains $expression" + else + echo "Output does not contain $expression" + exit 1 + fi - name: ZAP binary check (macOS x64) - unzip if: startsWith(matrix.os, 'macos') - run: unzip dist/zap-mac-x64.zip -d dist/zap-mac-x64 - - name: ZAP binary check (macOS x64) - sanity check - if: startsWith(matrix.os, 'macos') - run: | - ./dist/zap-mac-x64/zap-cli --version - ./dist/zap-mac-x64/zap.app/Contents/MacOS/zap --version + run: unzip dist/zap-mac-x64.zip -d dist/zap-mac - name: ZAP binary check (macOS x64) - check version is set if: startsWith(matrix.os, 'macos') uses: GuillaumeFalourd/assert-command-line-output@v2.1 with: - command_line: ./dist/zap-mac-x64/zap.app/Contents/MacOS/zap --version + command_line: ./dist/zap-mac/zap.app/Contents/MacOS/zap --version contains: '0.0.0' expected_result: FAILED - name: ZAP binary check (macOS x64) - check version is set via CLI if: startsWith(matrix.os, 'macos') uses: GuillaumeFalourd/assert-command-line-output@v2.1 with: - command_line: ./dist/zap-mac-x64/zap-cli --version + command_line: ./dist/zap-mac/zap-cli --version contains: '0.0.0' expected_result: FAILED - name: ZAP binary check (macOS x64) - unzip cleanup if: startsWith(matrix.os, 'macos') - run: rm -rf dist/zap-mac-x64 - - - name: ZAP binary check (macOS arm64) - unzip - if: startsWith(matrix.os, 'macos') - run: unzip dist/zap-mac-arm64.zip -d dist/zap-mac-arm64 - - name: ZAP binary check (macOS arm64) - sanity check - if: startsWith(matrix.os, 'macos') - run: | - ./dist/zap-mac-arm64/zap.app/Contents/MacOS/zap --version - ./dist/zap-mac-arm64/zap-cli --version - - name: ZAP binary check (macOS arm64) - check version is set - if: startsWith(matrix.os, 'macos') - uses: GuillaumeFalourd/assert-command-line-output@v2.1 - with: - command_line: ./dist/zap-mac-arm64/zap.app/Contents/MacOS/zap --version - contains: '0.0.0' - expected_result: FAILED - - name: ZAP binary check (macOS arm64) - check version is set via CLI - if: startsWith(matrix.os, 'macos') - uses: GuillaumeFalourd/assert-command-line-output@v2.1 - with: - command_line: ./dist/zap-mac-arm64/zap-cli --version - contains: '0.0.0' - expected_result: FAILED - - name: ZAP binary check (macOS x64) - unzip cleanup - if: startsWith(matrix.os, 'macos') - run: rm -rf dist/zap-mac-arm64 + run: rm -rf dist/zap-mac - name: ZAP binary check (Linux) - unzip if: startsWith(matrix.os, 'ubuntu') run: unzip dist/zap-linux-x64.zip -d dist/zap-linux - - name: ZAP binary check (Linux) - sanity check - if: startsWith(matrix.os, 'ubuntu') - run: | - ./dist/zap-linux/zap-cli --version - ./dist/zap-linux/zap --version - name: ZAP binary check (Linux) - check version is set if: startsWith(matrix.os, 'ubuntu') uses: GuillaumeFalourd/assert-command-line-output@v2.1 @@ -447,6 +333,138 @@ jobs: - name: ZAP binary check (Linux) - unzip cleanup if: startsWith(matrix.os, 'ubuntu') run: rm -rf dist/zap-linux + - name: Verify zap.png exists in package's base directory + if: startsWith(matrix.os, 'ubuntu') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: ./node_modules/7zip-bin/linux/x64/7za l ./dist/zap-linux-x64.zip | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in package's app.asar archive + if: startsWith(matrix.os, 'ubuntu') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/linux-unpacked/resources/app.asar | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in Windows x64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-win-x64.zip | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in Windows x64 .zip package's app.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/win-unpacked/resources/app.asar | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in Windows arm64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-win-arm64.zip | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in Windows arm64 .zip package's app.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/win-arm64-unpacked/resources/app.asar | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in macOS x64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-mac-x64.zip | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in macOS x64 .zip package's app-x64.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/mac/zap.app/Contents/Resources/app-x64.asar | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in macOS arm64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-mac-arm64.zip | grep zap.png + contains: 'zap.png' + + - name: Verify zap.png exists in macOS arm64 .zip package's app-arm64.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/mac-arm64/zap.app/Contents/Resources/app-arm64.asar | grep zap.png + contains: 'zap.png' + + - name: Verify apack.json exists in package's base directory + if: startsWith(matrix.os, 'ubuntu') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: ./node_modules/7zip-bin/linux/x64/7za l ./dist/zap-linux-x64.zip | grep apack.json + contains: 'apack.json' + - name: Verify apack.json exists in package's app.asar archive + if: startsWith(matrix.os, 'ubuntu') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/linux-unpacked/resources/app.asar | grep apack.json + contains: 'apack.json' + + - name: Verify apack.json exists in Windows x64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-win-x64.zip | grep apack.json + contains: 'apack.json' + - name: Verify apack.json exists in Windows x64 .zip package's app.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/win-unpacked/resources/app.asar | grep apack.json + contains: 'apack.json' + - name: Verify apack.json exists in Windows arm64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-win-arm64.zip | grep apack.json + contains: 'apack.json' + - name: Verify apack.json exists in Windows arm64 .zip package's app.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/win-arm64-unpacked/resources/app.asar | grep apack.json + contains: 'apack.json' + + - name: Verify apack.json exists in macOS x64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-mac-x64.zip | grep apack.json + contains: 'apack.json' + - name: Verify apack.json exists in macOS x64 .zip package's app-x64.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/mac/zap.app/Contents/Resources/app-x64.asar | grep apack.json + contains: 'apack.json' + - name: Verify apack.json exists in macOS arm64 .zip package + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: 7za l ./dist/zap-mac-arm64.zip | grep apack.json + contains: 'apack.json' + - name: Verify apack.json exists in macOS arm64 .zip package's app-arm64.asar archive + if: startsWith(matrix.os, 'macos') + uses: GuillaumeFalourd/assert-command-line-output@v2.1 + with: + command_line: npx asar l ./dist/mac-arm64/zap.app/Contents/Resources/app-arm64.asar | grep apack.json + contains: 'apack.json' - name: Archive Windows (x64) .zip file uses: actions/upload-artifact@v4 diff --git a/package.json b/package.json index d0f71bb945..665971b096 100644 --- a/package.json +++ b/package.json @@ -106,11 +106,14 @@ "pack:win": "cross-env NODE_OPTIONS=--max-old-space-size=4096 electron-builder -w", "pack:mac": "cross-env NODE_OPTIONS=--max-old-space-size=4096 electron-builder -m", "pack:mac:native": "cross-env NODE_OPTIONS=--max-old-space-size=4096 electron-builder -m", + "pack:cli:linux": "node ./src-script/pack-cli.js -p linux", + "pack:cli:win": "node ./src-script/pack-cli.js -p win", + "pack:cli:mac": "node ./src-script/pack-cli.js -p mac", "pkg": "npx pkg --out-path dist/ --compress GZip --options max-old-space-size=4096 .", "pkg:linux": "npx pkg -t node18-linux-x64,node18-linux-arm64 --public --no-bytecode --output dist/zap-linux --compress GZip --options max-old-space-size=4096 .", "pkg-use-local-fork": "node ../pkg/lib-es5/bin.js -t node18-linux-x64 --output dist/zap-linux --compress GZip --options max-old-space-size=4096 .", "pkg:win": "npx pkg -t node18-win-x64,node18-win-arm64 --public --no-bytecode --output dist/zap-win --compress GZip --options max-old-space-size=4096 .", - "pkg:mac": "npx pkg -t node18-macos-x64,node18-macos-arm64 --output dist/zap-macos --compress GZip --options max-old-space-size=4096 .", + "pkg:mac": "npx pkg -t node18-macos-x64 --output dist/zap-macos --compress GZip --options max-old-space-size=4096 .", "dist": "node src-script/build-release-package.js --output dist/release", "dist:mac": "node src-script/build-release-package.js --platform m --output dist/release", "dist:win": "node src-script/build-release-package.js --platform w --output dist/release", @@ -222,8 +225,8 @@ "build": { "appId": "zap.id", "artifactName": "${productName}-${os}-${arch}.${ext}", - "afterPack": "./src-script/after-pack-linux.js", - "afterAllArtifactBuild": "./src-script/after-all-artifacts.js", + "afterPack": "./src-script/pack-apack-win-linux.js", + "afterAllArtifactBuild": "./src-script/pack-apack-mac.js", "mac": { "category": "public.app-category.developer-tools", "darkModeSupport": true, diff --git a/src-script/after-all-artifacts.js b/src-script/after-all-artifacts.js deleted file mode 100644 index 0c0b95a95c..0000000000 --- a/src-script/after-all-artifacts.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * This script runs after all artifacts are built by Electron Builder. - * It adds additional files (e.g., apack.json, zap.png, zap-cli) to the final - * .zip artifacts for macOS, Windows, and Linux platforms. - */ -const fs = require('fs') -const path = require('path') -const Seven = require('node-7z') -const sevenBin = require('7zip-bin') -const pathTo7zip = sevenBin.path7za - -exports.default = async function (buildResult) { - const zipFiles = buildResult?.artifactPaths || [] - - for (const zipPath of zipFiles) { - if (!zipPath.endsWith('.zip')) continue - if ( - !( - zipPath.includes('mac') || - zipPath.includes('win') || - zipPath.includes('linux') - ) - ) - continue - - const additions = [ - path.join(buildResult.outDir, '../apack.json'), - path.join(buildResult.outDir, '../src/assets/zap.png') - ] - - // Detect platform and arch from filename - const platform = zipPath.includes('mac') - ? 'macos' - : zipPath.includes('linux') - ? 'linux' - : zipPath.includes('win') - ? 'win' - : null - - const arch = zipPath.includes('arm64') ? 'arm64' : 'x64' - - if (!platform) continue - - // Compose zap-cli binary name - const cliName = - platform === 'win' ? `zap-win-${arch}.exe` : `zap-${platform}-${arch}` - - const cliPath = path.join(buildResult.outDir, '../dist', cliName) - - if (fs.existsSync(cliPath)) { - const tempName = platform === 'win' ? 'zap-cli.exe' : 'zap-cli' - const tempPath = path.join(__dirname, tempName) - - // Copy to temp with desired name - fs.copyFileSync(cliPath, tempPath) - - additions.push(tempPath) - - // Clean up after zip - process.on('exit', () => { - if (fs.existsSync(tempPath)) fs.unlinkSync(tempPath) - }) - } else { - console.warn(`⚠️ zap-cli not found for ${platform}-${arch}: ${cliPath}`) - } - - // Add files to zip - for (const filePath of additions) { - await new Promise((resolve, reject) => { - const stream = Seven.add(zipPath, filePath, { - $bin: pathTo7zip, - $progress: true - }) - stream.on('end', resolve) - stream.on('error', (err) => { - console.error(`❌ Error adding ${filePath}:`, err.stderr || err) - reject(err) - }) - }) - - console.log( - `✅ Added ${path.basename(filePath)} to ${path.basename(zipPath)}` - ) - } - } -} diff --git a/src-script/after-pack-linux.js b/src-script/after-pack-linux.js deleted file mode 100644 index e9c44052fd..0000000000 --- a/src-script/after-pack-linux.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * after-pack-linux-assets.js - * Adds zap-cli, apack.json, and zap.png to Linux app output before .deb/.rpm packaging. - */ -const scriptUtil = require('./script-util.js') -const path = require('path') -const fs = require('fs') - -exports.default = async function (context) { - const { electronPlatformName, appOutDir, outDir, arch } = context - - if (electronPlatformName === 'linux') { - // 1. Copy apack.json and zap.png - await scriptUtil.executeCmd({}, 'npx', [ - 'copyfiles', - '-V', - '-f', - path.resolve(outDir, '../apack.json'), - path.resolve(outDir, '../src/assets/zap.png'), - appOutDir - ]) - console.log('✅ apack.json and zap.png copied to Linux appOutDir') - - // 2. Copy zap-cli for correct arch - const archName = arch === 3 ? 'arm64' : 'x64' // arch === 3 => arm64, else x64 - const cliSource = path.resolve(outDir, `../dist/zap-linux-${archName}`) - const cliDest = path.join(appOutDir, 'zap-cli') - - if (!fs.existsSync(cliSource)) { - throw new Error(`❌ zap-cli binary not found at ${cliSource}`) - } - - fs.copyFileSync(cliSource, cliDest) - fs.chmodSync(cliDest, 0o755) - - console.log(`✅ zap-cli (${archName}) copied to ${cliDest}`) - } -} diff --git a/src-script/build-release-package.js b/src-script/build-release-package.js index 15369bf342..e52ba64da6 100644 --- a/src-script/build-release-package.js +++ b/src-script/build-release-package.js @@ -32,8 +32,9 @@ async function buildForOS(osName, outputPath) { switch (osName) { case 'm': console.log(`Building for Mac... Output: ${outputPath}`) - await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:mac']) // Building zap-cli await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:mac']) // Building electron app + await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:mac']) // Building zap-cli + await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:mac']) // Adding zap-cli to zip file if (outputPath) { await scriptUtil.executeCmd({}, 'mv', [ './dist/zap-mac-x64.zip', @@ -48,8 +49,9 @@ async function buildForOS(osName, outputPath) { case 'w': console.log(`Building for Windows... Output: ${outputPath}`) - await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:win']) // Building zap-cli await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:win']) // Building electron app + await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:win']) // Building zap-cli + await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:win']) // Adding zap-cli to zip file if (outputPath) { await scriptUtil.executeCmd({}, 'mv', [ 'dist/zap-win-x64.zip', @@ -64,8 +66,9 @@ async function buildForOS(osName, outputPath) { case 'l': console.log(`Building for Linux... Output: ${outputPath}`) - await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:linux']) // Building zap-cli await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:linux']) // Building electron app + await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:linux']) // Building zap-cli + await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:linux']) // Adding zap-cli to zip file if (outputPath) { await scriptUtil.executeCmd({}, 'mv', [ 'dist/zap-linux-x64.zip', diff --git a/src-script/install-packages-ubuntu b/src-script/install-packages-ubuntu index a867353d1d..54079ab8c7 100755 --- a/src-script/install-packages-ubuntu +++ b/src-script/install-packages-ubuntu @@ -4,4 +4,4 @@ # to get source build to compile via npm install or npm ci # apt-get update -apt-get install -y --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev rpm +apt-get install -y --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev diff --git a/src-script/pack-apack-mac.js b/src-script/pack-apack-mac.js new file mode 100644 index 0000000000..a87327825d --- /dev/null +++ b/src-script/pack-apack-mac.js @@ -0,0 +1,52 @@ +const fs = require('fs') +const path = require('path') +const Seven = require('node-7z') +const sevenBin = require('7zip-bin') +const pathTo7zip = sevenBin.path7za + +exports.default = async function (buildResult) { + for (const element of buildResult?.artifactPaths || []) { + if ( + (element.includes('mac') || + element.includes('win') || + element.includes('linux')) && + element.endsWith('.zip') + ) { + // Add apack.json first + await new Promise((resolve, reject) => { + const myStream1 = Seven.add( + element, // The .zip file (output) + path.join(buildResult.outDir, '../apack.json'), // Add apack.json + { + $progress: true, + $bin: pathTo7zip + } + ) + + myStream1.on('end', resolve) + myStream1.on('error', (err) => { + console.log('Error adding apack.json:', err.stderr) + reject(err) + }) + }) + + // Then add zap.png after apack.json is added + await new Promise((resolve, reject) => { + const myStream2 = Seven.add( + element, // The .zip file (output) + path.join(buildResult.outDir, '../src/assets/zap.png'), // Add zap.png + { + $progress: true, + $bin: pathTo7zip + } + ) + + myStream2.on('end', resolve) + myStream2.on('error', (err) => { + console.log('Error adding zap.png:', err.stderr) + reject(err) + }) + }) + } + } +} diff --git a/src-script/pack-apack-win-linux.js b/src-script/pack-apack-win-linux.js new file mode 100644 index 0000000000..7eaaedc100 --- /dev/null +++ b/src-script/pack-apack-win-linux.js @@ -0,0 +1,19 @@ +const scriptUtil = require('./script-util.js') +const path = require('path') + +exports.default = async function (context) { + if ( + context.electronPlatformName === 'win32' || + context.electronPlatformName === 'linux' + ) { + await scriptUtil.executeCmd({}, 'npx', [ + 'copyfiles', + '-V', + '-f', + path.resolve(context.outDir, '../apack.json'), + path.resolve(context.outDir, '../src/assets/zap.png'), + context.appOutDir + ]) + console.log('Files copied successfully.') + } +} diff --git a/src-script/pack-cli.js b/src-script/pack-cli.js new file mode 100644 index 0000000000..b7d0b63ac2 --- /dev/null +++ b/src-script/pack-cli.js @@ -0,0 +1,79 @@ +'use strict' + +// Utilty script for adding ${cli} binaries to zap binaries generated via "pack:$platform" NPM targets + +const zip = require('../node_modules/7zip-bin/index') +const scriptUtil = require('./script-util.js') +const fsp = require('fs/promises') +const yargs = require('yargs/yargs') +const { hideBin } = require('yargs/helpers') +const argv = yargs(hideBin(process.argv)).argv +const baseDir = `${__dirname}/../` +const dist = `${baseDir}/dist` +console.log(argv) + +const platform = argv.p ? argv.p : process.platform + +/** + * Zip file + * @param {*} dst + * @param {*} filename + */ +async function addToZip(dst, filename) { + await scriptUtil.executeCmd({}, zip.path7za, [ + 'a', + `${dist}/${dst}`, + `${dist}/${filename}` + ]) +} + +/** + * Rename file + * @param {*} oldPath + * @param {*} newPath + */ +async function rename(oldPath, newPath) { + await fsp.rename(`${dist}/${oldPath}`, `${dist}/${newPath}`) +} + +/** + * Package ZAP. + */ +async function main() { + if (platform.includes('darwin') || platform.includes('mac')) { + let file = 'zap-macos' + let cli = `zap-cli` + + await rename(`${file}`, cli) + await addToZip(`zap-mac-x64.zip`, cli) + + // NOTE: `pkg` build tool does not officially support building for mac arch64 yet. + // until official support is out, x86 version will be packaged as + // Apple Rosetta will kick in. + await addToZip(`zap-mac-arm64.zip`, cli) + + // NOTE: pkg support for macos-arm64 is experimental + // await rename(`${file}-arm64`, cli) + // await addToZip(`${file}-arm64.zip`, cli) + } else if (platform.includes('win')) { + let file = 'zap-win' + let cli = `zap-cli.exe` + + await rename(`${file}-x64.exe`, cli) + await addToZip(`${file}-x64.zip`, cli) + + await rename(`${file}-arm64.exe`, cli) + await addToZip(`${file}-arm64.zip`, cli) + } else if (platform.includes('linux')) { + let file = 'zap-linux' + let cli = `zap-cli` + + await rename(`${file}-x64`, cli) + await addToZip(`${file}-x64.zip`, cli) + + await rename(`${file}-arm64`, cli) + await addToZip(`${file}-arm64.zip`, cli) + } +} + +main()