From 7441d631499c779ec3f91b24ff14154249775005 Mon Sep 17 00:00:00 2001 From: XeroxDev Date: Mon, 12 Feb 2024 19:17:39 +0100 Subject: [PATCH] ci: fix distribution tool --- .github/workflows/main.yml | 62 ++++++++++++++--------------- .gitignore | 3 +- package.json | 2 +- release-please-config.json | 1 + scripts/build.js | 81 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 33 deletions(-) create mode 100644 scripts/build.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 13e53fb..dda5273 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,34 +33,34 @@ jobs: with: target-branch: master - - name: Run build - run: npm run build - - - name: Create distribution folder - run: | - mkdir fun.shiro.ytmd.sdPlugin - copy sdpi.css fun.shiro.ytmd.sdPlugin\ - copy manifest.json fun.shiro.ytmd.sdPlugin\ - copy property-inspector.html fun.shiro.ytmd.sdPlugin\ - copy action.html fun.shiro.ytmd.sdPlugin\ - copy bundle.js fun.shiro.ytmd.sdPlugin\ - copy bundle-pi.js fun.shiro.ytmd.sdPlugin\ - copy icons fun.shiro.ytmd.sdPlugin -Recurse - - - name: Download Stream Deck Distribution Tool - uses: carlosperate/download-file-action@v1.0.3 - with: - file-url: https://developer.elgato.com/documentation/stream-deck/distributiontool/DistributionToolWindows.zip - file-name: distribution-tool.zip - - - name: Unzip Stream Deck Distribution Tool - run: tar -xf .\distribution-tool.zip - - - name: Validate plugin and build .streamDeckPlugin file - run: ./DistributionTool.exe -b -i fun.shiro.ytmd.sdPlugin -o ./ - - - name: Upload Release Artifact - if: ${{ steps.release.outputs.release_created }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh release upload ${{ steps.release.outputs.tag_name }} ./fun.shiro.ytmd.streamDeckPlugin --clobber \ No newline at end of file +# - name: Run build +# run: npm run build +# +# - name: Create distribution folder +# run: | +# mkdir fun.shiro.ytmd.sdPlugin +# copy sdpi.css fun.shiro.ytmd.sdPlugin\ +# copy manifest.json fun.shiro.ytmd.sdPlugin\ +# copy property-inspector.html fun.shiro.ytmd.sdPlugin\ +# copy action.html fun.shiro.ytmd.sdPlugin\ +# copy bundle.js fun.shiro.ytmd.sdPlugin\ +# copy bundle-pi.js fun.shiro.ytmd.sdPlugin\ +# copy icons fun.shiro.ytmd.sdPlugin -Recurse +# +# - name: Download Stream Deck Distribution Tool +# uses: carlosperate/download-file-action@v1.0.3 +# with: +# file-url: https://developer.elgato.com/documentation/stream-deck/distributiontool/DistributionToolWindows.zip +# file-name: distribution-tool.zip +# +# - name: Unzip Stream Deck Distribution Tool +# run: tar -xf .\distribution-tool.zip +# +# - name: Validate plugin and build .streamDeckPlugin file +# run: ./DistributionTool.exe -b -i fun.shiro.ytmd.sdPlugin -o ./ +# +# - name: Upload Release Artifact +# if: ${{ steps.release.outputs.release_created }} +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# run: gh release upload ${{ steps.release.outputs.tag_name }} ./fun.shiro.ytmd.streamDeckPlugin --clobber \ No newline at end of file diff --git a/.gitignore b/.gitignore index bed081e..96a684d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules/ dist/ coverage/ +build/ bundle.js bundle-pi.js -fun.shiro.ytmd.sdPlugin/ +DistributionTool.exe \ No newline at end of file diff --git a/package.json b/package.json index 821fa7d..212984e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "scripts": { "watch": "start watchify --debug -p tsify src/ytmd-pi.ts -o bundle-pi.js && start watchify --debug -p tsify src/ytmd.ts -o bundle.js", - "build": "browserify -p tsify src/ytmd-pi.ts | terser -cm --comments false -o bundle-pi.js && browserify -p tsify src/ytmd.ts | terser -cm --comments false -o bundle.js" + "build": "node scripts/build.js" }, "repository": { "type": "git", diff --git a/release-please-config.json b/release-please-config.json index 97cdbef..07d2b12 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -2,6 +2,7 @@ "packages": { ".": { "release-type": "node", + "draft": true, "include-component-in-tag": false, "extra-files": [ "src/version.ts", diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 0000000..83b9f24 --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,81 @@ +const fs = require('fs'); +const browserify = require('../node_modules/browserify'); +const tsify = require('../node_modules/tsify'); +const {minify_sync} = require('../node_modules/terser'); +const {execSync} = require('child_process'); +// Create release folder +console.log('Creating release folder'); +if (fs.existsSync('build')) { + execSync('rmdir /s /q build'); +} +fs.mkdirSync('build'); + +// Create plugin folder +console.log('Creating plugin folder'); +if (fs.existsSync('build/fun.shiro.ytmd.sdPlugin')) { + execSync('rmdir /s /q build/fun.shiro.ytmd.sdPlugin'); +} +fs.mkdirSync('build/fun.shiro.ytmd.sdPlugin'); + +// Build plugin +console.log('Building plugin'); + +// I know, this is a mess, but it works. +browserify({entries: ['src/ytmd-pi.ts'], plugin: [tsify]}).bundle((err, buf) => { + if (err) { + console.error(err); + return; + } + const minified = minify_sync(buf.toString(), { + mangle: { + toplevel: true + }, + output: { + comments: false + } + }); + if (minified.error) { + console.error(minified.error); + return; + } + fs.writeFileSync('build/fun.shiro.ytmd.sdPlugin/bundle-pi.js', minified.code); + + browserify({entries: ['src/ytmd.ts'], plugin: [tsify]}).bundle((err, buf) => { + if (err) { + console.error(err); + return; + } + const minified = minify_sync(buf.toString(), { + mangle: { + toplevel: true + }, + output: { + comments: false + } + }); + if (minified.error) { + console.error(minified.error); + return; + } + fs.writeFileSync('build/fun.shiro.ytmd.sdPlugin/bundle.js', minified.code); + + // Copy files + console.log('Copying files'); + fs.copyFileSync('sdpi.css', 'build/fun.shiro.ytmd.sdPlugin/sdpi.css'); + fs.copyFileSync('manifest.json', 'build/fun.shiro.ytmd.sdPlugin/manifest.json'); + fs.copyFileSync('property-inspector.html', 'build/fun.shiro.ytmd.sdPlugin/property-inspector.html'); + fs.copyFileSync('action.html', 'build/fun.shiro.ytmd.sdPlugin/action.html'); + fs.cpSync('icons', 'build/fun.shiro.ytmd.sdPlugin/icons', {recursive: true}); + + // Run distribution tool + console.log('Running distribution tool'); + execSync('DistributionTool.exe -b -i build/fun.shiro.ytmd.sdPlugin -o build'); + + // Clean up + console.log('Cleaning up'); + fs.rmSync('build/fun.shiro.ytmd.sdPlugin', {recursive: true}); + + // Done building release, check the build folder + console.log('Done building release, check the build folder'); + }); +});