Skip to content

Commit ab81a9f

Browse files
committed
Initial commit
0 parents  commit ab81a9f

23 files changed

+3163
-0
lines changed

.github/workflows/compile.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Compile
2+
3+
on:
4+
push: { branches: ["main"] }
5+
pull_request:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
10+
11+
jobs:
12+
compile:
13+
name: Compile
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v3
22+
23+
- name: Install pnpm
24+
run: npm install -g pnpm
25+
26+
- name: Install dependencies
27+
run: pnpm install
28+
29+
- name: Compile
30+
run: pnpm build

.github/workflows/lint.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Lint
2+
3+
on:
4+
push: { branches: ["main"] }
5+
pull_request:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
10+
11+
jobs:
12+
lint:
13+
name: Lint
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v3
22+
23+
- name: Install pnpm
24+
run: npm install -g pnpm
25+
26+
- name: Install dependencies
27+
run: pnpm install
28+
29+
- name: Run eslint
30+
run: pnpm lint:eslint
31+
32+
- name: Run prettier
33+
run: pnpm lint:prettier
34+
35+
- name: Ensure no changes to any files
36+
run: git diff --exit-code

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
8+
jobs:
9+
publish:
10+
name: Publish
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v3
19+
20+
- name: Get version
21+
run: |
22+
VERSION=${GITHUB_REF#refs/tags/}
23+
echo Version: $VERSION
24+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
25+
26+
- name: Install pnpm
27+
run: npm install -g pnpm
28+
29+
- name: Install dependencies
30+
run: pnpm install
31+
32+
- name: Compile
33+
run: pnpm build
34+
35+
- name: Update package.json version
36+
run: |
37+
jq --arg version $VERSION '.version = $version' package.json > package.tmp.json
38+
mv package.tmp.json package.json
39+
git diff package.json
40+
41+
- name: Publish
42+
env:
43+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
44+
run: |
45+
pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
46+
pnpm publish --no-git-checks --access public

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
lib/
3+
.DS_Store

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 80,
3+
"trailingComma": "all"
4+
}

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["esbenp.prettier-vscode"]
3+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": "explicit"
4+
},
5+
"editor.formatOnSave": true
6+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Alex Johansson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<div align="center">
2+
<h1>trpc-postman</h1>
3+
<a href="https://www.npmjs.com/package/trpc-postman"><img src="https://img.shields.io/npm/v/trpc-postman.svg?style=flat&color=brightgreen" target="_blank" /></a>
4+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-black" /></a>
5+
</div>
6+
7+
---
8+
9+
## Generate an Postman spec from your tRPC server, in one line of code
10+
11+
### Step 1: Install `trpc-postman`
12+
13+
```bash
14+
# npm
15+
npm install trpc-postman
16+
17+
# yarn
18+
yarn install trpc-postman
19+
20+
# pnpm
21+
pnpm install trpc-postman
22+
```
23+
24+
### Step 2: Generate Postman Collection
25+
26+
```typescript
27+
import { trpcToPostmanCollection } from "trpc-postman";
28+
29+
// generate Postman Collection JSON
30+
const postmanCollection = trpcToPostmanCollection({
31+
collectionName: "My API",
32+
router: trpcRouter,
33+
});
34+
```
35+
36+
## Publishing the Postman Collection
37+
38+
You can update your Postman Collection using your Postman API key and Collection ID
39+
40+
### Step 1: Generate a Postman API key
41+
42+
You can generate a Postman API key [here](https://www.postman.com/settings/me/api-keys).
43+
44+
### Step 2: Get your Colllection ID
45+
46+
If you don't already have a collection to publish to, create a collection manually.
47+
48+
Then, you can see your Collection ID by clicking the `i` button on the right-hand side:
49+
50+
![collection id](./collection-id.png)
51+
52+
### Step 3: Publish collection
53+
54+
> WARNING!! This will ERASE your entire collection with the generated Postman Collection.
55+
56+
```typescript
57+
import { trpcToPostmanCollection } from "trpc-postman";
58+
59+
// generate Postman Collection JSON
60+
const postmanCollection = trpcToPostmanCollection({
61+
collectionName: "My API",
62+
router: trpcRouter,
63+
});
64+
65+
// overwrite collection in postman
66+
await updateRemotePostmanCollection({
67+
apiKey: POSTMAN_API_KEY,
68+
collectionId: YOUR_COLLECTION_ID,
69+
collection: postmanCollection,
70+
});
71+
```

collection-id.png

327 KB
Loading

0 commit comments

Comments
 (0)