Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(release): prepare for v0.0.5 #6

Merged
merged 10 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
with:
ref: ${{ github.head_ref }}
token: ${{ env.GH_TOKEN }}
fetch-depth: 0

- name: Install pnpm
uses: pnpm/[email protected]
Expand Down Expand Up @@ -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
Expand All @@ -144,16 +142,44 @@ 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

- 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}"
Expand Down
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
78 changes: 30 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

<img width="824" alt="image" src="https://github.com/user-attachments/assets/cbe58812-bda6-4294-bb28-911f549c6a3e">

# 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<typeof api>
## 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)
7 changes: 6 additions & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}\
Expand Down
9 changes: 8 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export default [
},
},
{
ignores: ['node_modules/*', 'dist/*', '**/*/.gitignore', 'coverage/*'],
ignores: [
'node_modules/*',
'dist/*',
'**/*/.gitignore',
'coverage/*',
'playground/dist/*',
'playground/out/*',
],
},
]
4 changes: 2 additions & 2 deletions playground/.eslintrc.cjs → playground/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
13 changes: 12 additions & 1 deletion playground/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <repository-root>
$ pnpm install
$ pnpm build
```

### Install

```bash
$ cd playgloud
$ pnpm install
```

Expand Down
5 changes: 5 additions & 0 deletions playground/src/main/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getContextMenuHandler } from './showContextMenu'

import type { IpcMainInvokeEvent } from 'electron'
import type {
IpcBridgeApiSenderTypeGenerator,
IpcBridgeApiTypeGenerator
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion playground/src/renderer/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}