diff --git a/.github/workflows/publish-lib.yml b/.github/workflows/publish-lib.yml new file mode 100644 index 000000000..ef44cb558 --- /dev/null +++ b/.github/workflows/publish-lib.yml @@ -0,0 +1,65 @@ +name: Publish Library to NPM + +# Trigger on tag push +on: + push: + tags: + - 'API-v*' + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # Setup Node.js environment + - uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + # Extract version from tag + - name: Extract API version + run: echo "API_VERSION=${GITHUB_REF_NAME#API-v}" >> $GITHUB_ENV + + # Setup Bun + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + # Update version in source code + - name: Update API version constant + run: | + sed -i "s/COCKPIT_WIDGET_API_VERSION = '.*'/COCKPIT_WIDGET_API_VERSION = '${{ env.API_VERSION }}'/" src/libs/external-api/api.ts + + # Install dependencies + - name: Install dependencies + run: bun install --frozen-lockfile + + # Build library + - name: Build library + run: bun run build:lib + working-directory: . + + # Create package.json for distribution + - name: Create package.json for library + run: | + cd dist/lib + { + echo '{ + "name": "@bluerobotics/cockpit-api", + "version": "'${{ env.API_VERSION }}'", + "main": "cockpit-external-api.umd.js", + "module": "cockpit-external-api.es.js", + "publishConfig": { + "access": "public" + } + }' + } > package.json + + # Publish to NPM + - name: Publish to NPM + run: npm publish + working-directory: dist/lib + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index f8674b64a..9a9f1144f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "serve": "vite preview", "test:ci": "vitest --coverage --run", "test:unit": "vitest", - "typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false" + "typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false", + "build:lib": "BUILD_MODE=library vite build" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.4.0", diff --git a/src/components/widgets/IFrame.vue b/src/components/widgets/IFrame.vue index 7d1328a89..fd01ebfdc 100644 --- a/src/components/widgets/IFrame.vue +++ b/src/components/widgets/IFrame.vue @@ -3,6 +3,7 @@