Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit d49f9f3

Browse files
authored
Merge pull request #3 from chakra-ui/ci/release-workflow
ci: add release workflow
2 parents a7ec30f + a394810 commit d49f9f3

20 files changed

+1359
-55
lines changed

.changeset/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": ["@changesets/changelog-github", { "repo": "chakra-ui/polymorphic" }],
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.changeset/good-ducks-confess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@polymorphic-factory/react': minor
3+
---
4+
5+
Initial release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Install'
2+
description: 'Sets up Node.js and runs install'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Install dependencies
8+
uses: pnpm/[email protected]
9+
with:
10+
version: 7
11+
12+
- name: Setup Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version-file: '.nvmrc'
16+
registry-url: 'https://registry.npmjs.org'
17+
cache: 'pnpm'
18+
19+
- name: Setup Git User
20+
shell: bash
21+
run: |
22+
git config --global user.email "[email protected]"
23+
git config --global user.name "Tim Kolberger"
24+
25+
- name: Install dependencies
26+
shell: bash
27+
run: pnpm install

.github/workflows/quality.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Quality
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout branch
14+
uses: actions/checkout@v3
15+
16+
- name: Install
17+
uses: ./.github/composite-actions/install
18+
19+
- name: Build packages
20+
run: pnpm build
21+
22+
tests:
23+
name: Tests
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout branch
27+
uses: actions/checkout@v3
28+
29+
- name: Install
30+
uses: ./.github/composite-actions/install
31+
32+
- name: Run tests
33+
run: pnpm test
34+
35+
eslint:
36+
name: ESLint
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout branch
40+
uses: actions/checkout@v3
41+
42+
- name: Install
43+
uses: ./.github/composite-actions/install
44+
45+
- name: Run ESLint
46+
run: pnpm lint
47+
48+
types:
49+
name: TypeScript
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout branch
53+
uses: actions/checkout@v3
54+
55+
- name: Install
56+
uses: ./.github/composite-actions/install
57+
58+
- name: Run typecheck
59+
run: pnpm typecheck
60+
61+
prettier:
62+
name: Prettier
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Checkout branch
66+
uses: actions/checkout@v3
67+
68+
- name: Install
69+
uses: ./.github/composite-actions/install
70+
71+
- name: Run prettier
72+
run: pnpm format:check

.github/workflows/release.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
paths:
6+
- '.changeset/**'
7+
- 'packages/**'
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
14+
jobs:
15+
release:
16+
name: Release
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout branch
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Install
25+
uses: ./.github/composite-actions/install
26+
27+
- name: Build
28+
run: pnpm build
29+
30+
- name: Create release Pull Request or publish to NPM
31+
id: changesets
32+
uses: changesets/action@v1
33+
with:
34+
publish: pnpm release
35+
commit: 'ci(changesets): version packages'
36+
setupGitUser: false
37+
env:
38+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Create @rc release
43+
if: steps.changesets.outputs.published != 'true'
44+
run: |
45+
git checkout main
46+
pnpm version:rc
47+
pnpm release:rc
48+
env:
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,5 @@ dist
283283

284284
# End of https://www.toptal.com/developers/gitignore/api/macos,node,visualstudiocode,intellij+all
285285

286-
.turbo
286+
.turbo
287+
*.backup

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.x

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Tim Kolberger
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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# @polymorphic
1+
# @polymorphic-factory
22

33
## What's inside?
44

