Skip to content

Commit 0e0b349

Browse files
authored
Merge pull request #193 from podium-lib/ts-semrel-stuff
fix: generate types from JSDoc
2 parents 8ffadbb + d030487 commit 0e0b349

18 files changed

+375
-115
lines changed

.github/workflows/pull-request.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Run all tests on PR
2+
3+
permissions:
4+
id-token: write
5+
contents: read
6+
7+
on:
8+
pull_request:
9+
branches:
10+
- main
11+
- next
12+
13+
jobs:
14+
run-all-tests:
15+
runs-on: [ubuntu-latest]
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Install Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 20
24+
25+
- name: Install dependencies
26+
run: npm install
27+
28+
- name: Lint
29+
run: npm run lint
30+
31+
- name: Run all tests
32+
run: npm test
33+
34+
- name: Generate and check types
35+
run: npm run types

.github/workflows/release.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release on main
2+
3+
permissions:
4+
contents: write # to be able to publish a GitHub release
5+
issues: write # to be able to comment on released issues
6+
pull-requests: write # to be able to comment on released pull requests
7+
id-token: write # to enable use of OIDC for npm provenance
8+
9+
on:
10+
push:
11+
branches:
12+
- main
13+
- next
14+
15+
# Cancel previous workflows which might still be running
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
19+
20+
jobs:
21+
release:
22+
name: Release
23+
runs-on: [ubuntu-latest]
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Install Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 20
32+
33+
- name: Install dependencies
34+
run: npm install
35+
36+
- name: Lint
37+
run: npm run lint
38+
39+
- name: Run all tests
40+
run: npm test
41+
42+
- name: Generate and check types
43+
run: npm run types
44+
45+
- name: Release and publish
46+
run: npx semantic-release
47+
env:
48+
ARTIFACTORY_NPM_SECRET: ${{ env.ARTIFACTORY_NPM_SECRET }}
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
NPM_TOKEN: ${{ env.ARTIFACTORY_NPM_SECRET }}

.github/workflows/test.yml

-32
This file was deleted.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist/
12
coverage/
23
.nyc_output/
34
.idea/
@@ -14,3 +15,4 @@ tmp/**/*
1415
.idea/**/*
1516
coverage
1617
.tap/
18+
*.d.ts

CONTRIBUTING.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Contributing
2+
3+
Welcome, and thanks for showing an interest in contributing 💜
4+
5+
## 🧞 Commands
6+
7+
| Command | Action |
8+
| --------------- | ---------------------------------------------------------- |
9+
| `npm install` | Installs dependencies |
10+
| `npm test` | Runs unit tests |
11+
| `npm run lint` | Does a check with [ESLint](./.eslintrc) |
12+
| `npm run types` | Generates type definitions from JSDoc and does a typecheck |
13+
14+
## 🚚 Continuous deployment
15+
16+
This repo [uses conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) to automate releases with [Semantic Release][semantic-release].
17+
18+
Some example commits and their release type:
19+
20+
| Commit message | Release type |
21+
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
22+
| `fix: update a non-development dependency` | Patch. Bugfix release, updates for runtime dependencies. |
23+
| `feat: added a new option Foo` | Minor. New feature release. |
24+
| `refactor: removed a deprecated option Bar`<br><br>`BREAKING CHANGE: The Bar option has been removed.` | Major. Breaking release, like removing an option.<br /> (Note that the `BREAKING CHANGE: ` token must be in the footer of the commit) |
25+
26+
[workspace]: https://docs.npmjs.com/cli/using-npm/workspaces
27+
[semantic-release]: https://semantic-release.gitbook.io/semantic-release/
28+
29+
### Working with next releases
30+
31+
When making larger changes that needs thorough testing or modules widely used, you can create a `next` release. Here is how:
32+
33+
1. Create a branch `next` if one does not exist
34+
2. Make changes (or push whatever changes you have on a different branch onto `next`)
35+
3. When you are done, commit your changes with semantic-release in mind
36+
4. The workflows will run and publish a new version on the format: `major.minor.patch-next.<next version>
37+
Where `next version` is incremented each time you push a feat, fix or patch to the branch.
38+
39+
### GitHub Actions
40+
41+
GitHub Actions workflows:
42+
43+
- [Build and test pull requests](./.github/workflows/pull-request.yml)
44+
- [Build and release changes on `main`](./.github/workflows/release.yml)
45+
46+
You'll find the workflow logs and results in the Actions tab.
47+
48+
## On MessageBus
49+
50+
MessageBus uses a global singleton to coordinate message passing between different instances. This is something you need to be aware of, for instance, if writing unit tests. See [MessageBus.test.js](test/MessageBus.test.js) for an example.

README.md

+33-54
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
11
# @podium/browser
22

3-
Podium browser library.
3+
This is a client-side library designed to send and receive messages between different podlets in a layout.
44

5-
[![Dependencies](https://img.shields.io/david/podium-lib/browser.svg)](https://david-dm.org/podium-lib/browser)
6-
[![GitHub Actions status](https://github.com/podium-lib/browser/workflows/Run%20Lint%20and%20Tests/badge.svg)](https://github.com/podium-lib/browser/actions?query=workflow%3A%22Run+Lint+and+Tests%22)
7-
[![Known Vulnerabilities](https://snyk.io/test/github/podium-lib/browser/badge.svg)](https://snyk.io/test/github/podium-lib/browser)
5+
## Usage
86

9-
Currently this module only includes [MessageBus](#MessageBus), but it is possible that it will include more features in the future.
7+
To install:
108

11-
## Installation
12-
13-
```bash
14-
$ npm install @podium/browser
9+
```sh
10+
npm install @podium/browser
1511
```
1612

