diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml index d935fe0..76fcbf6 100644 --- a/.github/workflows/check_pr.yml +++ b/.github/workflows/check_pr.yml @@ -72,6 +72,7 @@ jobs: with: ref: ${{ github.head_ref }} token: ${{ env.GH_TOKEN }} + fetch-depth: 0 - name: Install pnpm uses: pnpm/action-setup@v4.0.0 @@ -120,9 +121,6 @@ jobs: echo "-- after" cat package.json|grep version - echo "Update changelog" - pnpm run changelog --tag ${APP_VERSION} - pnpm exec prettier --write CHANGELOG.md - name: Check if there are any changes id: check-changes-package-json @@ -144,8 +142,36 @@ jobs: echo "${RESULT}">>"${GITHUB_OUTPUT}" echo "${RESULT}" + - name: Generate a changelog + env: + APP_VERSION: ${{ needs.get-version.outputs.app-version }} + run: | + echo "Update changelog" + pnpm run changelog --tag ${APP_VERSION} + pnpm exec prettier --write CHANGELOG.md + + - name: Check if there are any changes + id: check-changes-changelog + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + IS_CHANGED: ${{ steps.check-changes-package-json.outputs.done-change }} + run: | + git add -N . + OLD_VALUE="${IS_CHANGED}" + if git diff --exit-code --quiet; then + echo "No changes detected." + RESULT="${VAR_NAME_FOR_CHANGED}=${OLD_VALUE}" + else + echo "Changes detected." + git add . + git commit -m "chore: update CHANGELOG.md" -m "[AUTO]" + RESULT="${VAR_NAME_FOR_CHANGED}=1" + fi + echo "${RESULT}">>"${GITHUB_OUTPUT}" + echo "${RESULT}" + - name: push - if: ${{ steps.check-changes-package-json.outputs.done-change > 0 }} + if: ${{ steps.check-changes-changelog.outputs.done-change > 0 }} env: GH_TOKEN: ${{ steps.app-token.outputs.token }} run: git push @@ -153,7 +179,7 @@ jobs: - name: Set the output id: result env: - IS_UPDATED: '${{ steps.check-changes-package-json.outputs.done-change }}' + IS_UPDATED: '${{ steps.check-changes-changelog.outputs.done-change }}' run: | RESULT="is-updated=${IS_UPDATED}" echo "${RESULT}">>"${GITHUB_OUTPUT}" diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a83792..d3b8ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,18 @@ All notable changes to this project will be documented in this file. -## [0.0.5] - 2024-10-17 +## [0.0.5] - 2024-10-18 + +### 🚀 Features + +- Initial code ([#4](https://github.com/mato533/electron-typed-ipc-bridge/issues/4)) + +### 📚 Documentation + +- Add playground sourcecode ([#7](https://github.com/mato533/electron-typed-ipc-bridge/issues/7)) ### ⚙️ Miscellaneous Tasks -- Add configration for generating changelog +- Initial repository configrations ([#2](https://github.com/mato533/electron-typed-ipc-bridge/issues/2)) +- Add configurations for Renovate ([#1](https://github.com/mato533/electron-typed-ipc-bridge/issues/1)) +- Add configration for ci/cd ([#5](https://github.com/mato533/electron-typed-ipc-bridge/issues/5)) diff --git a/README.md b/README.md index 55ef35c..9869548 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,51 @@ -# electron-typed-ipc-bridge +[![Run Test](https://github.com/mato533/electron-typed-ipc-bridge/actions/workflows/test.yml/badge.svg)](https://github.com/mato533/electron-typed-ipc-bridge/actions/workflows/test.yml) +[![codecov](https://codecov.io/gh/mato533/electron-typed-ipc-bridge/graph/badge.svg?token=T4ICAR3SCF)](https://codecov.io/gh/mato533/electron-typed-ipc-bridge) +[![GitHub](https://img.shields.io/github/license/mato533/rollup-plugin-gas)](https://github.com/mato533/rollup-plugin-gas/blob/main/LICENSE) + +# What is the electron-typed-ipc-bridge? Generate api on the bridge across isolated contexts of the electron. -# Use +# Why use this library? -## install +There are following reasends. -``` -npm install --save-dev electron-typed-ipc-bridge -``` +1. When implementing IPC using contextBridge, we want to use it in a type-safe. + +image -# Implimentation +1. We want to be freed from channel management. -1. create api on main script + This library is automaticaly generate channel ids with uuid. - ```ex. main/api.ts - const api = { - hello: (to: string)=>console.log(`hellow ${to}!`), - calc: { - add: (a:number, b:number) => a + b, - minus: (a:number, b:number) => a - b, - } - } as const +# How to use it? - export type IpcBridgeApi = IpcBridgeApiTypeGenerator +## install + +``` +npm install electron-typed-ipc-bridge +``` - ``` +## Implimentation -1. add handler at main.ts +**There 5 steps to use this library.** - ``` - registerIpcHandler(api) - ``` +1. Create api on main script -1. add invoker at preload.ts + See the playground code: [`main/api/index.ts`](playground/src/main/api/index.ts) - ``` - const api = await getApiInvoker() +1. Add handler at main.ts - if (process.contextIsolated) { - try { - contextBridge.exposeInMainWorld('electron', electronAPI) - contextBridge.exposeInMainWorld('api', api) - } catch (error) { - console.error(error) - } - } else { - window.electron = electronAPI - window.api = api - } + See the playground code: [`main/index.ts`](playground/src/main/index.ts) - ``` +1. Add invoker at preload.ts -1. add type decolation + See the playground code: [`preload/index.ts`](playground/src/preload/index.ts) - ``` - import type { IpcBridgeApi } from '@main/api' +1. Add type decolation - import type { ElectronAPI } from '@electron-toolkit/preload' + See the playground code: [`preload/index.d.ts`](playground/src/preload/index.ts) - declare global { - interface Window { - electron: ElectronAPI - api: IpcBridgeApi - } - } +1. Call the exposed API or add a handler for messages sent via the API at renderer. - ``` + See the playground code: [`renderer/src/App.vue`](playground/src/renderer/src/App.vue) diff --git a/cliff.toml b/cliff.toml index 4b576e9..bbbf4ba 100644 --- a/cliff.toml +++ b/cliff.toml @@ -19,9 +19,14 @@ body = """ {% else %}\ ## [unreleased] {% endif %}\ -{% for group, commits in commits | group_by(attribute="group") %} +{% for group, commits in commits | filter(attribute="merge_commit", value=false) | group_by(attribute="group") %} ### {{ group | striptags | trim | upper_first }} {% for commit in commits %} + {% if commit.message is matching("\\[(\\w+\\s)?#([0-9]+)\\]") %}\ + {# pass #}\ + {% else %}\ + {% continue %}\ + {% endif %}\ - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ {% if commit.breaking %}[**breaking**] {% endif %}\ {{ commit.message | upper_first }}\ diff --git a/eslint.config.js b/eslint.config.js index d083463..b0138e1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -79,6 +79,13 @@ export default [ }, }, { - ignores: ['node_modules/*', 'dist/*', '**/*/.gitignore', 'coverage/*'], + ignores: [ + 'node_modules/*', + 'dist/*', + '**/*/.gitignore', + 'coverage/*', + 'playground/dist/*', + 'playground/out/*', + ], }, ] diff --git a/playground/.eslintrc.cjs b/playground/.eslintrc.js similarity index 82% rename from playground/.eslintrc.cjs rename to playground/.eslintrc.js index b462405..403d1b2 100644 --- a/playground/.eslintrc.cjs +++ b/playground/.eslintrc.js @@ -1,7 +1,7 @@ /* eslint-env node */ -require('@rushstack/eslint-patch/modern-module-resolution') +import '@rushstack/eslint-patch/modern-module-resolution' -module.exports = { +export default { extends: [ 'eslint:recommended', 'plugin:vue/vue3-recommended', diff --git a/playground/README.md b/playground/README.md index 4f7faa5..7488a90 100644 --- a/playground/README.md +++ b/playground/README.md @@ -6,11 +6,22 @@ An Electron application with Vue and TypeScript - [VSCode](https://code.visualstudio.com/) + [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) + [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) -## Project Setup +## How to use playgloud + +### prerequist + +Built code must exist. + +```bash +$ cd +$ pnpm install +$ pnpm build +``` ### Install ```bash +$ cd playgloud $ pnpm install ``` diff --git a/playground/src/main/api/index.ts b/playground/src/main/api/index.ts index f0717ae..599366a 100644 --- a/playground/src/main/api/index.ts +++ b/playground/src/main/api/index.ts @@ -1,5 +1,6 @@ import { getContextMenuHandler } from './showContextMenu' +import type { IpcMainInvokeEvent } from 'electron' import type { IpcBridgeApiSenderTypeGenerator, IpcBridgeApiTypeGenerator @@ -8,6 +9,10 @@ import type { export const api = { invoke: { ping: () => console.log('pong'), + culc: { + add: (_event: IpcMainInvokeEvent, arg0: number, arg1: number) => arg0 + arg1, + minus: (_event: IpcMainInvokeEvent, arg0: number, arg1: number) => arg0 - arg1 + }, showContextMenu: getContextMenuHandler() }, on: { diff --git a/playground/src/renderer/src/env.d.ts b/playground/src/renderer/src/env.d.ts index aafef95..6366a91 100644 --- a/playground/src/renderer/src/env.d.ts +++ b/playground/src/renderer/src/env.d.ts @@ -2,7 +2,7 @@ declare module '*.vue' { import type { DefineComponent } from 'vue' - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types + // eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any const component: DefineComponent<{}, {}, any> export default component }