55
This turborepo uses [pnpm](https://pnpm.io) as a package manager. It includes the following packages:
66

77
### Packages
88

9+
- react
10+
911
### Build
1012

1113
To build all apps and packages, run the following command:

package.json

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
{
2-
"name": "polymorphic",
2+
"name": "polymorphic-factory",
33
"version": "0.0.0",
44
"private": true,
55
"workspaces": [
66
"packages/*"
77
],
88
"scripts": {
9-
"prepare": "husky install",
9+
"build": "turbo build",
10+
"format:check": "prettier --check packages/**/src",
11+
"format:write": "prettier --write packages/**/src",
1012
"lint": "turbo run lint",
13+
"prepare": "husky install",
14+
"react": "pnpm --filter=@polymorphic-factory/react",
15+
"release": "changeset publish",
16+
"release:rc": "changeset publish --tag rc",
1117
"test": "turbo run test",
1218
"typecheck": "turbo run typecheck",
13-
"react": "pnpm --filter=@polymorphic/react-factory"
19+
"version": "changeset version",
20+
"version:rc": "changeset version --snapshot rc"
1421
},
1522
"devDependencies": {
23+
"@changesets/changelog-github": "^0.4.7",
24+
"@changesets/cli": "2.25.2",
1625
"@commitlint/cli": "17.1.2",
1726
"@commitlint/config-conventional": "17.1.0",
27+
"@types/node": "18.11.7",
1828
"@typescript-eslint/eslint-plugin": "5.41.0",
1929
"@typescript-eslint/parser": "5.41.0",
20-
"@types/node": "18.11.7",
2130
"eslint": "8.26.0",
2231
"husky": "8.0.1",
2332
"lint-staged": "13.0.3",
2433
"prettier": "2.7.1",
34+
"tsup": "^6.3.0",
2535
"turbo": "1.6.1",
2636
"typescript": "4.8.4"
2737
},

packages/react/README.md

+104-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,104 @@
1-
# poly
1+
# @polymorphic-factory/react
2+
3+
Create polymorphic React components with a customizable `styled` function.
4+
5+
A polymorphic component is a component that can be rendered with a different element.
6+
7+
> **Known drawbacks for the type definitions:**
8+
>
9+
> Event handlers are not typed correctly when using the `as` prop.
10+
>
11+
> This is a deliberate decision to keep the usage as simple as possible.
12+
13+
## Installation
14+
15+
```bash
16+
npm install @polymorphic-factory/react
17+
```
18+
19+
or
20+
21+
```bash
22+
yarn add @polymorphic-factory/react
23+
```
24+
25+
or
26+
27+
```bash
28+
pnpm install @polymorphic-factory/react
29+
```
30+
31+
## Usage
32+
33+
Import the polymorphic factory and create your element factory.
34+
35+
```ts
36+
import { polymorphicFactory } from '@polymorphic-factory/react'
37+
const poly = polymorphicFactory()
38+
```
39+
40+
### Custom `styled` function
41+
42+
You can override the default implementation by passing `styled` function in the options.
43+
44+
```tsx
45+
const poly = polymorphicFactory({
46+
styled: (component, options) => (props) => {
47+
const Component = props.as || component
48+
return <Component data-custom-styled data-options={JSON.stringify(options)} {...props} />
49+
},
50+
})
51+
52+
const App = () => {
53+
return <poly.div hello="world" />
54+
// renders <div data-custom-styled data-options="{ \"hello\": \"world\" }" />
55+
}
56+
```
57+
58+
### Inline
59+
60+
Use the element factory to create elements inline.
61+
Every JSX element is supported `div`, `main`, `aside`, etc.
62+
63+
```tsx
64+
<>
65+
<poly.div />
66+
<poly.main>
67+
<poly.section>
68+
<poly.div as="p">This is rendered as a p element</poly.div>
69+
</poly.section>
70+
</poly.main>
71+
</>
72+
```
73+
74+
### Factory
75+
76+
Use the factory to wrap custom components.
77+
78+
```tsx
79+
const OriginalComponent = (props) => <div data-original="true" {...props}></div>
80+
const MyComponent = poly(OriginalComponent)
81+
82+
const App = () => <MyComponent />
83+
// render <div data-original="true" />
84+
```
85+
86+
It still supports the `as` prop, which would replace the `OriginalComponent`.
87+
88+
```tsx
89+
<MyComponent as="div" />
90+
// renders <div />
91+
```
92+
93+
## Types
94+
95+
```ts
96+
import type { HTMLPolymorphicComponents, HTMLPolymorphicProps } from '@polymorphic-factory/react'
97+
98+
type PolymorphicDiv = HTMLPolymorphicComponents['div']
99+
type DivProps = HTMLPolymorphicProps<'div'>
100+
```
101+
102+
## License
103+
104+
MIT © [Tim Kolberger](https://github.com/timkolberger)
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"replace": {
3+
"main": "dist/index.cjs.js",
4+
"module": "dist/index.esm.js",
5+
"types": "dist/index.d.ts",
6+
"exports": {
7+
".": {
8+
"import": "./dist/index.esm.js",
9+
"require": "./dist/index.cjs.js"
10+
},
11+
"./package.json": "./package.json"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)