17-
## MessageBus
13+
Include the library in your client-side application.
1814

19-
Cross podlet communication and message passing.
15+
```js
16+
import Podium from '@podium/browser';
17+
```
2018

21-
### Simple usage
19+
### Send messages between podlets
20+
21+
Use the [MessageBus](#messagebus) to send messages between podlets in a layout.
2222

2323
```javascript
24-
// In podlet A. Broadcast an event
24+
// In podlet A. Broadcast a message.
2525
import { MessageBus } from '@podium/browser';
2626

2727
const messageBus = new MessageBus();
2828

2929
messageBus.publish('search', 'query', 'couch');
30+
```
3031

31-
// In podlet B. Subscribe to an event
32+
```js
33+
// In podlet B. Subscribe to a message.
3234
import { MessageBus } from '@podium/browser';
3335

3436
const messageBus = new MessageBus();
3537

36-
messageBus.subscribe('search', 'query', event => {
38+
messageBus.subscribe('search', 'query', (event) => {
3739
console.log(event.payload);
3840
});
3941
```
4042

41-
### Constructor
43+
## API
4244

43-
Create a new MessageBus instance.
45+
### MessageBus
46+
47+
Cross podlet communication and message passing.
48+
Create a new MessageBus instance to use the API.
4449

4550
```javascript
51+
import { MessageBus } from '@podium/browser';
52+
4653
const messageBus = new MessageBus();
4754
```
4855

49-
### API
56+
#### `.publish(channel, topic, payload)`
5057

51-
#### .publish(channel, topic, payload)
52-
53-
Publish an event for a channel and topic combination. Returns the event object passed to subscribers.
58+
Publish a message for a channel and topic combination. Returns the `Event` object passed to subscribers.
5459

5560
This method takes the following arguments:
5661

@@ -68,9 +73,9 @@ messageBus.publish('search', 'query', 'laptop');
6873
messageBus.publish('auth', 'logout');
6974
```
7075

71-
#### .subscribe(channel, topic, callback)
76+
#### `.subscribe(channel, topic, callback)`
7277

73-
Subscribe to events for a channel and topic combination.
78+
Subscribe to messages for a channel and topic combination.
7479

7580
This method takes the following arguments:
7681

@@ -83,12 +88,12 @@ This method takes the following arguments:
8388
Example:
8489

8590
```javascript
86-
messageBus.subscribe('channel', 'topic', event => {
91+
messageBus.subscribe('channel', 'topic', (event) => {
8792
console.log(event.payload);
8893
});
8994
```
9095

91-
#### .unsubscribe(channel, topic, callback)
96+
#### `.unsubscribe(channel, topic, callback)`
9297

9398
Unsubscribe to events for a channel and topic combination.
9499

@@ -112,7 +117,7 @@ messageBus.subscribe('channel', 'topic', cb);
112117
messageBus.unsubscribe('channel', 'topic', cb);
113118
```
114119

115-
#### .peek(channel, topic)
120+
#### `.peek(channel, topic)`
116121

117122
Get the latest event for a channel and topic combination.
118123

@@ -123,7 +128,7 @@ This method takes the following arguments:
123128
| channel | `null` | `string` | `true` | Name of the channel |
124129
| topic | `null` | `string` | `true` | Name of the topic |
125130

126-
#### .log(channel, topic)
131+
#### `.log(channel, topic)`
127132

128133
Returns an array of the 10 latest events for a channel and topic combination.
129134
The array is ordered such that the the latest/newest events is at the front of the array.
@@ -140,33 +145,7 @@ Example:
140145
```javascript
141146
const events = messageBus.log('channel', 'topic');
142147

143-
events.forEach(event => {
148+
events.forEach((event) => {
144149
console.log(event.payload);
145150
});
146151
```
147-
148-
### Implementation
149-
150-
MessageBus uses a global singleton to coordinate message passing between different instances. This is something you need to be aware of, for instance, if writing unit tests. See [MessageBus.test.js](test/MessageBus.test.js) for an example.
151-
152-
## License
153-
154-
Copyright (c) 2019 FINN.no
155-
156-
Permission is hereby granted, free of charge, to any person obtaining a copy
157-
of this software and associated documentation files (the "Software"), to deal
158-
in the Software without restriction, including without limitation the rights
159-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
160-
copies of the Software, and to permit persons to whom the Software is
161-
furnished to do so, subject to the following conditions:
162-
163-
The above copyright notice and this permission notice shall be included in all
164-
copies or substantial portions of the Software.
165-
166-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
169-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
170-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
171-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
172-
SOFTWARE.

index.d.ts

-23
This file was deleted.

0 commit comments

Comments
 (0)